Simple Component in Java
- Simple Component in Java
- 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
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
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:
- Define service implementation classes.
- Implement UNO core interfaces.
- Implement your own interfaces.
- 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).|