Kaydet (Commit) 7b7e9109 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS sdksample (1.3.124); FILE MERGED

2004/08/03 15:33:01 dbo 1.3.124.2: revised sample code
Issue number:
Submitted by:
Reviewed by:
2004/06/30 09:10:25 jsc 1.3.124.1: #i29308# use of new UNO features
üst 93fcb2c0
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: service2_impl.cxx,v $ * $RCSfile: service2_impl.cxx,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: hr $ $Date: 2003-06-30 15:13:19 $ * last change: $Author: rt $ $Date: 2005-01-31 16:13:51 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* the BSD license. * the BSD license.
...@@ -59,54 +59,39 @@ namespace my_sc_impl ...@@ -59,54 +59,39 @@ namespace my_sc_impl
extern Sequence< OUString > SAL_CALL getSupportedServiceNames_MyService1Impl(); extern Sequence< OUString > SAL_CALL getSupportedServiceNames_MyService1Impl();
extern OUString SAL_CALL getImplementationName_MyService1Impl(); extern OUString SAL_CALL getImplementationName_MyService1Impl();
extern Reference< XInterface > SAL_CALL create_MyService1Impl( extern Reference< XInterface > SAL_CALL create_MyService1Impl(
Reference< XComponentContext > const & xContext ) Reference< XComponentContext > const & xContext )
SAL_THROW( () ); SAL_THROW( () );
static Sequence< OUString > getSupportedServiceNames_MyService2Impl() static Sequence< OUString > getSupportedServiceNames_MyService2Impl()
{ {
static Sequence < OUString > *pNames = 0; Sequence<OUString> names(1);
if( ! pNames ) names[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("my_module.MyService2"));
{ return names;
// MutexGuard guard( Mutex::getGlobalMutex() );
if( !pNames )
{
static Sequence< OUString > seqNames(1);
seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("my_module.MyService2"));
pNames = &seqNames;
}
}
return *pNames;
} }
static OUString getImplementationName_MyService2Impl() static OUString getImplementationName_MyService2Impl()
{ {
static OUString *pImplName = 0; return OUString( RTL_CONSTASCII_USTRINGPARAM(
if( ! pImplName ) "my_module.my_sc_implementation.MyService2") );
{
// MutexGuard guard( Mutex::getGlobalMutex() );
if( ! pImplName )
{
static OUString implName( RTL_CONSTASCII_USTRINGPARAM("my_module.my_sc_implementation.MyService2") );
pImplName = &implName;
}
}
return *pImplName;
} }
class MyService2Impl : public ::cppu::WeakImplHelper3< class MyService2Impl : public ::cppu::WeakImplHelper3<
::my_module::XSomething, lang::XServiceInfo, lang::XInitialization > ::my_module::XSomething, lang::XServiceInfo, lang::XInitialization >
{ {
OUString m_arg; OUString m_sData;
public: public:
// focus on three given interfaces, // focus on three given interfaces,
// no need to implement XInterface, XTypeProvider, XWeak // no need to implement XInterface, XTypeProvider, XWeak
// XInitialization will be called upon createInstanceWithArguments[AndContext]() // XInitialization will be called upon
// createInstanceWithArguments[AndContext]()
virtual void SAL_CALL initialize( Sequence< Any > const & args ) virtual void SAL_CALL initialize( Sequence< Any > const & args )
throw (Exception); throw (Exception);
// XSomething // XSomething
virtual OUString SAL_CALL methodOne( OUString const & str ) virtual OUString SAL_CALL methodOne( OUString const & str )
throw (RuntimeException); throw (RuntimeException);
virtual OUString SAL_CALL methodTwo( )
throw (RuntimeException);
// XServiceInfo // XServiceInfo
virtual OUString SAL_CALL getImplementationName() virtual OUString SAL_CALL getImplementationName()
throw (RuntimeException); throw (RuntimeException);
...@@ -115,45 +100,64 @@ public: ...@@ -115,45 +100,64 @@ public:
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
throw (RuntimeException); throw (RuntimeException);
}; };
// XInitialization implemention // XInitialization implemention
void MyService2Impl::initialize( Sequence< Any > const & args ) void MyService2Impl::initialize( Sequence< Any > const & args )
throw (Exception) throw (Exception)
{ {
if (1 != args.getLength()) if (args.getLength() != 1)
{ {
throw lang::IllegalArgumentException( throw lang::IllegalArgumentException(
OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instanciating this component!") ), OUString( RTL_CONSTASCII_USTRINGPARAM(
(::cppu::OWeakObject *)this, // resolve to XInterface reference "give a string instanciating this component!") ),
// resolve to XInterface reference:
static_cast< ::cppu::OWeakObject * >(this),
0 ); // argument pos 0 ); // argument pos
} }
if (! (args[ 0 ] >>= m_arg)) if (! (args[ 0 ] >>= m_sData))
{ {
throw lang::IllegalArgumentException( throw lang::IllegalArgumentException(
OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ), OUString( RTL_CONSTASCII_USTRINGPARAM(
(::cppu::OWeakObject *)this, // resolve to XInterface reference "no string given as argument!") ),
// resolve to XInterface reference:
static_cast< ::cppu::OWeakObject * >(this),
0 ); // argument pos 0 ); // argument pos
} }
} }
// XSomething implementation // XSomething implementation
OUString MyService2Impl::methodOne( OUString const & str ) OUString MyService2Impl::methodOne( OUString const & str )
throw (RuntimeException) throw (RuntimeException)
{ {
m_sData = str;
return OUString( RTL_CONSTASCII_USTRINGPARAM( return OUString( RTL_CONSTASCII_USTRINGPARAM(
"called methodOne() of MyService2 implementation: ") ) + m_arg + str; "called methodOne() of MyService2 implementation: ") ) + m_sData;
} }
OUString MyService2Impl::methodTwo( )
throw (RuntimeException)
{
return OUString( RTL_CONSTASCII_USTRINGPARAM(
"called methodTwo() of MyService2 implementation: ") ) + m_sData;
}
// XServiceInfo implementation // XServiceInfo implementation
OUString MyService2Impl::getImplementationName() OUString MyService2Impl::getImplementationName()
throw (RuntimeException) throw (RuntimeException)
{ {
// unique implementation name // unique implementation name
return OUString( RTL_CONSTASCII_USTRINGPARAM("my_module.my_sc_impl.MyService2") ); return OUString( RTL_CONSTASCII_USTRINGPARAM(
"my_module.my_sc_impl.MyService2") );
} }
sal_Bool MyService2Impl::supportsService( OUString const & serviceName ) sal_Bool MyService2Impl::supportsService( OUString const & serviceName )
throw (RuntimeException) throw (RuntimeException)
{ {
// this object only supports one service, so the test is simple // this object only supports one service, so the test is simple
return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("my_module.MyService2") ); return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
"my_module.MyService2") );
} }
Sequence< OUString > MyService2Impl::getSupportedServiceNames() Sequence< OUString > MyService2Impl::getSupportedServiceNames()
throw (RuntimeException) throw (RuntimeException)
{ {
...@@ -164,7 +168,7 @@ Reference< XInterface > SAL_CALL create_MyService2Impl( ...@@ -164,7 +168,7 @@ Reference< XInterface > SAL_CALL create_MyService2Impl(
Reference< XComponentContext > const & xContext ) Reference< XComponentContext > const & xContext )
SAL_THROW( () ) SAL_THROW( () )
{ {
return static_cast< lang::XTypeProvider * >( new MyService2Impl() ); return static_cast< ::cppu::OWeakObject * >( new MyService2Impl );
} }
} }
...@@ -176,12 +180,14 @@ static struct ::cppu::ImplementationEntry s_component_entries [] = ...@@ -176,12 +180,14 @@ static struct ::cppu::ImplementationEntry s_component_entries [] =
{ {
{ {
create_MyService1Impl, getImplementationName_MyService1Impl, create_MyService1Impl, getImplementationName_MyService1Impl,
getSupportedServiceNames_MyService1Impl, ::cppu::createSingleComponentFactory, getSupportedServiceNames_MyService1Impl,
::cppu::createSingleComponentFactory,
0, 0 0, 0
}, },
{ {
create_MyService2Impl, getImplementationName_MyService2Impl, create_MyService2Impl, getImplementationName_MyService2Impl,
getSupportedServiceNames_MyService2Impl, ::cppu::createSingleComponentFactory, getSupportedServiceNames_MyService2Impl,
::cppu::createSingleComponentFactory,
0, 0 0, 0
}, },
{ 0, 0, 0, 0, 0, 0 } { 0, 0, 0, 0, 0, 0 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment