Difference between revisions of "Documentation/DevGuide/WritingUNO/Implementing Your Own Interfaces"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Writing UNO)
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/WritingUNO/Providing a Single Factory Using a Helper Method
 
|NextPage=Documentation/DevGuide/WritingUNO/Providing a Single Factory Using a Helper Method
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Implementing Your Own Interfaces}}
 
{{DISPLAYTITLE:Implementing Your Own Interfaces}}
 
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 [[Documentation/DevGuide/WritingUNO/Using UNOIDL to Specify New Components|Using UNOIDL to Specify New Components]], the <code>org.openoffice.test.XImageShrinkFilter</code> interface specification was written and an interface class file was created. Its implementation is straightforward, you create a class that implements your interfaces: <!--[SOURCE:Components/Thumbs/org/openoffice/comp/test/ImageShrink.java]-->
 
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 [[Documentation/DevGuide/WritingUNO/Using UNOIDL to Specify New Components|Using UNOIDL to Specify New Components]], the <code>org.openoffice.test.XImageShrinkFilter</code> interface specification was written and an interface class file was created. Its implementation is straightforward, you create a class that implements your interfaces: <!--[SOURCE:Components/Thumbs/org/openoffice/comp/test/ImageShrink.java]-->
Line 70: Line 71:
 
As of {{PRODUCTNAME}} {{OO1.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 {{PRODUCTNAME}} {{OO2.0.0}}, the unopkg tool is used to do this. The jar files are then automatically added to the class path.
 
As of {{PRODUCTNAME}} {{OO1.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 {{PRODUCTNAME}} {{OO2.0.0}}, the unopkg tool is used to do this. The jar files are then automatically added to the class path.
  
{{Documentation/Note|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 {{PRODUCTNAME}} Basic. Basic uses the UNO core reflection service to get type information at runtime. The core reflection is based on the binary type library.}}
+
{{Note|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 {{PRODUCTNAME}} Basic. Basic uses the UNO core reflection service to get type information at runtime. The core reflection is based on the binary type library.}}
  
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Writing UNO Components]]
+
[[Category:Documentation/Developer's Guide/Writing UNO Components]]

Revision as of 14:55, 4 July 2018



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 com.sun.star.lib.uno.helper.WeakBase
        implements com.sun.star.lang.XServiceInfo,
                     org.openoffice.test.XImageShrinkFilter {
 
      ...
 
      String destDir = "";
      String sourceDir = "";
      boolean cancel = false;
      com.sun.star.awt.Size dimension = new com.sun.star.awt.Size();
 
      // XImageShrink implementation (a sub-interface of XImageShrinkFilter) 
 
      public void cancel() {
          cancel = true;
      }
 
      public boolean filter(com.sun.star.beans.PropertyValue[] 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 com.sun.star.awt.Size getDimension() {
          return dimension;
      }
 
      public String getSourceDirectory() {
          return sourceDir;
      }
 
      public void setDestinationDirectory(String str) {
          destDir = str;
      }
 
      public void setDimension(com.sun.star.awt.Size 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 OpenOffice.org 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 OpenOffice.org 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 OpenOffice.org 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 OpenOffice.org 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 OpenOffice.org 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