Difference between revisions of "General UNO Component Project Type"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Generated Code)
(Time Frame)
Line 160: Line 160:
= Time Frame =
= Time Frame =
Another update of this wizard is due on Novemner, 30th.
Another update of this wizard is due on November, 30th.

Revision as of 10:36, 7 November 2006


The StarOffice/OpenOffice.org Component wizard creates a new project based on a J2SE class library project and supports additional targets to create a complete office extension package and to deploy this package into the configured office installation.
The wizard collects all necessary information and allows the selection of exisiting services and interfaces which should be implemented. In the same wizard step it is also possible to define completely new services and interfaces to design abstract interfaces for a completely new functionality.
After finishing the wizard you can directly build the project and can create and deploy the office extension package in your office. All interface methods are default implemented and do nothing. In a second step you can insert your implementation in the generated skeleton, rebuild the extension and deploy it again to see the effect in your office.

Project Wizard

The project wizard is quite simple to use, you simply choose

  • File -> New Project -> StarOffice/OpenOffice.org -> StarOffice/OpenOffice.org Component

and follow the wizard.

  • Step 1: Selecting the project type


  • Step 2: Defining the project name, implementation class name, an package and the project location


  • Step 4: Specifiy or define the UNO IDL services and interfaces which should be implemented


Component TypeBrowser.png

Component Service.png

Component Interface.png

You can simply create or deploy the oxt extension package by choosing:

Project View -> Project Node -> Context Menu -> Create OXT|Deploy Office Extension

When you have deployed the package the usage of the new UNO component in your office is straight forward. Either you have implemented a special service provider interface (SPI) and can use it in the same way as any other implementations of this SPI can be used or you have defined some new service and/or interfaces and can instantiate your component as a normal service over the global service manager.

Generated Code

For a UNO component the wizard generates more code. But it depends on the selected UNO IDL types. If only existing types are selected and no new UNO IDL types are defned the wizard won't generate any UNO IDL files. For the above shown example the following files are generated:

  • uno-extension-manifest.xml
    the package descriptor, will be packed as "META-INF/manifest.xml". The content of the uno-extension-manifest.xml depends on the seletection or definition of the IDL types. If no new types are defined, no type library is specified.

[xml] <?xml version="1.0" encoding="UTF-8"?> <manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">

 <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"
 <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"


  • org/openoffice/test/MyTestService.idl
    the test service definition

[idl] /*

* MyTestService.idl
* Created on 11.09.2006 - 17:42:17
  1. ifndef _org_openoffice_test_MyTestService_
  2. define _org_openoffice_test_MyTestService_
  1. include "XMyTest.idl"

module org { module openoffice { module test {

   service MyTestService : XMyTest;

}; }; };

  1. endif

  • org/openoffice/test/XMyTest.idl
    the test interface definition

[idl] /*

* XMyTest.idl
* Created on 11.09.2006 - 17:42:17
  1. ifndef _org_openoffice_test_XMyTest_
  2. define _org_openoffice_test_XMyTest_
  1. include <com/sun/star/uno/XInterface.idl>

module org { module openoffice { module test {

   interface XMyTest {
       string helloWorld([in] string sMessage);
           raises ( com::sun::star::lang::IllegalArgumentException );

}; }; };

  1. endif
  • org/openoffice/test/TestComponentImpl.java
    the generated code skeleton where all selected services and interface are default implemented plus some UNO component base interfaces, so that the new generated project can be build and the extension can be deployed directly.

[java] package org.openoffice.test;

import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.registry.XRegistryKey; import com.sun.star.lib.uno.helper.WeakBase;

public final class TestComponentImpl extends WeakBase

  implements com.sun.star.lang.XServiceInfo,


   private final XComponentContext m_xContext;
   private static final String m_implementationName = TestComponentImpl.class.getName();
   private static final String[] m_serviceNames = {
       "org.openoffice.test.MyTestService" };

   public TestComponentImpl( XComponentContext context )
       m_xContext = context;
   public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) {
       XSingleComponentFactory xFactory = null;
       if ( sImplementationName.equals( m_implementationName ) )
           xFactory = Factory.createComponentFactory(TestComponentImpl.class, m_serviceNames);
       return xFactory;
   public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey ) {
       return Factory.writeRegistryServiceInfo(m_implementationName,
   // com.sun.star.lang.XServiceInfo:
   public String getImplementationName() {
        return m_implementationName;
   public boolean supportsService( String sService ) {
       int len = m_serviceNames.length;
       for( int i=0; i < len; i++) {
           if (sService.equals(m_serviceNames[i]))
               return true;
       return false;
   public String[] getSupportedServiceNames() {
       return m_serviceNames;
   // org.openoffice.test.XMyTest:
   public String helloWorld(String sMessage) throws com.sun.star.lang.IllegalArgumentException
       // TODO !!!
       // Exchange the default return implementation.
       // NOTE: Default initialized polymorphic structs can cause problems
       // because of missing default initialization of primitive types of
       // some C++ compilers or different Any initialization in Java and C++
       // polymorphic structs.
       return new String();


Time Frame

Another update of this wizard is due on November, 30th.

Personal tools