Difference between revisions of "Zh/Documentation/DevGuide/ProUNO/Importing a UNO Object"

From Apache OpenOffice Wiki
Jump to: navigation, search
(New page: {{Documentation/DevGuide/ProUNOTOC/Zh |ProUNO2b=block |ProUNO2bUNOIC=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/ProUNO/Starting OpenOffice.org in Listening Mode |NextPag...)
 
m
 
Line 6: Line 6:
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Characteristics of the Interprocess Bridge
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Characteristics of the Interprocess Bridge
 
}}
 
}}
[[en:Documentation/DevGuide/ProUNO/Importing a UNO Object]]
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:导入 UNO 对象}}
 
{{DISPLAYTITLE:导入 UNO 对象}}
  

Latest revision as of 02:02, 14 May 2009



进程间连接的最常用情况是从导出服务器导入对 UNO 对象的引用。例如,本手册中介绍的大多数 Java 示例获取对 OpenOffice.org ComponentContext 的引用。执行此操作的正确方法是使用 com.sun.star.bridge.UnoUrlResolver 服务。其主要接口 com.sun.star.bridge.XUnoUrlResolver 用以下方法定义:

  interface XUnoUrlResolver: com::sun::star::uno::XInterface
  {
      /** resolves an object on the UNO URL */
      com::sun::star::uno::XInterface resolve( [in] string sUnoUrl )  
          raises (com::sun::star::connection::NoConnectException,  
                  com::sun::star::connection::ConnectionSetupException,  
                  com::sun::star::lang::IllegalArgumentException); 
  };


传送到 resolve() 方法的字符串称为 UNO URL 。它必须具有以下格式:


UNO URL 模式


下面是一个示例 URL:uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager 。此 URL 的各个部分是:

  1. URL 模式 uno:。它将 URL 标识为 UNO URL,并将它与其他 URL(例如,http:ftp: URL)区分开来。
  2. 一个表示用于访问其他进程连接类型的字符串。在此字符串后面可以直接跟一个逗号分隔的名称值对列表,其中,名称和值用一个 '=' 分隔。专业 UNO - UNO 概念 - UNO 进程间连接 - 打开连接 中介绍了目前支持的连接类型。连接类型指定传送字节流时使用的传输机制,例如,TCP/IP 套接字或命名管道。
  3. 一个表示用于通过建立的字节流连接进行通信的协议类型的字符串。此字符串后面可以跟一个逗号分隔的名称值对列表,用于根据具体需要自定义协议。建议使用的协议为 urp(UNO 远程协议)。下面解释了一些有用的参数。有关完整的规范信息,请参阅 udk.openoffice.org 上名为 UNO-URL 的文档。
  4. 进程必须按照明确名称明确地导出具体对象。不能访问任意的 UNO 对象(但在 CORBA 中,则可通过 IOR 执行此操作)。

以下示例说明如何使用 UnoUrlResolver 导入对象:

  XComponentContext xLocalContext =
      com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
 
  // initial serviceManager
  XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
 
  // create a URL resolver
  Object urlResolver = xLocalServiceManager.createInstanceWithContext(
      "com.sun.star.bridge.UnoUrlResolver", xLocalContext);
 
  // query for the XUnoUrlResolver interface
  XUnoUrlResolver xUrlResolver =
      (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);
 
  // Import the object
  Object rInitialObject = xUrlResolver.resolve( 
      "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager");
 
  // XComponentContext
  if (null != rInitialObject) {
      System.out.println("initial object successfully retrieved");
  } else {
      System.out.println("given initial-object name unknown at server side");
  }


使用 UnoUrlResolver 时有一些限制。您不能:

  • 在桥由于任何原因终止时得到通知
  • 关闭底层进程间连接
  • 将一个本地对象作为初始对象提供给远程进程


这些问题可通过底层 API 得到解决,这将在下面的 专业 UNO - UNO 概念 - UNO 进程间连接 - 打开连接 中进行说明。

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages