merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / adabas / Bservices.cxx
blobfd70bcb2a1264a19f2c3fe43af0b123e700bc020
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: Bservices.cxx,v $
10 * $Revision: 1.7 $
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_connectivity.hxx"
33 #include "adabas/BDriver.hxx"
34 #include <cppuhelper/factory.hxx>
35 #include <osl/diagnose.h>
37 using namespace connectivity::adabas;
38 using ::rtl::OUString;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::registry::XRegistryKey;
42 using ::com::sun::star::lang::XSingleServiceFactory;
43 using ::com::sun::star::lang::XMultiServiceFactory;
45 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
47 const Reference< XMultiServiceFactory > & rServiceManager,
48 const OUString & rComponentName,
49 ::cppu::ComponentInstantiation pCreateFunction,
50 const Sequence< OUString > & rServiceNames,
51 rtl_ModuleCount* _pT
54 //***************************************************************************************
56 // Die vorgeschriebene C-Api muss erfuellt werden!
57 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
60 //---------------------------------------------------------------------------------------
61 void REGISTER_PROVIDER(
62 const OUString& aServiceImplName,
63 const Sequence< OUString>& Services,
64 const Reference< ::com::sun::star::registry::XRegistryKey > & xKey)
66 OUString aMainKeyName;
67 aMainKeyName = OUString::createFromAscii("/");
68 aMainKeyName += aServiceImplName;
69 aMainKeyName += OUString::createFromAscii("/UNO/SERVICES");
71 Reference< ::com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) );
72 OSL_ENSURE(xNewKey.is(), "ADABAS::component_writeInfo : could not create a registry key !");
74 for (sal_Int32 i=0; i<Services.getLength(); ++i)
75 xNewKey->createKey(Services[i]);
79 //---------------------------------------------------------------------------------------
80 struct ProviderRequest
82 Reference< XSingleServiceFactory > xRet;
83 Reference< XMultiServiceFactory > const xServiceManager;
84 OUString const sImplementationName;
86 ProviderRequest(
87 void* pServiceManager,
88 sal_Char const* pImplementationName
90 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
91 , sImplementationName(OUString::createFromAscii(pImplementationName))
95 inline
96 sal_Bool CREATE_PROVIDER(
97 const OUString& Implname,
98 const Sequence< OUString > & Services,
99 ::cppu::ComponentInstantiation Factory,
100 createFactoryFunc creator
103 if (!xRet.is() && (Implname == sImplementationName))
106 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
108 catch(...)
111 return xRet.is();
114 void* getProvider() const { return xRet.get(); }
117 //---------------------------------------------------------------------------------------
119 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
120 component_getImplementationEnvironment(
121 const sal_Char **ppEnvTypeName,
122 uno_Environment ** /*ppEnv*/
125 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
128 //---------------------------------------------------------------------------------------
129 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(
130 void* /*pServiceManager*/,
131 void* pRegistryKey
134 if (pRegistryKey)
137 Reference< ::com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey*>(pRegistryKey));
139 REGISTER_PROVIDER(
140 ODriver::getImplementationName_Static(),
141 ODriver::getSupportedServiceNames_Static(), xKey);
143 return sal_True;
145 catch (::com::sun::star::registry::InvalidRegistryException& )
147 OSL_ENSURE(sal_False, "ODBC::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
150 return sal_False;
153 //---------------------------------------------------------------------------------------
154 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
155 const sal_Char* pImplementationName,
156 void* pServiceManager,
157 void* /*pRegistryKey*/)
159 void* pRet = 0;
160 if (pServiceManager)
162 ProviderRequest aReq(pServiceManager,pImplementationName);
164 aReq.CREATE_PROVIDER(
165 ODriver::getImplementationName_Static(),
166 ODriver::getSupportedServiceNames_Static(),
167 ODriver_CreateInstance, ::cppu::createSingleFactory)
170 if(aReq.xRet.is())
171 aReq.xRet->acquire();
173 pRet = aReq.getProvider();
176 return pRet;