Difference between revisions of "Documentation/DevGuide/WritingUNO/Implementing Your Own Interfaces"
m (1 revision(s)) |
|||
(11 intermediate revisions by 6 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]--> | ||
− | + | <syntaxhighlight lang="java"> | |
package org.openoffice.comp.test; | package org.openoffice.comp.test; | ||
Line 65: | Line 66: | ||
... | ... | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | 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 <code>SystemClasspath</code> 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 {{AOo}} 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 an extension, which is then registered by the ''pkgchk'' executable. And as of OpenOffice.org 2.0.0, the unopkg tool is used to do this. The jar files are then automatically added to the class path. | |
− | + | {{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 {{AOo}} 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: Writing UNO Components]] | + | |
+ | [[Category:Documentation/Developer's Guide/Writing UNO Components]] |
Latest revision as of 13:36, 24 December 2020
- Class Definition with Helper Class
- Implementing Your Own Interfaces
- Providing a Single Factory Using a Helper Method
- Write Registration Info Using a Helper Method
- Implementing without Helpers
- Storing the Service Manager for Further Use
- Create Instance with Arguments
- Possible Structures for Java Components
- Running and Debugging Java Components
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 Apache OpenOffice 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 an extension, which is then registered by the pkgchk executable. And as of OpenOffice.org 2.0.0, the unopkg tool is used to do this. The jar files are then automatically added to the class path.
Content on this page is licensed under the Public Documentation License (PDL). |