Difference between revisions of "Documentation/DevGuide/WritingUNO/Simple Component in Java"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Writing UNO Components)
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/WritingUNO/Class Definition with Helper Class
 
|NextPage=Documentation/DevGuide/WritingUNO/Class Definition with Helper Class
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Simple Component in Java}}
 
{{DISPLAYTITLE:Simple Component in Java}}
 
This section shows how to write Java components. The examples in this chapter are in the samples folder that was provided with the programmer's manual.  
 
This section shows how to write Java components. The examples in this chapter are in the samples folder that was provided with the programmer's manual.  
Line 13: Line 14:
  
 
The method that provides single factories for the service implementations in a component is <code>__getServiceFactory()</code>:
 
The method that provides single factories for the service implementations in a component is <code>__getServiceFactory()</code>:
<source lang="java">
+
<syntaxhighlight lang="java">
 
   public static XSingleServiceFactory __getServiceFactory(String implName,
 
   public static XSingleServiceFactory __getServiceFactory(String implName,
 
                                       XMultiServiceFactory multiFactory,
 
                                       XMultiServiceFactory multiFactory,
 
                                       XRegistryKey regKey)
 
                                       XRegistryKey regKey)
</source>
+
</syntaxhighlight>
 
In theory, a client obtains a single factory from a component by calling <code>__getServiceFactory()</code> on the component implementation directly. This is rarely done because in most cases service manager is used to get an instance of the service implementation. The service manager uses <code>__getServiceFactory()</code> at the component to get a factory for the requested service from the component, then asks this factory to create an instance of the one object the factory supports.
 
In theory, a client obtains a single factory from a component by calling <code>__getServiceFactory()</code> on the component implementation directly. This is rarely done because in most cases service manager is used to get an instance of the service implementation. The service manager uses <code>__getServiceFactory()</code> at the component to get a factory for the requested service from the component, then asks this factory to create an instance of the one object the factory supports.
  
 
To find a requested service implementation, the service manager searches its registry database for the location of the component jar that contains this implementation. For this purpose, the component must have been registered beforehand. UNO components are able to write the necessary information on their own through a function that performs the registration and which can be called by the registration tool ''regcomp''. The function has this signature:
 
To find a requested service implementation, the service manager searches its registry database for the location of the component jar that contains this implementation. For this purpose, the component must have been registered beforehand. UNO components are able to write the necessary information on their own through a function that performs the registration and which can be called by the registration tool ''regcomp''. The function has this signature:
<source lang="java">
+
<syntaxhighlight lang="java">
 
   public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)  
 
   public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)  
</source>
+
</syntaxhighlight>
 
These two methods work together to make the implementations in a component available to a service manager. The method <code>__writeRegistryServiceInfo()</code> tells the service manager where to find an implementation while <code>__getServiceFactory()</code> enables the service manager to instantiate a service implementation, once found.
 
These two methods work together to make the implementations in a component available to a service manager. The method <code>__writeRegistryServiceInfo()</code> tells the service manager where to find an implementation while <code>__getServiceFactory()</code> enables the service manager to instantiate a service implementation, once found.
  
Line 35: Line 36:
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Professional UNO]]
+
[[Category:Documentation/Developer's Guide/Writing UNO Components]]

Latest revision as of 17:28, 23 December 2020

  • Simple Component in Java



This section shows how to write Java components. The examples in this chapter are in the samples folder that was provided with the programmer's manual.

A Java component is a library of Java classes (a jar) containing objects that implement arbitrary UNO services. For a service implementation in Java, implement the necessary UNO core interfaces and the interfaces needed for your purpose. These could be existing interfaces or interfaces defined by using UNOIDL.

Besides these service implementations, Java components need two methods to instantiate the services they implement in a UNO environment: one to get single factories for each service implementation in the jar, and another one to write registration information into a registry database. These methods are called static component operations in the following:

The method that provides single factories for the service implementations in a component is __getServiceFactory():

  public static XSingleServiceFactory __getServiceFactory(String implName,
                                      XMultiServiceFactory multiFactory,
                                      XRegistryKey regKey)

In theory, a client obtains a single factory from a component by calling __getServiceFactory() on the component implementation directly. This is rarely done because in most cases service manager is used to get an instance of the service implementation. The service manager uses __getServiceFactory() at the component to get a factory for the requested service from the component, then asks this factory to create an instance of the one object the factory supports.

To find a requested service implementation, the service manager searches its registry database for the location of the component jar that contains this implementation. For this purpose, the component must have been registered beforehand. UNO components are able to write the necessary information on their own through a function that performs the registration and which can be called by the registration tool regcomp. The function has this signature:

  public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)

These two methods work together to make the implementations in a component available to a service manager. The method __writeRegistryServiceInfo() tells the service manager where to find an implementation while __getServiceFactory() enables the service manager to instantiate a service implementation, once found.

The necessary steps to write a component are:

  1. Define service implementation classes.
  2. Implement UNO core interfaces.
  3. Implement your own interfaces.
  4. Provide static component operations to make your component available to a service manager.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages