Class Definition with Helper Class

From Apache OpenOffice Wiki
Jump to: navigation, search

XInterface, XTypeProvider and XWeak

The Java UNO environment contains Java helper classes that implement the majority of the core interfaces that are implemented by UNO components. There are two helper classes:

  • The helper is the minimal base class and implements XInterface, XTypeProvider and Xweak.
  • The helper that extends WeakBase and implements XComponent.

The is the only interface that should be implemented, but it is not part of the helpers.

Use the naming conventions described in section XServiceInfo for the service implementation. Following the rules, a service org.openoffice.test.ImageShrink should be implemented in org.openoffice.comp.test.ImageShrink.

A possible class definition that uses WeakBase could look like this:

  package org.openoffice.comp.test;
  public class ImageShrink extends 
          org.openoffice.test.XImageShrinkFilter { xComponentContext = null;
      /** Creates a new instance of ImageShrink */
      public ImageShrink( XComponentContext xContext) {
          this.xComponentContext = xContext;


If the implementation only supports one service, use the following code to implement XServiceInfo:

  //XServiceInfo implementation
  // hold the service name in a private static member variable of the class
  protected static final String __serviceName = "org.openoffice.test.ImageShrink";
  public String getImplementationName( ) {
      return getClass().getName();
  public boolean supportsService(String serviceName) {
      return serviceName.equals( __serviceName);
  public String[] getSupportedServiceNames( ) {
      return new String[] { __serviceName };

An implementation of more than one service in one UNO object is more complex. It has to return all supported service names in getSupportedServiceNames(), furthermore it must check all supported service names in supportsService(). Note that several services packaged in one component file are not discussed here, but objects supporting more than one service. Refer to A Component implementing three UNO objects for the implementation of srv3_4.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages