Difference between revisions of "Documentation/DevGuide/Config/Connecting to a Data Source"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
Line 11: Line 11:
 
To obtain a provider instance ask the global <idl>com.sun.star.lang.ServiceManager</idl> for a <idl>com.sun.star.configuration.ConfigurationProvider</idl>. Typically the first lines of code to get access to configuration data look similar to the following:  
 
To obtain a provider instance ask the global <idl>com.sun.star.lang.ServiceManager</idl> for a <idl>com.sun.star.configuration.ConfigurationProvider</idl>. Typically the first lines of code to get access to configuration data look similar to the following:  
 
<!--[SOURCE:Config/ConfigExamples.java]-->
 
<!--[SOURCE:Config/ConfigExamples.java]-->
 
+
<source lang="java">
 
   // get my global service manager  
 
   // get my global service manager  
 
   XMultiServiceFactory xServiceManager = (XMultiServiceFactory)UnoRuntime.queryInterface(
 
   XMultiServiceFactory xServiceManager = (XMultiServiceFactory)UnoRuntime.queryInterface(
Line 23: Line 23:
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,  
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,  
 
           xServiceManager.createInstance(sProviderService));
 
           xServiceManager.createInstance(sProviderService));
 
+
</source>
 
This code creates a default <idl>com.sun.star.configuration.ConfigurationProvider</idl>. The most important interface a <idl>com.sun.star.configuration.ConfigurationProvider</idl> implements is <idl>com.sun.star.lang.XMultiServiceFactory</idl> that is used to create further configuration objects.
 
This code creates a default <idl>com.sun.star.configuration.ConfigurationProvider</idl>. The most important interface a <idl>com.sun.star.configuration.ConfigurationProvider</idl> implements is <idl>com.sun.star.lang.XMultiServiceFactory</idl> that is used to create further configuration objects.
  
Line 35: Line 35:
  
 
A <idl>com.sun.star.configuration.AdministrationProvider</idl> is created in the same way as a <idl>com.sun.star.configuration.ConfigurationProvider</idl>.
 
A <idl>com.sun.star.configuration.AdministrationProvider</idl> is created in the same way as a <idl>com.sun.star.configuration.ConfigurationProvider</idl>.
 
+
<source lang="java">
 
   // get my global service manager
 
   // get my global service manager
 
   XMultiServiceFactory xServiceManager = getServiceManager();
 
   XMultiServiceFactory xServiceManager = getServiceManager();
Line 53: Line 53:
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,
 
           xServiceManager.createInstanceWithArguments(sAdminService,aProviderArguments));
 
           xServiceManager.createInstanceWithArguments(sAdminService,aProviderArguments));
 
+
</source>
 
As you see in the example above, the default <idl>com.sun.star.configuration.AdministrationProvider</idl> supports a special parameter for reinitialization:
 
As you see in the example above, the default <idl>com.sun.star.configuration.AdministrationProvider</idl> supports a special parameter for reinitialization:
  
Line 172: Line 172:
  
  
{{Documentation/Caution|The default configuration provider obtained when no arguments are given will always be the same object. Be careful not to call [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XComponent.html#dispose com.sun.star.lang.XComponent:dispose]() on this shared <idl>com.sun.star.configuration.ConfigurationProvider</idl>.  
+
{{Documentation/Caution|The default configuration provider obtained when no arguments are given will always be the same object. Be careful not to call <idlml>com.sun.star.lang.XComponent:dispose</idlml>() on this shared <idl>com.sun.star.configuration.ConfigurationProvider</idl>.  
  
If you provide any arguments, then a new instance is created. You must then call [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XComponent.html#dispose com.sun.star.lang.XComponent:dispose]() on this <idl>com.sun.star.configuration.ConfigurationProvider</idl>.}}
+
If you provide any arguments, then a new instance is created. You must then call <idlml>com.sun.star.lang.XComponent:dispose</idlml>() on this <idl>com.sun.star.configuration.ConfigurationProvider</idl>.}}
  
 
{{PDL1}}
 
{{PDL1}}
 
[[Category: Configuration Management]]
 
[[Category: Configuration Management]]

Revision as of 19:44, 4 April 2008



The first step to access the configuration database is to connect to a configuration data source.

To obtain a provider instance ask the global com.sun.star.lang.ServiceManager for a com.sun.star.configuration.ConfigurationProvider. Typically the first lines of code to get access to configuration data look similar to the following:

  // get my global service manager 
  XMultiServiceFactory xServiceManager = (XMultiServiceFactory)UnoRuntime.queryInterface(
  XMultiServiceFactory.class, this.getRemoteServiceManager(
      "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager")); 
 
  final String sProviderService = "com.sun.star.configuration.ConfigurationProvider";
 
  // create the provider and remember it as a XMultiServiceFactory
  XMultiServiceFactory xProvider = (XMultiServiceFactory)
      UnoRuntime.queryInterface(XMultiServiceFactory.class, 
          xServiceManager.createInstance(sProviderService));

This code creates a default com.sun.star.configuration.ConfigurationProvider. The most important interface a com.sun.star.configuration.ConfigurationProvider implements is com.sun.star.lang.XMultiServiceFactory that is used to create further configuration objects.

The com.sun.star.configuration.ConfigurationProvider always operates in the user mode, accessing data on behalf of the current user and directing updates to the user's personal layer.

For administrative access to manipulate the default layers the com.sun.star.configuration.AdministrationProvider is used. When creating this service, additional parameters can be used that select the layer for updates or that contain credentials used to authorize administrative access. The backend that is used determines which default layers exist, how they are addressed and how administrative access is authorized.

The standard file-based backend has several shared layers. One of these layers is used to store shared default data. The files for this layer are located in the share directory of the OpenOffice.org installation. To gain administrative access to this layer, no additional parameters are needed. An com.sun.star.configuration.AdministrationProvider for this backend automatically tries to read and write this shared layer. Additionally there are special layers that are used by the Extension Manager for deploying configuration data associated with extensions. For details, see Extensions.

Authorization for the file-based backend is done by the operating system based upon file access privileges. The current user requires write privileges in the shared configuration directory if an AdministrationProvider is suppose to update configuration data.

A com.sun.star.configuration.AdministrationProvider is created in the same way as a com.sun.star.configuration.ConfigurationProvider.

  // get my global service manager
  XMultiServiceFactory xServiceManager = getServiceManager();
 
  // get the arguments to use 
  com.sun.star.beans.PropertyValue aReinitialize = new com.sun.star.beans.PropertyValue()
  aReinitialize.Name = "reinitialize"
  aReinitialize.Value = new Boolean(true);
 
  Object[] aProviderArguments = new Object[1];
  aProviderArguments[0] = aReinitialize;
 
  final String sAdminService = "com.sun.star.configuration.AdministrationProvider";
 
  // create the provider and remember it as a XMultiServiceFactory
  XMultiServiceFactory xAdminProvider = (XMultiServiceFactory)
      UnoRuntime.queryInterface(XMultiServiceFactory.class,
          xServiceManager.createInstanceWithArguments(sAdminService,aProviderArguments));

As you see in the example above, the default com.sun.star.configuration.AdministrationProvider supports a special parameter for reinitialization:

Parameter Name Type Default Comments
reinitialize boolean false Discard any cached information from previous runs and regenerate from scratch.

Some backend implementations use cached data to speed up access. If the reinitialize parameter is true, this cache will be recreated from the XML data when the AdministrationProvider is created. With the current implementation, the parameter has no effect.

When establishing the connection, specify the parameters that select the backend to use and additional backend-specific parameters to select the data source. When there are no parameters given, the standard configuration backend and data source of the OpenOffice.org installation is used.

The standard values for these parameters may be found in the configuration file configmgr(.ini|rc) (.ini on Windows, rc on Unix) in the program directory of the OpenOffice.org installation. The INI entries have a prefix "CFG_" before the parameter name.

Template:Documentation/Note

The following parameters are supported to select the backend component to use:

Parameter Name Type Default Comments
BackendService string "com.sun.star.configuration.backend.LocalSingleBackend" This must be a UNO service or implementation name that can be used to create a service instance. The instance created must support either service com.sun.star.configuration.backend.Backend or service com.sun.star.configuration.backend.SingleBackend
BackendWrapper string "com.sun.star.configuration.backend.SingleBackendAdapter" This parameter is used only, if the service specified by parameter "BackendService" only implements service [IDLS:com.sun.star.configuration.backend.SingleBackend, but does not support service Backend. It must be a UNO service or implementation name that can be used to create a service instance. The instance created must support service com.sun.star.configuration.backend.BackendAdapter.

The following parameter was formerly supported to select the type of backend to use:

Parameter Name Type Default Comments
servertype string "uno"<c/ode> Other values are not supported any more in OpenOffice.org. This setting formerly was used to select between several internal backend implementations.

For the "com.sun.star.configuration.backend.LocalSingleBackend" backend, the following parameters are used to select the location of data:

Parameter Name Type Default Comments
<code>SchemaDataUrl string or string[] $(installurl)/share/registry/schema

+ locations used for extensions

This must be a file URL pointing to a directory, a whitespace-separated list of such URLs or a sequence of such URLs.

The locations are searched in the given order until a schema is found.

DefaultLayerUrls string or string[] $(installurl)/share/registry

+ locations used for extensions

This must be a file URL pointing to a directory, a whitespace-separated list of such URLs or a sequence of such URLs.

The layers are merged in the given order.

The data is located in subdirectory data of each location. Additionally locale-specific data can be placed in subdirectory res.

UserLayerUrl string $(userurl)/user/registry This must be a file URL pointing to a directory.

If this is one of the entries of parameter "DefaultLayerUrls", then only the entries before it will be used as default layers.

The data is located in the subdirectory data of the given location.

Arguments can be provided that determine the default behavior of views created through this com.sun.star.configuration.ConfigurationProvider. The following parameters may be used for this purpose:

Parameter Name Type Default Comments
Locale string The user's locale. This parameter was called "locale" in a former version. The old name is still supported for compatibility.
EnableAsync boolean true This parameter was called "lazywrite" in a former version. The old name is still supported for compatibility.


Documentation caution.png The default configuration provider obtained when no arguments are given will always be the same object. Be careful not to call <idlml>com.sun.star.lang.XComponent:dispose</idlml>() on this shared com.sun.star.configuration.ConfigurationProvider.

If you provide any arguments, then a new instance is created. You must then call <idlml>com.sun.star.lang.XComponent:dispose</idlml>() on this com.sun.star.configuration.ConfigurationProvider.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools