How to access OpenOffice or Sun ONE Webtop from remote |
Contents |
|||||||||||
Introduction |
|||||||||||
Introduction |
|||||||||||
If you want to access an Office service from a program written in the programming language Java, first both environments should be connected with each other. Java and Office act as a client-server environment. Office plays the role of the server while the Java program figures as the client. Because you don't want to distinguish between local and remote UNO calls, you have to create an interprocess bridge. |
|||||||||||
Using the component UnoUrlResolver |
|||||||||||
At first, a simple service manager will be created by calling the static method createSimpleServiceManager() from the class com.sun.star.comp.helper.Bootstrap.
The created service manager is able to create the service UnoUrlResolver, if this service was registered before.
Comparable to casting in C++ the class UnoRuntime provides a method queryInterface() for getting an object that has all methods from the interface XUnoUrlResolver.
Now, the object xurlresolver resolves the
object that is specified as follow: At this point the Java program (client) will
connect to the office (server) that was run with the command:
Finally a XMultiServiceFactory
will be created, which allows the acces to the running office.
All program fragments described above are summarized in the following.
|
|||||||||||
Creating an interprocess bridge |
|||||||||||
First of all the servicemanager is needed because the servicemanager allows to instantiate the service Connector. The class Bootstrap provides a method that will create a simple servicemanager.
The servicemanager creates a new instance of the service Connector, which allows to establish a connection to another process (in that case: Office).
The method queryInterface queries for the new interface XConnector to the existing UNO object objectConnector.
The client (Java code) will contact the server (running office) if the office is launched for example with the following option: "soffice -accept=socket,host=localhost,port=8100;urp". Here, the UNO Remote Protocol is used to transmit UNO calls via process-boundaries ( comparable to iiop in CORBA). The connection description contains the kind of the connection plus a comma seperated list of attributes. In this case a TCP/IP connection is specified.
The service NamingService provides a collection of global reachable objects. Normally an UNO application exposes its external reachable objects through this service. The StarOffice naming service can be addressed as "StarOffice.NamingService".
In order to create a new bridge between the environment Java and the environment Office the method "getBridgeByName" of the class UnoRuntime should be called. That method needs five arguments:
The interface IBridge maps an object from the destination environment (Office) to the source environment (Java). The name of the object, which should be mapped, and the interface, under which the object should be mapped, are passed on to the bridge.
The method queryInterface queries for the new interface XNamingService to the existing UNO object objectInitial.
The method getRegisteredObject of the interface XNamingService provides a previous registered object: The service manager of the currrent office. Furthermore, there is a query for the interface XMultiServiceFactory to the existing service manager.
|
|||||||||||
Summary |
|||||||||||
All program fragments described above are summarized in the following.
|
|||||||||||
|
|||||||||||
|
|||||||||||
Author: Bertram
Nolte (Fri 3 Aug 2001 15:46:08) |
|||||||||||
|