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: Hservices.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_connectivity.hxx"
34 #include "hsqldb/HDriver.hxx"
35 #include <cppuhelper/factory.hxx>
36 #include <osl/diagnose.h>
38 using namespace connectivity::hsqldb
;
39 using ::rtl::OUString
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Sequence
;
42 using ::com::sun::star::registry::XRegistryKey
;
43 using ::com::sun::star::lang::XSingleServiceFactory
;
44 using ::com::sun::star::lang::XMultiServiceFactory
;
46 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
48 const Reference
< XMultiServiceFactory
> & rServiceManager
,
49 const OUString
& rComponentName
,
50 ::cppu::ComponentInstantiation pCreateFunction
,
51 const Sequence
< OUString
> & rServiceNames
,
55 //***************************************************************************************
57 // Die vorgeschriebene C-Api muss erfuellt werden!
58 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
61 //---------------------------------------------------------------------------------------
62 void REGISTER_PROVIDER(
63 const OUString
& aServiceImplName
,
64 const Sequence
< OUString
>& Services
,
65 const Reference
< ::com::sun::star::registry::XRegistryKey
> & xKey
)
67 OUString aMainKeyName
;
68 aMainKeyName
= OUString::createFromAscii("/");
69 aMainKeyName
+= aServiceImplName
;
70 aMainKeyName
+= OUString::createFromAscii("/UNO/SERVICES");
72 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
73 OSL_ENSURE(xNewKey
.is(), "ADABAS::component_writeInfo : could not create a registry key !");
75 for (sal_Int32 i
=0; i
<Services
.getLength(); ++i
)
76 xNewKey
->createKey(Services
[i
]);
80 //---------------------------------------------------------------------------------------
81 struct ProviderRequest
83 Reference
< XSingleServiceFactory
> xRet
;
84 Reference
< XMultiServiceFactory
> const xServiceManager
;
85 OUString
const sImplementationName
;
88 void* pServiceManager
,
89 sal_Char
const* pImplementationName
91 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
92 , sImplementationName(OUString::createFromAscii(pImplementationName
))
97 sal_Bool
CREATE_PROVIDER(
98 const OUString
& Implname
,
99 const Sequence
< OUString
> & Services
,
100 ::cppu::ComponentInstantiation Factory
,
101 createFactoryFunc creator
104 if (!xRet
.is() && (Implname
== sImplementationName
))
107 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
115 void* getProvider() const { return xRet
.get(); }
118 //---------------------------------------------------------------------------------------
120 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
121 component_getImplementationEnvironment(
122 const sal_Char
**ppEnvTypeName
,
123 uno_Environment
** /*ppEnv*/
126 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
129 //---------------------------------------------------------------------------------------
130 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
131 void* /*pServiceManager*/,
138 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
141 ODriverDelegator::getImplementationName_Static(),
142 ODriverDelegator::getSupportedServiceNames_Static(), xKey
);
146 catch (::com::sun::star::registry::InvalidRegistryException
& )
148 OSL_ENSURE(sal_False
, "ODBC::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
154 //---------------------------------------------------------------------------------------
155 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
156 const sal_Char
* pImplementationName
,
157 void* pServiceManager
,
158 void* /*pRegistryKey*/)
163 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
165 aReq
.CREATE_PROVIDER(
166 ODriverDelegator::getImplementationName_Static(),
167 ODriverDelegator::getSupportedServiceNames_Static(),
168 ODriverDelegator_CreateInstance
, ::cppu::createSingleFactory
)
172 aReq
.xRet
->acquire();
174 pRet
= aReq
.getProvider();