使用参数创建实例
From Apache OpenOffice Wiki
< Zh | Documentation
如果通过 com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext() 和 com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments() 传送参数来提出服务,则服务必须实现 com.sun.star.lang.XInitialization 接口。第二个服务 my_module.MyService2 将实现它,并将单个字符串作为参数。
// 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). |