Implementing Your Own Interfaces

From Apache OpenOffice Wiki
Jump to: navigation, search

The functionality of a component is accessible only by its interfaces. When writing a component, choose one of the available API interfaces or define an interface. UNO types are used as method arguments to other UNO objects. Java does not support unsigned integer types, so their use is discouraged. In the chapter Using UNOIDL to Specify New Components, the org.openoffice.test.XImageShrinkFilter interface specification was written and an interface class file was created. Its implementation is straightforward, you create a class that implements your interfaces:

  package org.openoffice.comp.test;
  public class ImageShrink extends
                     org.openoffice.test.XImageShrinkFilter {
      String destDir = "";
      String sourceDir = "";
      boolean cancel = false; dimension = new;
      // XImageShrink implementation (a sub-interface of XImageShrinkFilter) 
      public void cancel() {
          cancel = true;
      public boolean filter([] propertyValue) {
          // while cancel = false, 
          // scale images found in sourceDir according to dimension and 
          // write them to destDir, using the image file format given in 
          // []propertyValue
          // (implementation omitted)
          cancel = false;
          return true;
      // XIMageShrink implementation 
      public String getDestinationDirectory() {
          return destDir;
      public getDimension() {
          return dimension;
      public String getSourceDirectory() {
          return sourceDir;
      public void setDestinationDirectory(String str) {
          destDir = str;
      public void setDimension( size) {
          dimension = size;
      public void setSourceDirectory(String str) {
          sourceDir = str;

For the component to run, the new interface class file must be accessible to the Java Virtual Machine. Unlike stand-alone Java applications, it is not sufficient to set the CLASSPATH environment variable. Instead, the class path is passed to the VM when it is created. Prior to 1.1.0, one could modify the class path by editing the SystemClasspath entry of the java(.ini|rc) which was located in the folder <officepath>\user\config. Another way was to use the Options dialog. To navigate to the class path settings, one had to expand the node in the tree on the left-hand side and chose Security. On the right-hand side, there was a field called User Classpath.

As of 1.1.0 the component, class files, and type library are packed into a extension, which is then registered by the pkgchk executable. And as of 2.0, the unopkg tool is used to do this. The jar files are then automatically added to the class path.

Documentation note.png It is also important that the binary type library of the new interfaces are provided together with the component, otherwise the component is not accessible from Basic. Basic uses the UNO core reflection service to get type information at runtime. The core reflection is based on the binary type library.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages