Update ooo320-m1
[ooovba.git] / dbaccess / source / ext / adabas / Acomponentmodule.hxx
blobedaaacb5d4281cffab035ae7e8899d9f85b731b0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Acomponentmodule.hxx,v $
10 * $Revision: 1.4 $
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 _EXTENSIONS_COMPONENT_MODULE_HXX_
32 #define _EXTENSIONS_COMPONENT_MODULE_HXX_
34 /** you may find this file helpfull if you implement a component (in it's own library) which can't use
35 the usual infrastructure.<br/>
36 More precise, you find helper classes to ease the use of resources and the registration of services.
37 <p>
38 You need to define a preprocessor variable COMPMOD_NAMESPACE in order to use this file. Set it to a string
39 which should be used as namespace for the classes defined herein.</p>
42 #ifndef _OSL_MUTEX_HXX_
43 #include <osl/mutex.hxx>
44 #endif
45 #ifndef _TOOLS_RESID_HXX
46 #include <tools/resid.hxx>
47 #endif
48 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
52 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
55 #include <com/sun/star/uno/Sequence.hxx>
56 #endif
57 #ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
58 #include <com/sun/star/registry/XRegistryKey.hpp>
59 #endif
60 #ifndef _CPPUHELPER_FACTORY_HXX_
61 #include <cppuhelper/factory.hxx>
62 #endif
63 #ifndef _RTL_STRING_HXX_
64 #include <rtl/string.hxx>
65 #endif
67 class ResMgr;
69 //.........................................................................
70 namespace COMPMOD_NAMESPACE
72 //.........................................................................
74 typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
76 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager,
77 const ::rtl::OUString & _rComponentName,
78 ::cppu::ComponentInstantiation _pCreateFunction,
79 const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames,
80 rtl_ModuleCount* _pModuleCounter
83 //=========================================================================
84 //= OModule
85 //=========================================================================
86 class OModuleImpl;
87 class OModule
89 friend class OModuleResourceClient;
91 private:
92 OModule();
93 // not implemented. OModule is a static class
95 protected:
96 // resource administration
97 static ::osl::Mutex s_aMutex; /// access safety
98 static sal_Int32 s_nClients; /// number of registered clients
99 static OModuleImpl* s_pImpl; /// impl class. lives as long as at least one client for the module is registered
100 static ::rtl::OString s_sResPrefix;
102 // auto registration administration
103 static ::com::sun::star::uno::Sequence< ::rtl::OUString >*
104 s_pImplementationNames;
105 static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >*
106 s_pSupportedServices;
107 static ::com::sun::star::uno::Sequence< sal_Int64 >*
108 s_pCreationFunctionPointers;
109 static ::com::sun::star::uno::Sequence< sal_Int64 >*
110 s_pFactoryFunctionPointers;
112 public:
113 // cna be set as long as no resource has been accessed ...
114 static void setResourceFilePrefix(const ::rtl::OString& _rPrefix);
116 /// get the vcl res manager of the module
117 static ResMgr* getResManager();
119 /** register a component implementing a service with the given data.
120 @param _rImplementationName
121 the implementation name of the component
122 @param _rServiceNames
123 the services the component supports
124 @param _pCreateFunction
125 a function for creating an instance of the component
126 @param _pFactoryFunction
127 a function for creating a factory for that component
128 @see revokeComponent
130 static void registerComponent(
131 const ::rtl::OUString& _rImplementationName,
132 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
133 ::cppu::ComponentInstantiation _pCreateFunction,
134 FactoryInstantiation _pFactoryFunction);
136 /** revoke the registration for the specified component
137 @param _rImplementationName
138 the implementation name of the component
140 static void revokeComponent(
141 const ::rtl::OUString& _rImplementationName);
143 /** write the registration information of all known components
144 <p>writes the registration information of all components which are currently registered into the
145 specified registry.<p/>
146 <p>Usually used from within component_writeInfo.<p/>
147 @param _rxServiceManager
148 the service manager
149 @param _rRootKey
150 the registry key under which the information will be stored
151 @return
152 sal_True if the registration of all implementations was successfull, sal_False otherwise
154 static sal_Bool writeComponentInfos(
155 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager,
156 const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey >& _rRootKey);
158 /** creates a Factory for the component with the given implementation name.
159 <p>Usually used from within component_getFactory.<p/>
160 @param _rxServiceManager
161 a pointer to an XMultiServiceFactory interface as got in component_getFactory
162 @param _pImplementationName
163 the implementation name of the component
164 @return
165 the XInterface access to a factory for the component
167 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
168 const ::rtl::OUString& _rImplementationName,
169 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
172 protected:
173 /// register a client for the module
174 static void registerClient();
175 /// revoke a client for the module
176 static void revokeClient();
178 private:
179 /** ensure that the impl class exists
180 @precond m_aMutex is guarded when this method gets called
182 static void ensureImpl();
185 //=========================================================================
186 //= OModuleResourceClient
187 //=========================================================================
188 /** base class for objects which uses any global module-specific ressources
190 class OModuleResourceClient
192 public:
193 OModuleResourceClient() { OModule::registerClient(); }
194 ~OModuleResourceClient() { OModule::revokeClient(); }
197 //=========================================================================
198 //= ModuleRes
199 //=========================================================================
200 /** specialized ResId, using the ressource manager provided by the global module
202 class ModuleRes : public ::ResId
204 public:
205 ModuleRes(USHORT _nId) : ResId(_nId, *OModule::getResManager()) { }
208 //==========================================================================
209 //= OMultiInstanceAutoRegistration
210 //==========================================================================
211 template <class TYPE>
212 class OMultiInstanceAutoRegistration
214 public:
215 /** automatically registeres a multi instance component
216 <p>Assumed that the template argument has the three methods
217 <ul>
218 <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/>
219 <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/>
220 <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
221 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code>
222 </li>
223 <ul/>
224 the instantiation of this object will automatically register the class via <method>OModule::registerComponent</method>.
225 <p/>
226 The factory creation function used is <code>::cppu::createSingleFactory</code>.
227 @see OOneInstanceAutoRegistration
229 OMultiInstanceAutoRegistration();
230 ~OMultiInstanceAutoRegistration();
233 template <class TYPE>
234 OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
236 OModule::registerComponent(
237 TYPE::getImplementationName_Static(),
238 TYPE::getSupportedServiceNames_Static(),
239 TYPE::Create,
240 ::cppu::createSingleFactory
244 template <class TYPE>
245 OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
247 OModule::revokeComponent(TYPE::getImplementationName_Static());
250 //==========================================================================
251 //= OOneInstanceAutoRegistration
252 //==========================================================================
253 template <class TYPE>
254 class OOneInstanceAutoRegistration
256 public:
257 /** automatically registeres a single instance component
258 <p>Assumed that the template argument has the three methods
259 <ul>
260 <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/>
261 <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/>
262 <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
263 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code>
264 </li>
265 <ul/>
266 the instantiation of this object will automatically register the class via <method>OModule::registerComponent</method>.
267 <p/>
268 The factory creation function used is <code>::cppu::createOneInstanceFactory</code>.
269 @see OOneInstanceAutoRegistration
271 OOneInstanceAutoRegistration();
272 ~OOneInstanceAutoRegistration();
275 template <class TYPE>
276 OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
278 OModule::registerComponent(
279 TYPE::getImplementationName_Static(),
280 TYPE::getSupportedServiceNames_Static(),
281 TYPE::Create,
282 ::cppu::createOneInstanceFactory
286 template <class TYPE>
287 OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
289 OModule::revokeComponent(TYPE::getImplementationName_Static());
292 //.........................................................................
293 } // namespace COMPMOD_NAMESPACE
294 //.........................................................................
296 #endif // _EXTENSIONS_COMPONENT_MODULE_HXX_