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: configunoreg.cxx,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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
35 #include "confapifactory.hxx"
36 #include "serviceinfohelper.hxx"
37 #include <cppuhelper/factory.hxx>
38 #include <rtl/ustrbuf.hxx>
40 // ***************************************************************************************
42 // Die vorgeschriebene C-Api muss erfuellt werden!
43 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
46 //---------------------------------------------------------------------------------------
48 const configmgr::ServiceRegistrationInfo
* pInfo
,
49 const com::sun::star::uno::Reference
< com::sun::star::registry::XRegistryKey
> & xKey
)
51 if (pInfo
== 0 || pInfo
->registeredServiceNames
==0 || pInfo
->implementationName
==0)
54 rtl::OUStringBuffer aMainKeyName
;
55 aMainKeyName
.appendAscii("/");
56 aMainKeyName
.appendAscii(pInfo
->implementationName
);
57 aMainKeyName
.appendAscii("/UNO/SERVICES");
59 com::sun::star::uno::Reference
< com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
.makeStringAndClear()) );
60 OSL_ENSURE(xNewKey
.is(), "CONFMGR::component_writeInfo : could not create a registry key !");
62 for(sal_Char
const * const* p
= pInfo
->registeredServiceNames
; *p
; ++p
)
64 xNewKey
->createKey(rtl::OUString::createFromAscii(*p
));
68 //---------------------------------------------------------------------------------------
70 void RegisterSingleton(
71 const configmgr::SingletonRegistrationInfo
* pInfo
,
72 const com::sun::star::uno::Reference
< com::sun::star::registry::XRegistryKey
> & xKey
)
74 if (pInfo
== 0 || pInfo
->singletonName
==0 ||
75 pInfo
->implementationName
==0 ||
76 pInfo
->instantiatedServiceName
==0 )
79 rtl::OUStringBuffer aSingletonKeyName
;
80 aSingletonKeyName
.appendAscii("/");
81 aSingletonKeyName
.appendAscii(pInfo
->implementationName
);
82 aSingletonKeyName
.appendAscii("/UNO/SINGLETONS/");
83 aSingletonKeyName
.appendAscii(pInfo
->singletonName
);
85 com::sun::star::uno::Reference
< com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aSingletonKeyName
.makeStringAndClear()) );
86 OSL_ENSURE(xNewKey
.is(), "CONFMGR::component_writeInfo : could not create a registry key !");
88 xNewKey
->setStringValue(rtl::OUString::createFromAscii(pInfo
->instantiatedServiceName
));
90 if (pInfo
->mappedImplementation
!= 0)
91 RegisterService(pInfo
->mappedImplementation
,xKey
);
95 //-----------------------------------------------------------------------------
96 struct ServiceImplementationRequest
98 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> xRet
;
99 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> const m_xServiceManager
;
100 rtl::OUString
const sImplementationName
;
102 //-------------------------------------------------------------------------
103 ServiceImplementationRequest(
104 void* pServiceManager
,
105 sal_Char
const* pImplementationName
107 : m_xServiceManager(reinterpret_cast<com::sun::star::lang::XMultiServiceFactory
*>(pServiceManager
))
108 , sImplementationName(rtl::OUString::createFromAscii(pImplementationName
))
111 //-------------------------------------------------------------------------
113 sal_Bool
shouldCreate(const configmgr::ServiceRegistrationInfo
* pInfo
) const
115 OSL_ENSURE(!xRet
.is(), "CreateProvider : invalid creation request: we already have a return value !");
118 0 == sImplementationName
.compareToAscii(pInfo
->implementationName
);
121 //-------------------------------------------------------------------------
123 sal_Bool
CreateProviderFactory(
124 const configmgr::ServiceRegistrationInfo
* pInfo
,
128 if (this->shouldCreate(pInfo
))
131 configmgr::ServiceRegistrationHelper
aInfo(pInfo
);
133 const com::sun::star::uno::Sequence
< rtl::OUString
> Services
= aInfo
.getRegisteredServiceNames();
135 xRet
= configmgr::createProviderFactory( aInfo
.getImplementationName(), bAdmin
);
137 OSL_ENSURE(xRet
.is(), "CreateProvider : WHERE IS THE return value !");
139 catch(com::sun::star::uno::Exception
&)
145 //-------------------------------------------------------------------------
147 sal_Bool
CreateServiceFactory(
148 const configmgr::ServiceRegistrationInfo
* pInfo
,
149 ::cppu::ComponentFactoryFunc Factory
152 if (this->shouldCreate(pInfo
))
155 configmgr::ServiceRegistrationHelper
aInfo(pInfo
);
157 const com::sun::star::uno::Sequence
< rtl::OUString
> Services
= aInfo
.getRegisteredServiceNames();
159 xRet
= cppu::createSingleComponentFactory( Factory
, aInfo
.getImplementationName(), Services
, 0);
161 OSL_ENSURE(xRet
.is(), "CreateProvider : WHERE IS THE return value !");
163 catch(com::sun::star::uno::Exception
&)
169 //-------------------------------------------------------------------------
171 sal_Bool
CreateSingletonMapperFactory(
172 const configmgr::SingletonRegistrationInfo
* pInfo
,
173 ::cppu::ComponentFactoryFunc Mapper
176 OSL_ENSURE(pInfo
&& pInfo
->mappedImplementation
, "CreateProvider : Cannot map unmapped singleton !");
178 return pInfo
&& pInfo
->mappedImplementation
&&
179 CreateServiceFactory(pInfo
->mappedImplementation
,Mapper
);
182 //-------------------------------------------------------------------------
183 void* getService() const
185 // we want to transport the interface pointer as flat C void pointer, so this prevents deletion
193 //---------------------------------------------------------------------------------------
195 extern "C" SAL_DLLPUBLIC_EXPORT
196 void SAL_CALL
component_getImplementationEnvironment(
197 const sal_Char
**ppEnvTypeName
,
198 uno_Environment
** /* ppEnv */
201 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
204 //---------------------------------------------------------------------------------------
205 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
206 void* /* pServiceManager */,
213 com::sun::star::uno::Reference
< com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast<com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
215 // configuration access entry points: configuration provider
216 RegisterSingleton(configmgr::getDefaultProviderSingletonInfo(), xKey
) ;
218 RegisterService(configmgr::getConfigurationProviderServiceInfo(), xKey
);
219 RegisterService(configmgr::getDefaultProviderServiceInfo(), xKey
);
220 RegisterService(configmgr::getAdminProviderServiceInfo(), xKey
);
222 // registry wrapper (deprecated)
223 RegisterService(configmgr::getConfigurationRegistryServiceInfo(), xKey
);
226 RegisterService(configmgr::backend::getUpdateMergerServiceInfo(), xKey
);
229 RegisterService(configmgr::xml::getSchemaParserServiceInfo(), xKey
);
230 RegisterService(configmgr::xml::getLayerParserServiceInfo(), xKey
);
231 RegisterService(configmgr::xml::getLayerWriterServiceInfo(), xKey
);
233 // bootstrap handling
234 RegisterSingleton(configmgr::getBootstrapContextSingletonInfo(), xKey
) ;
235 RegisterService(configmgr::getBootstrapContextServiceInfo(), xKey
) ;
237 // backend singletons
238 RegisterSingleton(configmgr::backend::getDefaultBackendSingletonInfo(), xKey
) ;
241 RegisterService(configmgr::backend::getDefaultBackendServiceInfo(), xKey
) ;
242 RegisterService(configmgr::backend::getSingleBackendAdapterServiceInfo(), xKey
) ;
243 RegisterService(configmgr::backend::getMultiStratumBackendServiceInfo(), xKey
) ;
244 RegisterService(configmgr::localbe::getLocalBackendServiceInfo(), xKey
) ;
245 RegisterService(configmgr::localbe::getLocalDataImportServiceInfo(), xKey
) ;
246 RegisterService(configmgr::localbe::getLocalHierarchyBrowserServiceInfo(), xKey
) ;
247 RegisterService(configmgr::localbe::getLocalSchemaSupplierServiceInfo(), xKey
) ;
248 RegisterService(configmgr::localbe::getLocalLegacyStratumServiceInfo(), xKey
) ;
249 RegisterService(configmgr::localbe::getLocalDataStratumServiceInfo(), xKey
) ;
250 RegisterService(configmgr::localbe::getLocalReadonlyStratumServiceInfo(), xKey
) ;
251 RegisterService(configmgr::localbe::getLocalResourceStratumServiceInfo(), xKey
) ;
252 RegisterService(configmgr::localbe::getLocalMultiStratumServiceInfo(), xKey
) ;
255 RegisterService(configmgr::backend::getMergeImportServiceInfo(), xKey
);
256 RegisterService(configmgr::backend::getCopyImportServiceInfo(), xKey
);
260 catch (::com::sun::star::registry::InvalidRegistryException
& )
262 OSL_ENSURE(sal_False
, "configmgr: component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
268 //---------------------------------------------------------------------------------------
269 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
270 const sal_Char
* pImplementationName
,
271 void* pServiceManager
,
272 void* /*pRegistryKey*/)
277 ServiceImplementationRequest
aReq(pServiceManager
,pImplementationName
);
279 // configuration access entry points: configuration provider
280 aReq
.CreateProviderFactory(
281 configmgr::getConfigurationProviderServiceInfo(),
284 aReq
.CreateProviderFactory(
285 configmgr::getAdminProviderServiceInfo(),
288 aReq
.CreateServiceFactory(
289 configmgr::getDefaultProviderServiceInfo(),
290 &configmgr::instantiateDefaultProvider
)
292 // registry wrapper (deprecated)
293 aReq
.CreateServiceFactory(
294 configmgr::getConfigurationRegistryServiceInfo(),
295 &configmgr::instantiateConfigRegistry
)
298 aReq
.CreateServiceFactory(
299 configmgr::backend::getUpdateMergerServiceInfo(),
300 &configmgr::backend::instantiateUpdateMerger
)
303 aReq
.CreateServiceFactory(
304 configmgr::xml::getSchemaParserServiceInfo(),
305 &configmgr::xml::instantiateSchemaParser
)
307 aReq
.CreateServiceFactory(
308 configmgr::xml::getLayerParserServiceInfo(),
309 &configmgr::xml::instantiateLayerParser
)
311 aReq
.CreateServiceFactory(
312 configmgr::xml::getLayerWriterServiceInfo(),
313 &configmgr::xml::instantiateLayerWriter
)
315 // bootstrap handling
316 aReq
.CreateServiceFactory(
317 configmgr::getBootstrapContextServiceInfo(),
318 &configmgr::instantiateBootstrapContext
)
320 // backend singletons
321 aReq
.CreateSingletonMapperFactory(
322 configmgr::backend::getDefaultBackendSingletonInfo(),
323 configmgr::backend::getDefaultBackendSingleton
)
326 aReq
.CreateServiceFactory(
327 configmgr::backend::getDefaultBackendServiceInfo(),
328 configmgr::backend::instantiateDefaultBackend
)
330 aReq
.CreateServiceFactory(
331 configmgr::backend::getSingleBackendAdapterServiceInfo(),
332 configmgr::backend::instantiateSingleBackendAdapter
)
334 aReq
.CreateServiceFactory(
335 configmgr::backend::getMultiStratumBackendServiceInfo(),
336 configmgr::backend::instantiateMultiStratumBackend
)
338 aReq
.CreateServiceFactory(
339 configmgr::localbe::getLocalBackendServiceInfo(),
340 configmgr::localbe::instantiateLocalBackend
)
342 aReq
.CreateServiceFactory(
343 configmgr::localbe::getLocalDataImportServiceInfo(),
344 configmgr::localbe::instantiateLocalDataImporter
)
346 aReq
.CreateServiceFactory(
347 configmgr::localbe::getLocalHierarchyBrowserServiceInfo(),
348 configmgr::localbe::instantiateLocalHierarchyBrowser
)
350 aReq
.CreateServiceFactory(
351 configmgr::localbe::getLocalSchemaSupplierServiceInfo(),
352 configmgr::localbe::instantiateLocalSchemaSupplier
)
354 aReq
.CreateServiceFactory(
355 configmgr::localbe::getLocalLegacyStratumServiceInfo(),
356 configmgr::localbe::instantiateLocalLegacyStratum
)
358 aReq
.CreateServiceFactory(
359 configmgr::localbe::getLocalDataStratumServiceInfo(),
360 configmgr::localbe::instantiateLocalDataStratum
)
362 aReq
.CreateServiceFactory(
363 configmgr::localbe::getLocalReadonlyStratumServiceInfo(),
364 configmgr::localbe::instantiateLocalReadonlyStratum
)
366 aReq
.CreateServiceFactory(
367 configmgr::localbe::getLocalResourceStratumServiceInfo(),
368 configmgr::localbe::instantiateLocalResourceStratum
)
370 aReq
.CreateServiceFactory(
371 configmgr::localbe::getLocalMultiStratumServiceInfo(),
372 configmgr::localbe::instantiateLocalMultiStratum
)
375 aReq
.CreateServiceFactory(
376 configmgr::backend::getMergeImportServiceInfo(),
377 &configmgr::backend::instantiateMergeImporter
)
379 aReq
.CreateServiceFactory(
380 configmgr::backend::getCopyImportServiceInfo(),
381 &configmgr::backend::instantiateCopyImporter
);
383 pRet
= aReq
.getService();
388 //---------------------------------------------------------------------------------------