Mapping of Services

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:03, 15 February 2008 by Ccornell (Talk | contribs)

Jump to: navigation, search



A new-style service is mapped to a C++ class with the same name. The class has one or more public static member functions that correspond to the explicit or implicit constructors of the service.

For a new-style service with a given interface type XIfc, an explicit constructor of the form

 name([in] Type1 arg1, [in] Type2 arg2) raises (Exception1, ..., ExceptionN);

is represented by the C++ member function

 public:
 static com::sun::star::uno::Reference< XIfc > name(
     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context,
     Type1 arg1, Type2 arg2) 
     throw (Exception1, ..., ExceptionN, com::sun::star::uno::RuntimeException) { ... }

If a service constructor has a rest parameter (any...), it is mapped to a parameter of type com::sun::star::uno::Sequence< com::sun::star::uno::Any > const & in C++.

If a new-style service has an implicit constructor, the corresponding C++ member function is of the form

 public:
 static com::sun::star::uno::Reference< XIfc > create(
     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context) 
     throw (com::sun::star::uno::RuntimeException) { ... }

The semantics of both explicit and implicit service constructors in C++ are as follows. They are the same as for Java:

  • The first argument to a service constructor is always a com.sun.star.uno.XComponentContext, which must be a non-null reference. Any further arguments are used to initialize the created service (see below).
  • The service constructor first uses com.sun.star.uno.XComponentContext:getServiceManager to obtain a service manager (a com.sun.star.lang.XMultiComponentFactory) from the given component context.
  • The service constructor then uses com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext to create a service instance, passing it the list of arguments without the initial XComponentContext. If the service constructor has a single rest parameter, its sequence of any values is used directly, otherwise the given arguments are made into a sequence of any values. In the case of an implicit service constructor, no arguments are passed, and com.sun.star.lang.XMultiComponentFactory:createInstanceWithContext is used instead.
  • If any of the above steps fails with an exception that the service constructor may throw (according to its exception specification), the service constructor also fails by throwing that exception. Otherwise, if any of the above steps fails with an exception that the service constructor may not throw, the service constructor instead fails by throwing a com.sun.star.uno.DeploymentException. Finally, if no service instance could be created (because either the given component context has no service manager, or the service manager does not support the requested service), the service constructor fails by throwing a com.sun.star.uno.DeploymentException. The net effect is that a service constructor either returns a non-null instance of the requested service, or throws an exception; a service constructor will never return a null instance.

Old-style services are not mapped into the C++ language binding.

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