Difference between revisions of "Documentation/DevGuide/WritingUNO/Write Registration Info Using a Helper Method"
m |
|||
(8 intermediate revisions by 4 users not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/WritingUNO/Implementing without Helpers | |NextPage=Documentation/DevGuide/WritingUNO/Implementing without Helpers | ||
}} | }} | ||
+ | {{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}} | ||
{{DISPLAYTITLE:Write Registration Info Using Helper Method}} | {{DISPLAYTITLE:Write Registration Info Using Helper Method}} | ||
− | UNO components have to be registered with the registry database of a service manager. In an office installation, this is the file ''types.rdb'' (up through | + | UNO components have to be registered with the registry database of a service manager. In an office installation, this is the file ''types.rdb'' (up through OpenOffice.org 1.1.0, ''applicat.rdb'') for all predefined services. A service manager can use this database to find the implementations for a service. For instance, if an instance of your component is created using the following call. |
− | < | + | <syntaxhighlight lang="java"> |
Object imageShrink = | Object imageShrink = | ||
xRemoteServiceManager.createInstance("org.openoffice.test.ImageShrink"); | xRemoteServiceManager.createInstance("org.openoffice.test.ImageShrink"); | ||
− | </ | + | </syntaxhighlight> |
Using the given service or implementation name, the service manager looks up the location of the corresponding jar file in the registry and instantiates the component. | Using the given service or implementation name, the service manager looks up the location of the corresponding jar file in the registry and instantiates the component. | ||
− | {{ | + | {{Note|If you want to use the service manager of the Java UNO runtime, <tt>com.sun.star.comp.servicemanager.ServiceManager</tt> (''jurt.jar''), to instantiate your service implementation, then you would have to create the service manager and add the factory for "org.openoffice.test.ImageShrink" programmatically, because the Java service manager does not use the registry. |
Alternatively, you can use <tt>com.sun.star.comp.helper.RegistryServiceFactory</tt> from ''juh.jar'' which is registry-based. Its drawback is that it delegates to a C++ implementation of the service manager through the java-bridge.}} | Alternatively, you can use <tt>com.sun.star.comp.helper.RegistryServiceFactory</tt> from ''juh.jar'' which is registry-based. Its drawback is that it delegates to a C++ implementation of the service manager through the java-bridge.}} | ||
During the registration, a component writes the necessary information into the registry. The process to write the information is triggered externally when a client calls the <code>__writeRegistryServiceInfo()</code> method at the component. | During the registration, a component writes the necessary information into the registry. The process to write the information is triggered externally when a client calls the <code>__writeRegistryServiceInfo()</code> method at the component. | ||
− | < | + | <syntaxhighlight lang="java"> |
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) | public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) | ||
− | </ | + | </syntaxhighlight> |
− | The caller passes an <idl>com.sun.star.registry.XRegistryKey</idl> interface that is used by the method to write the registry entries. Again, the <code>FactoryHelper</code> class offers a way to implement the method: <!--[SOURCE:Components/Thumbs/org/openoffice/comp/test/ImageShrink.java]--> | + | The caller passes an <idl>com.sun.star.registry.XRegistryKey</idl> interface that is used by the method to write the registry entries. Again, the <code>FactoryHelper</code> class offers a way to implement the method: |
− | < | + | <!--[SOURCE:Components/Thumbs/org/openoffice/comp/test/ImageShrink.java]--> |
+ | <syntaxhighlight lang="java"> | ||
... | ... | ||
Line 31: | Line 33: | ||
__serviceName, regKey); | __serviceName, regKey); | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
The writeRegistryServiceInfo method takes three arguments: | The writeRegistryServiceInfo method takes three arguments: | ||
Line 38: | Line 40: | ||
* XRegistryKey | * XRegistryKey | ||
− | Use tools | + | Use tools such as ''regcomp'' to register a component. This tool takes the path to the jar file containing the component as an argument. Since the jar can contain several classes, the class that implements the <code>__writeRegistryServiceInfo()</code> method must be pointed out by means of the manifest. Again, the <code>RegistrationClassName</code> entry determines the correct class. For example: |
RegistrationClassName: org.openoffice.comp.test.ImageShrink | RegistrationClassName: org.openoffice.comp.test.ImageShrink | ||
Line 45: | Line 47: | ||
{{PDL1}} | {{PDL1}} | ||
− | [[Category: Writing UNO Components]] | + | |
+ | [[Category:Documentation/Developer's Guide/Writing UNO Components]] |
Latest revision as of 13:38, 24 December 2020
- Class Definition with Helper Class
- Implementing Your Own Interfaces
- Providing a Single Factory Using a Helper Method
- Write Registration Info Using a Helper Method
- Implementing without Helpers
- Storing the Service Manager for Further Use
- Create Instance with Arguments
- Possible Structures for Java Components
- Running and Debugging Java Components
UNO components have to be registered with the registry database of a service manager. In an office installation, this is the file types.rdb (up through OpenOffice.org 1.1.0, applicat.rdb) for all predefined services. A service manager can use this database to find the implementations for a service. For instance, if an instance of your component is created using the following call.
Object imageShrink = xRemoteServiceManager.createInstance("org.openoffice.test.ImageShrink");
Using the given service or implementation name, the service manager looks up the location of the corresponding jar file in the registry and instantiates the component.
During the registration, a component writes the necessary information into the registry. The process to write the information is triggered externally when a client calls the __writeRegistryServiceInfo()
method at the component.
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
The caller passes an com.sun.star.registry.XRegistryKey interface that is used by the method to write the registry entries. Again, the FactoryHelper
class offers a way to implement the method:
... // static __writeRegistryServiceInfo implementation public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { return FactoryHelper.writeRegistryServiceInfo( ImageShrink.class.getName(), __serviceName, regKey); }
The writeRegistryServiceInfo method takes three arguments:
- implementation name
- service name
- XRegistryKey
Use tools such as regcomp to register a component. This tool takes the path to the jar file containing the component as an argument. Since the jar can contain several classes, the class that implements the __writeRegistryServiceInfo()
method must be pointed out by means of the manifest. Again, the RegistrationClassName
entry determines the correct class. For example:
RegistrationClassName: org.openoffice.comp.test.ImageShrink
The above entry is also necessary to locate the class that provides __getServiceFactory()
, therefore the functions __writeRegistryServiceInfo()
and __getServiceFactory()
have to be in the same class.
Content on this page is licensed under the Public Documentation License (PDL). |