Difference between revisions of "Documentation/DevGuide/WritingUNO/C++/Create Instance with Arguments"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Writing UNO Components)
m (FINAL VERSION FOR L10N)
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/WritingUNO/C++/Multiple Components in One Dynamic Link Library
 
|NextPage=Documentation/DevGuide/WritingUNO/C++/Multiple Components in One Dynamic Link Library
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/C++/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Create Instance with Arguments}}
 
{{DISPLAYTITLE:Create Instance with Arguments}}
 
If the service should be raised passing arguments through [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XMultiComponentFactory.html#createInstanceWithArgumentsAndContext com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext()] and [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XMultiServiceFactory.html#createInstanceWithArguments com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments()], it has to implement the interface <idl>com.sun.star.lang.XInitialization</idl>. The second service <code>my_module.MyService2</code> implements it, expecting a single string as an argument.  
 
If the service should be raised passing arguments through [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XMultiComponentFactory.html#createInstanceWithArgumentsAndContext com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext()] and [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XMultiServiceFactory.html#createInstanceWithArguments com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments()], it has to implement the interface <idl>com.sun.star.lang.XInitialization</idl>. The second service <code>my_module.MyService2</code> implements it, expecting a single string as an argument.  
Line 31: Line 32:
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Professional UNO]]
+
[[Category:Documentation/Developer's Guide/Writing UNO Components]]

Revision as of 09:44, 13 May 2009



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
In other languages