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

From Apache OpenOffice Wiki
Jump to: navigation, search
 
Line 12: Line 12:
 
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">
+
<syntaxhighlight lang="java">
 
   // get my global service manager  
 
   // get my global service manager  
 
   XMultiServiceFactory xServiceManager = (XMultiServiceFactory)UnoRuntime.queryInterface(
 
   XMultiServiceFactory xServiceManager = (XMultiServiceFactory)UnoRuntime.queryInterface(
Line 24: Line 24:
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,  
 
       UnoRuntime.queryInterface(XMultiServiceFactory.class,  
 
           xServiceManager.createInstance(sProviderService));
 
           xServiceManager.createInstance(sProviderService));
</source>
+
</syntaxhighlight>
 
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.
  
 
The <idl>com.sun.star.configuration.ConfigurationProvider</idl> always operates in the user mode, accessing data on behalf of the current user and directing updates to the user's personal layer.
 
The <idl>com.sun.star.configuration.ConfigurationProvider</idl> always operates in the user mode, accessing data on behalf of the current user and directing updates to the user's personal layer.
  
The backend data store 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 {{PRODUCTNAME}} installation. Additionally there are special layers that are used by the Extension Manager for deploying configuration data associated with extensions. For details, see [[Documentation/DevGuide/Extensions/Extensions|Extensions]].  
+
The backend data store 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 {{AOo}} installation. Additionally, there are special layers that are used by the Extension Manager for deploying configuration data associated with extensions. For details, see [[Documentation/DevGuide/Extensions/Extensions|Extensions]].  
  
 
Arguments can be provided that determine the default behavior of views created through this <idl>com.sun.star.configuration.ConfigurationProvider</idl>. The following parameter may be used for this purpose:
 
Arguments can be provided that determine the default behavior of views created through this <idl>com.sun.star.configuration.ConfigurationProvider</idl>. The following parameter may be used for this purpose:
Line 47: Line 47:
  
  
{{Warn|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>.  
+
{{Warn|The default configuration provider obtained when no arguments are given will always be the same object. Be careful not to call <idlm>com.sun.star.lang.XComponent:dispose</idlm>() 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 <idlml>com.sun.star.lang.XComponent:dispose</idlml>() on this <idl>com.sun.star.configuration.ConfigurationProvider</idl>.}}
+
If you provide any arguments, then a new instance is created. You must then call <idlm>com.sun.star.lang.XComponent:dispose</idlm>() on this <idl>com.sun.star.configuration.ConfigurationProvider</idl>.}}
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Configuration Management]]
 
[[Category:Documentation/Developer's Guide/Configuration Management]]

Latest revision as of 16:53, 21 December 2020



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.

The backend data store 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 Apache OpenOffice installation. Additionally, there are special layers that are used by the Extension Manager for deploying configuration data associated with extensions. For details, see Extensions.

Arguments can be provided that determine the default behavior of views created through this com.sun.star.configuration.ConfigurationProvider. The following parameter 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.


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

If you provide any arguments, then a new instance is created. You must then call dispose() on this com.sun.star.configuration.ConfigurationProvider.

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