从 UNOIDL 定义生成源代码
From Apache OpenOffice Wiki
< Zh | Documentation
.idl 文件中提供的类型说明文件将在随后的过程中使用,以创建用于服务管理器的类型信息,并生成头文件和类文件。处理 UNOIDL 定义包括三个步骤。
- 使用 idlc 编译 .idl 文件。结果是包含二进制类型说明的 .urd 文件(UNO 反射数据)。
- 使用 regmerge 将 .urd 文件合并到注册表数据库。注册表数据库文件的扩展名是 .rdb(注册表数据库)。它们树状结构中包含二进制数据描述类型,树状结构的根以
/
表示。类型说明的默认关键字是 /UCR 关键字(UNO 核心反射)。 - 使用 javamaker 或 cppumaker 从注册表文件生成源代码。工具 javamaker 和 cppumaker 将 UNOIDL 类型映射到 Java 和 C++,如 专业 UNO - UNO 语言绑定 所述。这些工具使用的注册表必须包含要映射到所用编程语言的所有类型,包括类型说明中引用的所有类型。因此,除需要完整的办公软件注册表外,javamaker 和 cppumaker 还需要合并后的注册表。OpenOffice.org 附带了完整的注册表数据库,该数据库可以提供 UNO 在运行时使用的所有类型。SDK 使用现有已安装的 OpenOffice.org 的数据库(类型库)。
以下显示了在 Linux 下的一个简单设定中,从 .idl 文件创建 Java 类文件和 C++ 头文件所必需的命令。我们假设 <OFFICE_PROGRAM_PATH>/classes 中的 JAR 已添加到 CLASSPATH,SDK 安装在 /home/sdk 中,而 /home/sdk/linux/bin 位于 PATH 环境变量中,因此 UNO 工具可以直接运行。项目文件夹是 /home/sdk/Thumbs,其中包含了上述 .idl 文件 XImageShrink.idl
。
# make project folder the current directory
cd /home/sdk/Thumbs
# compile XImageShrink.idl using idlc
# usage: idlc [-options] file_1.idl ... file_n.idl
# -C adds complete type information including services
# -I includepath tells idlc where to look for include files
#
# idlc writes the resulting urds to the current folder by default
idlc -C -I../idl XImageShrink.idl
# create registry database (.rdb) file from UNO registry data (.urd) using regmerge
# usage: regmerge mergefile.rdb mergeKey regfile_1.urd ... regfile_n.urd
# mergeKey entry in the tree-like rdb structure where types from .urd should be recorded, the tree
# starts with the root / and UCR is the default key for type descriptions
#
# regmerge writes the rdb to the current folder by default
regmerge thumbs.rdb /UCR XImageShrink.urd
# generate Java class files for new types from rdb
# -B base node to look for types, in this case UCR
# -T type to generate Java files for
# -nD do not generate sources for dependent types, they are available in the Java UNO jar files
#
# javamaker creates a directory tree for the output files according to
# the modules the given types were placed in. The tree is created in the current folder by default
javamaker -BUCR -Torg.openoffice.test.XImageShrink -nD <OFFICE_PROGRAM_PATH>/types.rdb thumbs.rdb
# generate C++ header files (hpp and hdl) for new types and their dependencies from rdb
# -B base node to look for types, in this case UCR
# -T type to generate C++ header files for
#
# cppumaker creates a directory tree for the output files according to
# the modules the given types were placed in. The tree is created in the current folder by default
cppumaker -BUCR -Torg.openoffice.test.XImageShrink <OFFICE_PROGRAM_PATH>/types.rdb thumbs.rdb
使用这些命令之后,您将得到一个注册表数据库 thumbs.rdb 和一个 Java 类文件 XImageShrink.class
。(在 2.0 之前的 OpenOffice.org 版本中,javamaker 生成 Java 源文件而不是类文件;因此必须另外执行一个步骤,调用源文件的 javac
。)您可以对 thumbs.rdb
运行 regview 以查看完成的合并。
regview thumbs.rdb
接口 XImageShrink
的结果代码如下所示:
Registry "file:///home/sdk/Thumbs/thumbs.rdb": / / UCR / org / openoffice / test / XImageShrink Value: Type = RG_VALUETYPE_BINARY Size = 316 Data = minor version: 0 major version: 1 type: 'interface' uik: { 0x00000000-0x0000-0x0000-0x00000000-0x00000000 } name: 'org/openoffice/test/XImageShrink' super name: 'com/sun/star/uno/XInterface' Doku: "" IDL source file: "/home/sdk/Thumbs/XImageShrink.idl" number of fields: 3 field #0: name='SourceDirectory' type='string' access=READWRITE Doku: "" IDL source file: "" field #1: name='DestinationDirectory' type='string' access=READWRITE Doku: "" IDL source file: "" field #2: name='Dimension' type='com/sun/star/awt/Size' access=READWRITE Doku: "" IDL source file: "" number of methods: 0 number of references: 0
源文件的生成可以完全由 makefile 自动完成。如果需要更多信息,请参阅下面 编写 UNO 组件 - Java 中的简单组件 - 运行和调试 Java 组件 和 编写 UNO 组件 - C++ 组件。现在您已准备好在 UNO 组件中实现自己的类型和接口了。下一节讨论可在 UNO 组件中实现的 UNO 核心接口。
Content on this page is licensed under the Public Documentation License (PDL). |