Difference between revisions of "Zh/Documentation/DevGuide/WritingUNO/Write Registration Info Using a Helper Method"
From Apache OpenOffice Wiki
< Zh | Documentation
(New page: {{Documentation/DevGuide/WritingUNOTOC/Zh |WritingUNO2c=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/WritingUNO/Providing a Single Factory Using a Helper Method |NextPage=...) |
|||
Line 20: | Line 20: | ||
− | {{ | + | {{Note|如果要使用 Java UNO 运行时的服务管理器 <tt>com.sun.star.comp.servicemanager.ServiceManager</tt> ('''jurt.jar''') 来实例化服务实现,那么必须创建服务管理器,并以编程方式添加 “org.openoffice.test.ImageShrink” 的工厂,因为 Java 服务管理器不使用注册表。 |
或者,您还可以使用基于注册表的 '''juh.jar''' 中的 <tt>com.sun.star.comp.helper.RegistryServiceFactory</tt>。但其缺点是它通过 Java 桥委托给服务管理器的 C++ 实现。}} | 或者,您还可以使用基于注册表的 '''juh.jar''' 中的 <tt>com.sun.star.comp.helper.RegistryServiceFactory</tt>。但其缺点是它通过 Java 桥委托给服务管理器的 C++ 实现。}} |
Latest revision as of 19:39, 4 July 2018
UNO 组件必须使用服务管理器的注册表数据库注册。在办公软件安装中,这是用于所有预设服务的文件 types.rdb(在 1.1.0 之前为 applicat.rdb)。服务管理器可以使用此数据库查找服务的实现。例如,如果您的组件的实例使用以下调用创建。
Object imageShrink = xRemoteServiceManager.createInstance("org.openoffice.test.ImageShrink");
服务管理器使用给定的服务名称或实现名称,在注册表中查找相应的 jar 文件,并实例化组件。
在注册的过程中,组件将向注册表中写入必要的信息。当客户端调用组件的 __writeRegistryServiceInfo()
方法时,将从外部触发写入信息的过程。
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
调用程序将传送该方法用来写入注册表条目的 com.sun.star.registry.XRegistryKey 接口。同样,FactoryHelper
类提供了实现方法的方式:
... // static __writeRegistryServiceInfo implementation public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { return FactoryHelper.writeRegistryServiceInfo( ImageShrink.class.getName(), __serviceName, regKey); }
writeRegistryServiceInfo 方法接受三个参数:
- 实现名称
- 服务名称
- XRegistryKey
使用工具(如 regcomp)或使用 Java 应用程序 com.sun.star.tools.uno.RegComp
来注册组件。这些工具可以接受包含组件的 jar 文件的路径作为参数。由于 jar 可以包含多个类,实现 __writeRegistryServiceInfo()
方法的类必须通过标明的方式指出。同样,RegistrationClassName
条目将确定正确的类。例如:
RegistrationClassName: org.openoffice.comp.test.ImageShrink
上述条目对于确定提供 __getServiceFactory()
的类的位置也是非常必要的,因此函数 __writeRegistryServiceInfo()
和 __getServiceFactory()
必须在同一类中。
Content on this page is licensed under the Public Documentation License (PDL). |