XServiceInfo

From Apache OpenOffice Wiki
Jump to: navigation, search



Every service implementation should export the com.sun.star.lang.XServiceInfo interface. XServiceInfo must be implemented manually, because only the programmer knows what services the implementation supports. The sections about Java and C++ components below show examples for XServiceInfo implementations.

This is how the IDL specification for XServiceInfo looks like:

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

Implementation Name

The method getImplementationName() provides access to the implementation name of a service implementation. The implementation name uniquely identifies one implementation of service specifications in a UNO object. The name can be chosen freely by the implementation alone, because it does not appear in IDL. However, the implementation should adhere to the following naming conventions:

Company prefix dot "comp" dot module name dot unique object name in module implemented service(s)
com.sun.star . comp . forms . ODataBaseForm com.sun.star.forms.DataBaseForm
org.openoffice . comp . test . OThumbs org.openoffice.test.ImageShrink

org.openoffice.test.ThumbnailInsert ...

If an object implements one single service, it can use the service name to derive an implementation name. Implementations of several services should use a name that describes the entire object.

If a createInstance() is called at the service manager using an implementation name, an instance of exactly that implementation is received. An implementation name is equivalent to a class name in Java. A Java component simply returns the fully qualified class name in getImplementationName().

Tip.png It is good practice to program against the specification and not against the implementation, otherwise, your application could break with future versions. Apache OpenOffices API implementation is not supposed to be compatible, only the specification is.


Supported Service Names

The methods getSupportedServiceNames() and supportsService() deal with the availability of services in an implemented object. Note that the supported services are the services implemented in one class that supports these services, not the services of all implementations contained in the component file. In the illustration A Component implementing three UNO objects, XServiceInfo is exported by the implemented objects in a component, not by the component. That means, srv3_4 must support XServiceInfo and return "Service3" and "Service4" as supported service names.

The service name identifies a service as it was specified in IDL. If an object is instantiated at the service manager using the service name, an object that complies to the service specification is returned.

Documentation note.png The single service factories returned by components that are used to create instances of an implementation through their interfaces com.sun.star.lang.XSingleComponentFactory or com.sun.star.lang.XSingleServiceFactory must support XServiceInfo. The single factories support this interface to allow UNO to inspect the capabilities of a certain implementation before instantiating it. You can take advantage of this feature through the com.sun.star.container.XContentEnumerationAccess interface of a service manager.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages