Client applications
A client application is a stand-alone J2SE application that can bootstrap a UNO environment and start the default OpenOffice.org, or connect to a running instance. A client application project is nothing but a standard Java project with an added OpenOffice.org library. As APIs are integrated into NetBeans, features like code completion, error highlighting, the automatic import of packages, etc, are available.

Creating a client application is a straightforward File-new Project-OpenOffice.org-OpenOffice.org Client Application. In the next screen, fill in a project name, say Simple Client, and a suitable package name like org.lfy.example. That's it! Your client application project has been successfully set up.

Now go to 'Project explorer' and open the code for the main method in SimpleClientjava: SimpleClient-Source Packages-org.lfy.example-SimpleClientjava.
A default code to bootstrap office instance is presented in the main method. Replace that with the following code, which is used to load a new Calc document when this client application is run.

The packages required to import are not listed here; but NetBeans will help you for this purpose. You can add some more code to control spreadsheet(s) in the loaded Calc document, depending on your wishes.

Now use the build and run options of the project to test the extension. A new office instance will be created in which a blank Calc document is loaded. Note that the deploy option is not available for a client application because it is a simple 128E application, as mentioned earlier.

This code looks very similar to the add-on code discussed in the previous article, except the first line where the context is already available as add-on code is invoked from the running instance.

Till now we have managed to create three types of projects without knowing much about UNO, so it is better to have a brief overview of UNO and some other terminology like API and IDL before going to the next example.

So do you know UNO?
Universal Network Objects (UNO) provide an environment to use OpenOffice.org services in a language-independent manner across platforms. It is a component model that, unlike others, is not bound to any programming language and offers interoperability between different languages.

UNO components can be created and accessed from any programming language, provided language binding is available for it. Languages like C++ and Java are well supported for UNO and a few more like Python or Ruby, which are under development.

The standalone environment of UNO objects that's isolated from OpenOffice.org is called the UNO Runtime Environment (URE).

000 API
APls are helpful to program 000 through UNO object from many supported programming languages. The main goal of the API project is to offer 000 as a service provider and integrate it with different applications.

IDL files
Interface Definition Langtiage (IDb) files' provide an abstract view of UNO objects. They contain attributes and methods. The IDL language used here is called UNO IDL.

Every interface inherits from Xlnterface. Modules are similar to packages in Java or namespaces in C++. Attributes are supported by get,set methods. Compiled IDL files are then merged with the implementation part to create complete objects.

Here are the steps to create a simple UNO component: File-NewProject-OpenOffice.org-OpenOffice.org Component. In the next screen, give a project name, say Simple UNO, with a suitable package name like org.lfy.example. The next screen is used to include an existing interface/service or create new ones to be added to the UNO component. In this example we will create a new interface called XCountable with the service, Counter.

The steps to create the XCountable interface are: Select Interface-Define New Data. Enter 'Name' as XCountable. ow, for the first method, enter setCount as 'Name' and void as 'Type'. For the parameter in the setCount method, enter nCount as 'Name' and long as 'Type'. Use the 'Next Function' to create the getCount method, where we'll enter getCount as the 'Name' and long as the 'Type'. As we'll not require the 'Parameter' in this case, delete it.

Similarly, create two more methods, increment and decrement, with no parameters and long return type.
The following are the steps to create the counter service: select Service-Define New Data. Enter Counter as the 'Name' and org.lfy.XCountable as the 'Interface'.

Here are the steps to add the counter service: use the Add Service/Interface option and navigate to org-ify-example-Counter to add it.

After all the steps are done, the wizard will look like what's shown in Figure 5.

Now click on the Finish button to complete the creation of the project. Observe the created IDL files XCountable.idl and Counter.idl in the project explorer to get a better idea about IDL files.

Use the Deploy and Run Extension in OpenOffice. org option to build and deploy this newly created UNO component.

At any time, if the deployment of an extension fails, make sure that the correct version of JRE is set under Tools-Options-OpenOffice. org-Java.
In this example, we have created a new service. We can also use an existing service to modify or enhance it. On understanding this sample component, you can develop real components to avail the services of 000.


Name:  openoffice.org with extension.jpg
Views: 307
Size:  52.9 KB