Create Instance with Arguments

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

Jump to: navigation, search



If the service should be raised passing arguments through com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext() and com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments(), it has to implement the interface com.sun.star.lang.XInitialization. The second service my_module.MyService2 implements it, expecting a single string as an argument.

 // XInitialization implementation
 void MyService2Impl::initialize( Sequence< Any > const & args )
     throw (Exception)
 {
     if (1 != args.getLength())
     {
         throw lang::IllegalArgumentException(
             OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instanciating this component!") ),
             (::cppu::OWeakObject *)this, // resolve to XInterface reference
             0 ); // argument pos
     }
     if (! (args[ 0 ] >>= m_arg))
     {
         throw lang::IllegalArgumentException(
             OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ),
             (::cppu::OWeakObject *)this, // resolve to XInterface reference
             0 ); // argument pos
     }
 }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools