Mapping of Services

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:13, 23 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

  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

  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, which must be a non-null reference. Any further arguments are used to initialize the created service (see below).
  • The service constructor first uses getServiceManager to obtain a service manager (a from the given component context.
  • The service constructor then uses 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 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 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 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
In other languages