Difference between revisions of "General UNO Component Project Type"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Use case Example : OOoBasic Macro Call)
(See also)
 
(27 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
Back to [[OpenOffice_NetBeans_Integration|OpenOffice.org NetBeans Integration]]
 +
 
__TOC__
 
__TOC__
  
 
= Overview =
 
= Overview =
  
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.<br>
+
The OpenOffice.org Component wizard creates a new project based on a J2SE class library project and supports additional targets to create a complete OpenOffice.org extension package and to deploy this package into the configured OpenOffice.org installation.<br>
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.<br>
+
The wizard collects all necessary information and allows you to select the existing services and interfaces that should be implemented. In the same wizard step you can also define completely new services and interfaces (and additional data types based on IDL) to design abstract interfaces for completely new functionality.<br>
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.
+
After finishing the wizard you can directly build the project and can create and deploy the OpenOffice.org extension package. All interface methods are implemented by default, 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.
  
 
= Project Wizard =
 
= Project Wizard =
 
The project wizard is quite simple to use, you simply choose
 
The project wizard is quite simple to use, you simply choose
*'' '''File -> New Project -> StarOffice/OpenOffice.org -> StarOffice/OpenOffice.org Component''' ''
+
*'' '''File -> New Project -> OpenOffice.org -> OpenOffice.org Component''' ''
 
and follow the wizard.
 
and follow the wizard.
  
* '''Step 1''': Selecting the project type
+
* '''Step 1''': Select the project type
 
<br>[[Image:Component1.png|center]]<br>
 
<br>[[Image:Component1.png|center]]<br>
* '''Step 2''': Defining the project name, implementation class name, an package and the project location  
+
* '''Step 2''': Define the project name, implementation class name, an package and the project location  
 
<br>[[Image:Component2.png|center]]<br>
 
<br>[[Image:Component2.png|center]]<br>
* '''Step 4''': Specifiy or define the UNO IDL services and interfaces which should be implemented
+
* '''Step 4''': Specifiy or define the UNO IDL services and interfaces which should be implemented.
<br>[[Image:Component3.png|center]]<br>
+
** To provide an own defined interface, choose the '''Interface''' node and click on '''Define New Data Type'''<br><br>[[Image:Component_Interface1.png|center]]<br><br>
<br>[[Image:Component_TypeBrowser.png|center]]<br>
+
** Create the interface as shown in this picture<br><br>[[Image:Component_Interface.png|center]]<br><br>
<br>[[Image:Component_Service.png|center]]<br>
+
** Back at the New Project window, select the '''Service''' node and click again on '''Define New Data Type'''. Create the service as follows:<br><br>[[Image:Component_Service.png|center]]<br><br>
<br>[[Image:Component_Interface.png|center]]<br>
+
** Back at the New Project window, click on '''Add Service/Interface'''. Select the new created service. The interface will be added automatically:<br><br>[[Image:Component_TypeBrowser.png|center]]<br><br>
 +
** When everything looks like this, click '''OK''':<br><br>[[Image:Component3.png|center]]<br><br>
 +
 
  
 
You can simply create or deploy the '''oxt''' extension package by choosing:<br>
 
You can simply create or deploy the '''oxt''' extension package by choosing:<br>
::'''Project View -> Project Node -> Context Menu -> Create OXT|Deploy Office Extension'''<br><br>
+
::'''Project View -> Project Node -> Context Menu -> Deploy and Run Extension in OpenOffice.org'''<br><br>
  
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.
+
When you have deployed the package, the usage of the new UNO component in OpenOffice.org 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 =
 
= 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:
+
The wizard generates more code for a UNO component, but it depends on the selected UNO IDL types. If only existing types are selected and no new UNO IDL types are defined, the wizard will not generate any UNO IDL files.  For the example shown above, the following files are generated:
  
* '''uno-extension-manifest.xml'''<br>the package descriptor, will be packed as &quot;META-INF/manifest.xml&quot;. 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.
+
* '''uno-extension-manifest.xml'''<br>the package descriptor, will be packed as &quot;META-INF/manifest.xml&quot;. The content of the uno-extension-manifest.xml depends on the selection or definition of the IDL types. If no new types are defined, no type library is specified. Own IDL types are packed in an additional jar referenced here. Without new IDL types, this jar will also not exist.
<code>[xml]
+
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
 
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
Line 38: Line 42:
 
   <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
 
   <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
 
                       manifest:full-path="TestComponent.jar"/>
 
                       manifest:full-path="TestComponent.jar"/>
 +
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=Java"
 +
                      manifest:full-path="TestComponent_IDL_types.jar"/>
 
</manifest:manifest>
 
</manifest:manifest>
</code>
+
</source>
 
* '''org/openoffice/test/MyTestService.idl'''<br>the test service definition
 
* '''org/openoffice/test/MyTestService.idl'''<br>the test service definition
<code>[idl]
+
<source lang="idl">
 
/*
 
/*
 
  * MyTestService.idl
 
  * MyTestService.idl
Line 59: Line 65:
  
 
#endif
 
#endif
</code>
+
</source>
 
* '''org/openoffice/test/XMyTest.idl'''<br>the test interface definition
 
* '''org/openoffice/test/XMyTest.idl'''<br>the test interface definition
<code>[idl]
+
<source lang="idl">
 
/*
 
/*
 
  * XMyTest.idl
 
  * XMyTest.idl
Line 82: Line 88:
 
}; }; };
 
}; }; };
  
#endif</code>
+
#endif
* '''org/openoffice/test/TestComponentImpl.java'''<br>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.
+
</source>
<code>[java]
+
* '''org/openoffice/test/TestComponentImpl.java'''<br>the generated code skeleton where all selected services and interface are implemented by defualt plus some UNO component base interfaces, so that the newly generated project can be built and the extension can be deployed directly.
 +
<source lang="java">
 
package org.openoffice.test;
 
package org.openoffice.test;
  
Line 108: Line 115:
 
     {
 
     {
 
         m_xContext = context;
 
         m_xContext = context;
     };
+
     }
  
 
     public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) {
 
     public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) {
Line 152: Line 159:
 
         // some C++ compilers or different Any initialization in Java and C++
 
         // some C++ compilers or different Any initialization in Java and C++
 
         // polymorphic structs.
 
         // polymorphic structs.
         return new String();
+
         return "";
 
     }
 
     }
  
 
}
 
}
</code>
+
</source>
  
== Use case Example : OOoBasic Macro Call ==
+
= Result Use Example : OOoBasic Macro Call =
  
For using the previous skeleton for an OOoBasic service call, we only have to alter the last method helloWorld and adding 2 lines
+
For using the previous skeleton for an OOoBasic service call, we only have to alter the last method helloWorld and redeploy the oxt extension
<code>[java]
+
<source lang="java">
 
     // org.openoffice.test.XMyTest:
 
     // org.openoffice.test.XMyTest:
 
     public String helloWorld(String message)
 
     public String helloWorld(String message)
 
     {
 
     {
         String response = new String();
+
         String response = "Hello " + message;   
        response = "Hello " + message;   
+
 
         return response;
 
         return response;
 
     }
 
     }
</code>
+
</source>
  
Then, opening a new OpenOffice.org, your component is available for any macro you may need. It is seen as any legacy service and is manipulated the same way. Even introspection with xRay is available, letting you to verify that all your properties and methods are available.
+
Then, opening a new OpenOffice.org, your component is available for any macro you may need. It is seen as any legacy service and is manipulated the same way. Even introspection is available, letting you verify that all your properties and methods are available, as the xRay call can show.
<code>[oobas]
+
<source lang="oobas">
 
sub TestHelloWorld()
 
sub TestHelloWorld()
' Create the new UNo service
+
' Create the new UNO service
 
myService = createUNOService("org.openoffice.test.MyTestService")
 
myService = createUNOService("org.openoffice.test.MyTestService")
' The new service with its properties é methods is available
+
' The new service with its properties & methods is available
 
msgbox myService.helloWorld ("Laurent")
 
msgbox myService.helloWorld ("Laurent")
 
' It is also available through Xray introspection
 
' It is also available through Xray introspection
 
xRay myService
 
xRay myService
 
end sub
 
end sub
</code>
+
</source>
[[Image:hello_testing_netbeans.png&|center]]
+
{| border="0"
[[Image:xray_helloworld_netbeans.png|center]]
+
|-
 +
| [[Image:hello_testing_netbeans.png|center]]
 +
| [[Image:xray_helloworld_netbeans.png|center]]
 +
|}
 +
 
  
= Time Frame =
 
  
Another update of this wizard is due on November, 30th.
+
= See also =
 +
* Daniel Bölzle's tutorial : [[Uno/Cpp/Tutorials/component_tutorial|Writing a simple UNO component]]
 +
* [[Documentation/DevGuide/WritingUNO/Writing_UNO_Components|Writing UNO Components]] in Developer's Guide
 +
* [[Constructing_Components|Constructing Components in C++]]
 +
* [[Extensions_Packager|Extensions Packager]] (BasicAddonBuilder from [mailto:paolomantovani@openoffice.org Paolo Mantovani])
 +
* [[BASIC/UNO_Object_Browser|BASIC UNO Object Browser]] : You can see the corresponding code as a complex component.
 +
* [[API/Samples/Java/Office/MinimalComponent|Minimal Java Component]]
  
 
[[Category:Uno]]
 
[[Category:Uno]]
[[Category:Development]]
 
 
[[Category:Extensions]]
 
[[Category:Extensions]]
 +
[[Category:API]]

Latest revision as of 13:10, 28 March 2010

Back to OpenOffice.org NetBeans Integration

Overview

The OpenOffice.org Component wizard creates a new project based on a J2SE class library project and supports additional targets to create a complete OpenOffice.org extension package and to deploy this package into the configured OpenOffice.org installation.
The wizard collects all necessary information and allows you to select the existing services and interfaces that should be implemented. In the same wizard step you can also define completely new services and interfaces (and additional data types based on IDL) to design abstract interfaces for completely new functionality.
After finishing the wizard you can directly build the project and can create and deploy the OpenOffice.org extension package. All interface methods are implemented by default, 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.

Project Wizard

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

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

and follow the wizard.

  • Step 1: Select the project type

Component1.png

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

Component2.png

  • Step 4: Specifiy or define the UNO IDL services and interfaces which should be implemented.
    • To provide an own defined interface, choose the Interface node and click on Define New Data Type

      Component Interface1.png


    • Create the interface as shown in this picture

      Component Interface.png


    • Back at the New Project window, select the Service node and click again on Define New Data Type. Create the service as follows:

      Component Service.png


    • Back at the New Project window, click on Add Service/Interface. Select the new created service. The interface will be added automatically:

      Component TypeBrowser.png


    • When everything looks like this, click OK:

      Component3.png



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

Project View -> Project Node -> Context Menu -> Deploy and Run Extension in OpenOffice.org

When you have deployed the package, the usage of the new UNO component in OpenOffice.org 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

The wizard generates more code for a UNO component, but it depends on the selected UNO IDL types. If only existing types are selected and no new UNO IDL types are defined, the wizard will not generate any UNO IDL files. For the example shown above, 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 selection or definition of the IDL types. If no new types are defined, no type library is specified. Own IDL types are packed in an additional jar referenced here. Without new IDL types, this jar will also not exist.
<?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:full-path="types.rdb"/>
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
                       manifest:full-path="TestComponent.jar"/>
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=Java"
                       manifest:full-path="TestComponent_IDL_types.jar"/>
</manifest:manifest>
  • org/openoffice/test/MyTestService.idl
    the test service definition
/*
 * MyTestService.idl
 *
 * Created on 11.09.2006 - 17:42:17
 *
 */
 
#ifndef _org_openoffice_test_MyTestService_
#define _org_openoffice_test_MyTestService_
 
#include "XMyTest.idl"
 
module org { module openoffice { module test {
    service MyTestService : XMyTest;
}; }; };
 
#endif
  • org/openoffice/test/XMyTest.idl
    the test interface definition
/*
 * XMyTest.idl
 *
 * Created on 11.09.2006 - 17:42:17
 *
 */
 
#ifndef _org_openoffice_test_XMyTest_
#define _org_openoffice_test_XMyTest_
 
#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 );
    };
}; }; };
 
#endif
  • org/openoffice/test/TestComponentImpl.java
    the generated code skeleton where all selected services and interface are implemented by defualt plus some UNO component base interfaces, so that the newly generated project can be built and the extension can be deployed directly.
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,
              org.openoffice.test.XMyTest
{
    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,
                                                m_serviceNames,
                                                xRegistryKey);
    }
 
    // 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 "";
    }
 
}

Result Use Example : OOoBasic Macro Call

For using the previous skeleton for an OOoBasic service call, we only have to alter the last method helloWorld and redeploy the oxt extension

    // org.openoffice.test.XMyTest:
    public String helloWorld(String message)
    {
        String response = "Hello " + message;   
        return response;
    }

Then, opening a new OpenOffice.org, your component is available for any macro you may need. It is seen as any legacy service and is manipulated the same way. Even introspection is available, letting you verify that all your properties and methods are available, as the xRay call can show.

sub TestHelloWorld()
	' Create the new UNO service
	myService = createUNOService("org.openoffice.test.MyTestService")
	' The new service with its properties & methods is available
	msgbox myService.helloWorld ("Laurent")
	' It is also available through Xray introspection
	xRay myService
end sub
Hello testing netbeans.png
Xray helloworld netbeans.png


See also

Personal tools