XServiceInfo

From Apache OpenOffice Wiki
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


每个服务实现都应该导出 com.sun.star.lang.XServiceInfo 接口。XServiceInfo 必须手动实现,因为只有程序员才知道实现支持的服务。下面有关 Java 和 C++ 组件的各节介绍了 XServiceInfo 实现的示例。


XServiceInfo 的 IDL 规范如下所示:

  // module com::sun::star::lang
  interface XServiceInfo: com::sun::star::uno::XInterface
  { 
      string getImplementationName(); 
      boolean supportsService( [in] string ServiceName ); 
      sequence<string> getSupportedServiceNames(); 
  };


实现名称

方法 getImplementationName() 提供了对服务实现的实现名称的访问。实现名称可以唯一标识 UNO 对象中的服务规范的一个实现。名称可以由实现自由选择,因为名称不显示在 IDL 中。但是,实现应该遵循以下命名约定:

公司前缀 点 "comp" 点 模块名称 点 在模块中唯一的对象名称 实现的服务
com.sun.star . comp . forms . ODataBaseForm com.sun.star.forms.DataBaseForm
org.openoffice . comp . test . OThumbs org.openoffice.test.ImageShrink

org.openoffice.test.ThumbnailInsert ...


如果对象实现一个服务,则它可以使用服务名称导出实现名称。多个服务的实现应该使用可以描述整个对象的名称。


如果使用实现名称在服务管理器调用 createInstance(),则将接收到该实现的一个具体实例。实现名称相当于 Java 中的类名称。Java 组件只是在 getImplementationName() 中返回全限定类名称。


Tip.png 按规范编程而不是按实现编程是一种很好的操作实践,否则,您的应用程序可能会在以后的版本中出现问题。OpenOffice.org API 实现是不兼容的,只有规范是兼容的。


支持的服务名称

方法 getSupportedServiceNames() 和 supportsService() 用于处理已实现对象中服务的可用性。请注意,支持的服务是在支持这些服务的一个类中实现的服务,而不是组件文件包含的所有实现的服务。在插图 实现三个 UNO 对象的组件中,XServiceInfo 由组件中已实现的对象导出,而不是由组件导出。这表示 srv3_4 必须支持 XServiceInfo 并返回 "Service3" 和 "Service4" 作为支持的服务名称。


服务名称可以标识服务,因为它已在 IDL 中指定。如果使用服务名称在服务管理器实例化对象,则将返回编译到服务规范的对象。


Documentation note.png 由组件返回的用于通过其接口 com.sun.star.lang.XSingleComponentFactory 或 com.sun.star.lang.XSingleServiceFactory 来创建实现的实例的单服务工厂必须支持 XServiceInfo。单个工厂支持此接口以允许 UNO 在实例化之前实现检查实现的功能。您可以通过服务管理器的 com.sun.star.container.XContentEnumerationAccess 接口利用此功能。
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages