Difference between revisions of "Documentation/DevGuide/WritingUNO/Class Definition with Helper Class"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Documentation/Developers Guide/Writing UNO Components) |
m |
||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/WritingUNO/Implementing Your Own Interfaces | |NextPage=Documentation/DevGuide/WritingUNO/Implementing Your Own Interfaces | ||
}} | }} | ||
+ | [[zh:Zh/Documentation/DevGuide/WritingUNO/Class Definition with Helper Class]] | ||
{{DISPLAYTITLE:Class Definition with Helper Class}} | {{DISPLAYTITLE:Class Definition with Helper Class}} | ||
=== XInterface, XTypeProvider and XWeak === | === XInterface, XTypeProvider and XWeak === |
Revision as of 06:03, 25 July 2008
- 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
XInterface, XTypeProvider and XWeak
The OpenOffice.org 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
com.sun.star.lib.uno.helper.WeakBase
is the minimal base class and implementsXInterface
,XTypeProvider
andXweak
. - The helper
com.sun.star.lib.uno.helper.ComponentBase
that extendsWeakBase
and implementsXComponent
.
The com.sun.star.lang.XServiceInfo 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 com.sun.star.lib.uno.helper.WeakBase implements com.sun.star.lang.XServiceInfo, org.openoffice.test.XImageShrinkFilter { com.sun.star.uno.XComponentContext xComponentContext = null; /** Creates a new instance of ImageShrink */ public ImageShrink(com.sun.star.uno.XComponentContext XComponentContext xContext) { this.xComponentContext = xContext; } ... }
XServiceInfo
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) { if ( serviceName.equals( __serviceName)) return true; return false; } 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). |