merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / jdbc / jservices.cxx
blob2f9875b6ec7076365bc28e95423398f593d96952
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: jservices.cxx,v $
10 * $Revision: 1.9 $
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 "java/sql/Driver.hxx"
34 #include <cppuhelper/factory.hxx>
36 using namespace connectivity;
37 using ::rtl::OUString;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::registry::XRegistryKey;
41 using ::com::sun::star::lang::XSingleServiceFactory;
42 using ::com::sun::star::lang::XMultiServiceFactory;
44 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
46 const Reference< XMultiServiceFactory > & rServiceManager,
47 const OUString & rComponentName,
48 ::cppu::ComponentInstantiation pCreateFunction,
49 const Sequence< OUString > & rServiceNames,
50 rtl_ModuleCount* _pModCount
53 //***************************************************************************************
55 // Die vorgeschriebene C-Api muss erfuellt werden!
56 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
59 //---------------------------------------------------------------------------------------
60 void REGISTER_PROVIDER(
61 const OUString& aServiceImplName,
62 const Sequence< OUString>& Services,
63 const Reference< ::com::sun::star::registry::XRegistryKey > & xKey)
65 OUString aMainKeyName;
66 aMainKeyName = OUString::createFromAscii("/");
67 aMainKeyName += aServiceImplName;
68 aMainKeyName += OUString::createFromAscii("/UNO/SERVICES");
70 Reference< ::com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) );
71 OSL_ENSURE(xNewKey.is(), "SBA::component_writeInfo : could not create a registry key !");
73 for (sal_Int32 i=0; i<Services.getLength(); ++i)
74 xNewKey->createKey(Services[i]);
78 //---------------------------------------------------------------------------------------
79 struct ProviderRequest
81 Reference< XSingleServiceFactory > xRet;
82 Reference< XMultiServiceFactory > const xServiceManager;
83 OUString const sImplementationName;
85 ProviderRequest(
86 void* pServiceManager,
87 sal_Char const* pImplementationName
89 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
90 , sImplementationName(OUString::createFromAscii(pImplementationName))
94 inline
95 sal_Bool CREATE_PROVIDER(
96 const OUString& Implname,
97 const Sequence< OUString > & Services,
98 ::cppu::ComponentInstantiation Factory,
99 createFactoryFunc creator
102 if (!xRet.is() && (Implname == sImplementationName))
105 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
107 catch(...)
110 return xRet.is();
113 void* getProvider() const { return xRet.get(); }
116 //---------------------------------------------------------------------------------------
118 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
119 component_getImplementationEnvironment(
120 const sal_Char **ppEnvTypeName,
121 uno_Environment ** /*ppEnv*/
124 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
127 //---------------------------------------------------------------------------------------
128 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(
129 void* /*pServiceManager*/,
130 void* pRegistryKey
133 if (pRegistryKey)
136 Reference< ::com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey*>(pRegistryKey));
138 REGISTER_PROVIDER(
139 java_sql_Driver::getImplementationName_Static(),
140 java_sql_Driver::getSupportedServiceNames_Static(), xKey);
142 return sal_True;
144 catch (::com::sun::star::registry::InvalidRegistryException& )
146 OSL_ENSURE(sal_False, "SBA::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
149 return sal_False;
152 //---------------------------------------------------------------------------------------
153 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
154 const sal_Char* pImplementationName,
155 void* pServiceManager,
156 void* /*pRegistryKey*/)
158 void* pRet = 0;
159 if (pServiceManager)
161 ProviderRequest aReq(pServiceManager,pImplementationName);
163 aReq.CREATE_PROVIDER(
164 java_sql_Driver::getImplementationName_Static(),
165 java_sql_Driver::getSupportedServiceNames_Static(),
166 java_sql_Driver_CreateInstance,
167 ::cppu::createSingleFactory);
169 if(aReq.xRet.is())
170 aReq.xRet->acquire();
171 pRet = aReq.getProvider();
174 return pRet;