Difference between revisions of "Documentation/DevGuide/WritingUNO/Providing a Single Factory Using a Helper Method"
m |
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/WritingUNO/Write Registration Info Using a Helper Method | |NextPage=Documentation/DevGuide/WritingUNO/Write Registration Info Using a Helper Method | ||
}} | }} | ||
− | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}} | |
{{DISPLAYTITLE:Providing a Single Factory Using Helper Method}} | {{DISPLAYTITLE:Providing a Single Factory Using Helper Method}} | ||
The component must be able to create single factories for each service implementation it contains and return them in the static component operation <code>__getServiceFactory()</code>. The {{PRODUCTNAME}} Java UNO environment provides a Java class <code>com.sun.star.comp.loader.FactoryHelper</code> that creates a default implementation of a single factory through its method <code>getServiceFactory()</code>. The following example could be written: | The component must be able to create single factories for each service implementation it contains and return them in the static component operation <code>__getServiceFactory()</code>. The {{PRODUCTNAME}} Java UNO environment provides a Java class <code>com.sun.star.comp.loader.FactoryHelper</code> that creates a default implementation of a single factory through its method <code>getServiceFactory()</code>. The following example could be written: |
Revision as of 08:50, 13 May 2009
- 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
The component must be able to create single factories for each service implementation it contains and return them in the static component operation __getServiceFactory()
. The OpenOffice.org Java UNO environment provides a Java class com.sun.star.comp.loader.FactoryHelper
that creates a default implementation of a single factory through its method getServiceFactory()
. The following example could be written:
package org.openoffice.comp.test; import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.registry.XRegistryKey; import com.sun.star.comp.loader.FactoryHelper; public class ImageShrink ... { ... // static __getServiceFactory() implementation // static member __serviceName was introduced above for XServiceInfo implementation public static XSingleServiceFactory __getServiceFactory(String implName, XMultiServiceFactory multiFactory, com.sun.star.registry.XRegistryKey regKey) { com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals( ImageShrink.class.getName()) ) xSingleServiceFactory = FactoryHelper.getServiceFactory(ImageShrink.class, ImageShrink.__serviceName, multiFactory, regKey); return xSingleServiceFactory; } ... }
The FactoryHelper
is contained in the jurt jar file. The getServiceFactory()
method takes as a first argument a Class
object. When createInstance()
is called on the default factory, it creates an instance of that Class
using newInstance()
on it and retrieves the implementation name through getName()
. The second argument is the service name. The multiFactory
and regKey
arguments were received in __getServiceFactory()
and are passed to the FactoryHelper
.
The default factory created by the FactoryHelper
expects a public constructor in the implementation class of the service and calls it when it instantiates the service implementation. The constructor can be a default constructor, or it can take a com.sun.star.uno.XComponentContext or a com.sun.star.lang.XMultiServiceFactory as an argument. Refer to Create Instance with Arguments for other arguments that are possible.
Java components are housed in jar files. When a component has been registered, the registry contains the name of the jar file, so that the service manager can find it. However, because a jar file can contain several class files, the service manager must be told which one contains the __getServiceFactory()
method. That information has to be put into the jar's Manifest file, for example:
RegistrationClassName: org.openoffice.comp.test.ImageShrink
Content on this page is licensed under the Public Documentation License (PDL). |