1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #include <cppuhelper/implbase3.hxx>
37 #include <cppuhelper/factory.hxx>
38 #include <cppuhelper/implementationentry.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <uno/lbnames.h>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/lang/XInitialization.hpp>
44 #include <com/sun/star/lang/IllegalArgumentException.hpp>
45 #include <mymodule/XSomething.hpp>
48 using namespace ::rtl
; // for OUString
49 using namespace ::com::sun::star
; // for odk interfaces
50 using namespace ::com::sun::star::uno
; // for basic types
56 extern Sequence
< OUString
> SAL_CALL
getSupportedServiceNames_MyService1Impl();
57 extern OUString SAL_CALL
getImplementationName_MyService1Impl();
58 extern Reference
< XInterface
> SAL_CALL
create_MyService1Impl(
59 Reference
< XComponentContext
> const & xContext
);
61 static Sequence
< OUString
> getSupportedServiceNames_MyService2Impl()
63 Sequence
<OUString
> names(1);
64 names
[0] = "mymodule.MyService2";
68 static OUString
getImplementationName_MyService2Impl()
70 return OUString("mymodule.my_sc_implementation.MyService2");
73 class MyService2Impl
: public ::cppu::WeakImplHelper3
<
74 ::mymodule::XSomething
, lang::XServiceInfo
, lang::XInitialization
>
77 // it's good practice to store the context for further use when you use
78 // other UNO API's in your implementation
79 Reference
< XComponentContext
> m_xContext
;
81 inline MyService2Impl(Reference
< XComponentContext
> const & xContext
) SAL_NOEXCEPT
82 : m_xContext(xContext
)
85 virtual ~MyService2Impl() {}
87 // focus on three given interfaces,
88 // no need to implement XInterface, XTypeProvider, XWeak
90 // XInitialization will be called upon
91 // createInstanceWithArguments[AndContext]()
92 virtual void SAL_CALL
initialize( Sequence
< Any
> const & args
);
94 virtual OUString SAL_CALL
methodOne( OUString
const & str
);
95 virtual OUString SAL_CALL
methodTwo( );
97 virtual OUString SAL_CALL
getImplementationName();
98 virtual sal_Bool SAL_CALL
supportsService( OUString
const & serviceName
);
99 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames();
102 // XInitialization implementation
103 void MyService2Impl::initialize( Sequence
< Any
> const & args
)
105 if (args
.getLength() != 1)
107 throw lang::IllegalArgumentException(
109 "give a string instantiating this component!"),
110 // resolve to XInterface reference:
111 static_cast< ::cppu::OWeakObject
* >(this),
114 if (! (args
[ 0 ] >>= m_sData
))
116 throw lang::IllegalArgumentException(
118 "no string given as argument!"),
119 // resolve to XInterface reference:
120 static_cast< ::cppu::OWeakObject
* >(this),
125 // XSomething implementation
126 OUString
MyService2Impl::methodOne( OUString
const & str
)
129 return OUString( "called methodOne() of MyService2 implementation: " ) + m_sData
;
132 OUString
MyService2Impl::methodTwo( )
134 return OUString( "called methodTwo() of MyService2 implementation: " ) + m_sData
;
137 // XServiceInfo implementation
138 OUString
MyService2Impl::getImplementationName()
140 // unique implementation name
141 return OUString("mymodule.my_sc_implementation.MyService2");
144 sal_Bool
MyService2Impl::supportsService( OUString
const & serviceName
)
146 return cppu::supportsService(this, serviceName
);
149 Sequence
< OUString
> MyService2Impl::getSupportedServiceNames()
151 return getSupportedServiceNames_MyService2Impl();
154 Reference
< XInterface
> SAL_CALL
create_MyService2Impl(
155 Reference
< XComponentContext
> const & xContext
)
157 return static_cast< ::cppu::OWeakObject
* >( new MyService2Impl( xContext
) );
162 /* shared lib exports implemented without helpers in service_impl1.cxx */
165 static const struct ::cppu::ImplementationEntry s_component_entries
[] =
168 create_MyService1Impl
, getImplementationName_MyService1Impl
,
169 getSupportedServiceNames_MyService1Impl
,
170 ::cppu::createSingleComponentFactory
,
174 create_MyService2Impl
, getImplementationName_MyService2Impl
,
175 getSupportedServiceNames_MyService2Impl
,
176 ::cppu::createSingleComponentFactory
,
186 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(
187 char const * implName
, lang::XMultiServiceFactory
* xMgr
,
188 registry::XRegistryKey
* xRegistry
)
190 return ::cppu::component_getFactoryHelper(
191 implName
, xMgr
, xRegistry
, ::my_sc_impl::s_component_entries
);
194 SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment(
195 char const ** ppEnvTypeName
, uno_Environment
**)
197 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */