1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: forms_module.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef FORMS_MODULE_INCLUDE_CONTEXT
32 #error "not to be included directly! use 'foo_module.hxx instead'!"
35 #ifndef FORMS_MODULE_NAMESPACE
36 #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!"
39 #include <osl/mutex.hxx>
40 #include <tools/resid.hxx>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/registry/XRegistryKey.hpp>
45 #include <cppuhelper/factory.hxx>
46 #include <rtl/string.hxx>
48 //.........................................................................
49 namespace FORMS_MODULE_NAMESPACE
51 //.........................................................................
53 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
> (SAL_CALL
*FactoryInstantiation
)
55 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rServiceManager
,
56 const ::rtl::OUString
& _rComponentName
,
57 ::cppu::ComponentInstantiation _pCreateFunction
,
58 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
> & _rServiceNames
,
59 rtl_ModuleCount
* _pModuleCounter
62 //=========================================================================
64 //=========================================================================
69 // not implemented. OFormsModule is a static class
72 // auto registration administration
73 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
>*
74 s_pImplementationNames
;
75 static ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::rtl::OUString
> >*
77 static ::com::sun::star::uno::Sequence
< sal_Int64
>*
78 s_pCreationFunctionPointers
;
79 static ::com::sun::star::uno::Sequence
< sal_Int64
>*
80 s_pFactoryFunctionPointers
;
83 /** register a component implementing a service with the given data.
84 @param _rImplementationName
85 the implementation name of the component
87 the services the component supports
88 @param _pCreateFunction
89 a function for creating an instance of the component
90 @param _pFactoryFunction
91 a function for creating a factory for that component
94 static void registerComponent(
95 const ::rtl::OUString
& _rImplementationName
,
96 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& _rServiceNames
,
97 ::cppu::ComponentInstantiation _pCreateFunction
,
98 FactoryInstantiation _pFactoryFunction
);
100 /** revoke the registration for the specified component
101 @param _rImplementationName
102 the implementation name of the component
104 static void revokeComponent(
105 const ::rtl::OUString
& _rImplementationName
);
107 /** write the registration information of all known components
108 <p>writes the registration information of all components which are currently registered into the
109 specified registry.<p/>
110 <p>Usually used from within component_writeInfo.<p/>
111 @param _rxServiceManager
114 the registry key under which the information will be stored
116 sal_True if the registration of all implementations was successfull, sal_False otherwise
118 static sal_Bool
writeComponentInfos(
119 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxServiceManager
,
120 const ::com::sun::star::uno::Reference
< ::com::sun::star::registry::XRegistryKey
>& _rRootKey
);
122 /** creates a Factory for the component with the given implementation name.
123 <p>Usually used from within component_getFactory.<p/>
124 @param _rxServiceManager
125 a pointer to an XMultiServiceFactory interface as got in component_getFactory
126 @param _pImplementationName
127 the implementation name of the component
129 the XInterface access to a factory for the component
131 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getComponentFactory(
132 const ::rtl::OUString
& _rImplementationName
,
133 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxServiceManager
137 /** ensure that the impl class exists
138 @precond m_aMutex is guarded when this method gets called
140 static void ensureImpl();
143 //==========================================================================
144 //= OMultiInstanceAutoRegistration
145 //==========================================================================
146 template <class TYPE
>
147 class OMultiInstanceAutoRegistration
150 /** automatically registeres a multi instance component
151 <p>Assumed that the template argument has the three methods
153 <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/>
154 <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/>
155 <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
156 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code>
159 the instantiation of this object will automatically register the class via <method>OFormsModule::registerComponent</method>.
161 <p>The factory creation function used is <code>::cppu::createSingleFactory</code>.</p>
163 @see OOneInstanceAutoRegistration
165 OMultiInstanceAutoRegistration();
166 ~OMultiInstanceAutoRegistration();
169 template <class TYPE
>
170 OMultiInstanceAutoRegistration
<TYPE
>::OMultiInstanceAutoRegistration()
172 OFormsModule::registerComponent(
173 TYPE::getImplementationName_Static(),
174 TYPE::getSupportedServiceNames_Static(),
176 ::cppu::createSingleFactory
180 template <class TYPE
>
181 OMultiInstanceAutoRegistration
<TYPE
>::~OMultiInstanceAutoRegistration()
183 OFormsModule::revokeComponent(TYPE::getImplementationName_Static());
186 //==========================================================================
187 //= OOneInstanceAutoRegistration
188 //==========================================================================
189 template <class TYPE
>
190 class OOneInstanceAutoRegistration
193 /** automatically registeres a single instance component
194 <p>Assumed that the template argument has the three methods
196 <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/>
197 <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/>
198 <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
199 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code>
202 the instantiation of this object will automatically register the class via <method>OFormsModule::registerComponent</method>.
204 The factory creation function used is <code>::cppu::createOneInstanceFactory</code>.
205 @see OOneInstanceAutoRegistration
207 OOneInstanceAutoRegistration();
208 ~OOneInstanceAutoRegistration();
211 template <class TYPE
>
212 OOneInstanceAutoRegistration
<TYPE
>::OOneInstanceAutoRegistration()
214 OFormsModule::registerComponent(
215 TYPE::getImplementationName_Static(),
216 TYPE::getSupportedServiceNames_Static(),
218 ::cppu::createOneInstanceFactory
222 template <class TYPE
>
223 OOneInstanceAutoRegistration
<TYPE
>::~OOneInstanceAutoRegistration()
225 OFormsModule::revokeComponent(TYPE::getImplementationName_Static());
228 //==========================================================================
229 //= helper for classes implementing the service handling via
230 //= OMultiInstanceAutoRegistration or OOneInstanceAutoRegistration
231 //==========================================================================
232 #define DECLARE_SERVICE_REGISTRATION( classname ) \
233 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
234 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); \
236 static ::rtl::OUString SAL_CALL getImplementationName_Static(); \
237 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static(); \
238 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); \
240 friend class OOneInstanceAutoRegistration< classname >; \
241 friend class OMultiInstanceAutoRegistration< classname >; \
243 #define IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \
245 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw ( RuntimeException ) \
246 { return getImplementationName_Static(); } \
248 Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw (RuntimeException) \
250 return ::comphelper::concatSequences( \
251 getAggregateServiceNames(), \
252 getSupportedServiceNames_Static() \
256 ::rtl::OUString SAL_CALL classname::getImplementationName_Static() \
257 { return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.forms."#classname ) ); } \
259 Reference< XInterface > SAL_CALL classname::Create( const Reference< XMultiServiceFactory >& _rxFactory ) \
260 { return static_cast< XServiceInfo* >( new classname( _rxFactory ) ); } \
263 #define IMPLEMENT_SERVICE_REGISTRATION_1( classname, baseclass, service1 ) \
264 IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \
266 Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \
268 Sequence< ::rtl::OUString > aOwnNames( 1 ); \
269 aOwnNames[ 0 ] = service1; \
271 return ::comphelper::concatSequences( \
272 baseclass::getSupportedServiceNames_Static(), \
277 #define IMPLEMENT_SERVICE_REGISTRATION_2( classname, baseclass, service1, service2 ) \
278 IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \
280 Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \
282 Sequence< ::rtl::OUString > aOwnNames( 2 ); \
283 aOwnNames[ 0 ] = service1; \
284 aOwnNames[ 1 ] = service2; \
286 return ::comphelper::concatSequences( \
287 baseclass::getSupportedServiceNames_Static(), \
292 #define IMPLEMENT_SERVICE_REGISTRATION_7( classname, baseclass, service1, service2, service3, service4 , service5, service6, service7 ) \
293 IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \
295 Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \
297 Sequence< ::rtl::OUString > aOwnNames( 7 ); \
298 aOwnNames[ 0 ] = service1; \
299 aOwnNames[ 1 ] = service2; \
300 aOwnNames[ 2 ] = service3; \
301 aOwnNames[ 3 ] = service4; \
302 aOwnNames[ 4 ] = service5; \
303 aOwnNames[ 5 ] = service6; \
304 aOwnNames[ 6 ] = service7; \
306 return ::comphelper::concatSequences( \
307 baseclass::getSupportedServiceNames_Static(), \
312 #define IMPLEMENT_SERVICE_REGISTRATION_8( classname, baseclass, service1, service2, service3, service4 , service5, service6, service7, service8 ) \
313 IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \
315 Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \
317 Sequence< ::rtl::OUString > aOwnNames( 8 ); \
318 aOwnNames[ 0 ] = service1; \
319 aOwnNames[ 1 ] = service2; \
320 aOwnNames[ 2 ] = service3; \
321 aOwnNames[ 3 ] = service4; \
322 aOwnNames[ 4 ] = service5; \
323 aOwnNames[ 5 ] = service6; \
324 aOwnNames[ 6 ] = service7; \
325 aOwnNames[ 6 ] = service8; \
327 return ::comphelper::concatSequences( \
328 baseclass::getSupportedServiceNames_Static(), \
333 //.........................................................................
334 } // namespace FORMS_MODULE_NAMESPACE
335 //.........................................................................