UNOjava组件的创建流程
2012-09-26 11:16
134 查看
UNO Components
This section will explain some very basic things about UNO components. You can skip it if you already know it. First I will explain what a component is and its main parts. Afterwards, I will explain what is needed to create a UNO component to help you tofully understand the different tools and their use during the tutorial.
Components anatomy
"A component is a system element offering a predefined service and able to communicate with other components" explainsWikipedia(Fr) (Even thought there is a definition on the English wikipedia article, I prefer the French one because of its completeness). In UNOs case a component will generally be delivered as a package containing a library (share library in C++ or jar in Java).
For UNO, a component is made of two distinct parts: specifications and an implementation.
Specification: definition in a common language of what the component should do. For UNO, this language is called UNO-IDL and is more or less similar toCorba
IDL. The documented part that will be provided as an API to use the component is the specification. Thus, it should be complete and implementation independent.
Implementation: is the code that will realize what is described in the component specifications. This programming language can either be C++, Java, Python or others. This is the internal part of the component and will not be accessible
from another component.
In order that UNO knows which implementation corresponds to which specification, the component will use registries. There are two of them: the first one describes all the component specifications (types.rdb) and the second translates the implementation
into specifications (services.rdb) and is generated from the implementation.
Components creation process
The following diagram will help you better understand what should be done to get a component from its specification and sources. As shown by the diagram, the specifications are compiled and merged into onetypes.rdb registry.Class filesare generated from that file to translate the specifications into a Java class definition file which is built with the implementation into a class using thejava compiler. All the classes are delivered as ajar file with a specific manifest
as we will see further in this tutorial. This doesn't make a usable OpenOffice.org: thetypes.rdb andjar file will have to be zipped into a.uno.pkg file described with another manifest.
![](http://wiki.openoffice.org/w/images/a/af/CompilationChain.png)
http://wiki.openoffice.org/wiki/JavaEclipseTuto
例子:
0. prepare environment
cd /usr/lib64/openoffice.org/basis3.1/sdk
./setsdkenv_unix
1. create interface
XHelloWorld.idl
HelloWorld.idl
用idl语言来描述你自己需要向外部暴露的接口
2. idlc
idlc -C -I$OO_SDK_HOME/idl XHelloWorld.idl
idlc -C -I$OO_SDK_HOME/idl HelloWorld.idl
3. /UCR key (UNO core reflection)
regmerge thumbs.rdb /UCR XHelloWorld.urd
regmerge thumbs.rdb /UCR HelloWorld.urd
#check it
regview thumbs.rdb
4.
javamaker -Gc -BUCR -O./classes $OO_SDK_URE_HOME/share/misc/types.rdb thumbs.rdb
5. implements interface and compile
javac -classpath ./classes:$OO_SDK_URE_HOME/share/java/juh.jar:$OO_SDK_URE_HOME/share/java/jurt.jar:$OO_SDK_URE_HOME/share/java/ridl.jar:$OO_SDK_URE_HOME/share/java/unoloader.jar -d ./classes /home/jialiang/workspace_uno_test/uno_test/src/org/openoffice/test/comp/HelloWorldImpl.java
6. deploy
jar cfm HelloWorldImpl.jar HelloWorldImpl.mf -C ./classes .
regcomp -register -r thumbs.rdb -br $OO_SDK_URE_HOME/share/misc/services.rdb -br $OO_SDK_URE_HOME/share/misc/types.rdb -br thumbs.rdb -l com.sun.star.loader.Java2 -c file:///$OO_SDK_HOME/../program/classes/HelloWorldImpl.jar
7. install to OO, and test it
cd $OO_SDK_HOME/../program
su root
vi fundamentalbasisrc
append your jar file to URE_MORE_JAVA_TYPES path
append your rdb file to URE_MORE_SERVICES and URE_MORE_TYPES path
Sub Main oTestComp = createUnoService("org.openoffice.test.HelloWorld") MsgBox oTestComp.dbg_methods MsgBox oTestComp.dbg_properties print oTestComp.getHelloWorld() oTestComp.DestinationDirectory = "test" print oTestComp.DestinationDirectory end sub
XHelloWorld.idl:
#ifndef _org_openoffice_test_XImageShrink_idl_ #define _org_openoffice_test_XImageShrink_idl_ #include <com/sun/star/uno/XInterface.idl> #include <com/sun/star/awt/Size.idl> module org { module openoffice { module test { interface XHelloWorld { [attribute] string SourceDirectory; [attribute] string DestinationDirectory; string getHelloWorld(); void printHelloWorld(); }; }; }; }; #endif
HelloWorld.idl:
#ifndef __org_openoffice_test_hellworld_idl__ #define __org_openoffice_test_hellworld_idl__ #include <XHelloWorld.idl> module org { module openoffice { module test { service HelloWorld : org::openoffice::test::XHelloWorld { }; }; }; }; #endif
HelloWorldImpl.java:
package org.openoffice.test.comp; import org.openoffice.test.XHelloWorld; import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.registry.XRegistryKey; import com.sun.star.comp.loader.FactoryHelper; import com.sun.star.lib.uno.helper.WeakBase; public class HelloWorldImpl extends WeakBase implements com.sun.star.lang.XServiceInfo, org.openoffice.test.XHelloWorld { com.sun.star.uno.XComponentContext xComponentContext = null; // maintain a static implementation id for all instances of HelloWorld // initialized by the first call to getImplementationId() static byte[] _implementationId; // hold the service name in a private static member variable of the class protected static final String __serviceName = "org.openoffice.test.HelloWorld"; String destDir = ""; String sourceDir = ""; /** Creates a new instance of HelloWorld */ public HelloWorldImpl() { } // static __getServiceFactory() Implementation public static XSingleServiceFactory __getServiceFactory(String implName, XMultiServiceFactory multiFactory, com.sun.star.registry.XRegistryKey regKey) { com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals(HelloWorldImpl.class.getName())) xSingleServiceFactory = FactoryHelper.getServiceFactory( HelloWorldImpl.class, HelloWorldImpl.__serviceName, multiFactory, regKey); return xSingleServiceFactory; } public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { // System.out.println(HelloWorldImpl.class.getName()); return FactoryHelper.writeRegistryServiceInfo( HelloWorldImpl.class.getName(), __serviceName, regKey); } @Override public String getSourceDirectory() { return sourceDir; } @Override public void setDestinationDirectory(String str) { destDir = str; } @Override public void setSourceDirectory(String str) { sourceDir = str; } // XServiceInfo implementation @Override public String getImplementationName() { return getClass().getName(); } @Override public boolean supportsService(String serviceName) { if (serviceName.equals(__serviceName)) return true; return false; } @Override public String[] getSupportedServiceNames() { return new String[] { __serviceName }; } @Override public String getHelloWorld() { return "Hello World"; } @Override public void printHelloWorld() { System.out.println("Hello World"); } @Override public String getDestinationDirectory() { return destDir; } }
HelloWorldImpl.mf:
Manifest-Version: 1.0 RegistrationClassName: org.openoffice.test..comp.HelloWorldImpl
注意:我的OO版本是3.1,不同的版本可能不一样。
相关文章推荐
- Java对象创建(含静态属性)内存分配流程解析
- nova组件、架构、代码目录以及创建虚拟机流程
- Android 四大组件 之 content provider 创建流程
- JAVA创建文件||文件夹标准流程
- JavaIO流程--创建文件和目录的实例
- openstack创建虚拟机流程,从界面任务发起,到nova等组件处理,到虚机创建完成
- 【Java基础】Java类的加载和对象创建流程的详细分析
- Windows操作系统下安装IIS、组件及IIS创建网站流程
- 利用java的开源组件JExcel创建无差异的Excel文件,并且导入到.net项目中去.
- 关于java存储和对象创建的流程
- Java类的加载和对象创建流程的详细分析
- 创建控制器组件:HelloAction.java
- 简化 Ajax 和 Java 开发之第 4 部分:用 JSP 标记文件创建 JSF 样式的组件
- 【简记】Java Web 内幕——Spring源码(组件分析,BeanFactory源码,Bean创建之前)
- java存储以及java对象创建的流程(详解)
- 简化 Ajax 和 Java 开发,第 4 部分: 使用 JSP 标记文件创建 JSF 样式的组件
- OpenStack中nova组件创建虚拟机的源码流程
- Java JNI调用dll中的C代码的流程
- java基础学习(三)控制执行流程
- HOW2J——JAVA基础——控制流程综合练习