merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / macab / MacabServices.cxx
blob4541df29b9ac332c571ac3f917df3c576e9b0577
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: MacabServices.cxx,v $
10 * $Revision: 1.3 $
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 "MacabDriver.hxx"
35 #include <cppuhelper/factory.hxx>
36 #include <osl/diagnose.h>
38 using namespace connectivity::macab;
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,
52 rtl_ModuleCount* _pTemp
55 //***************************************************************************************
57 // The following C Api must be provided!
58 // It consists in three functions that must be exported by the module
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(), "MACAB::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;
87 ProviderRequest(
88 void* pServiceManager,
89 sal_Char const* pImplementationName
91 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
92 , sImplementationName(OUString::createFromAscii(pImplementationName))
96 inline
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);
109 catch(...)
112 return xRet.is();
115 void* getProvider() const { return xRet.get(); }
118 //---------------------------------------------------------------------------------------
120 extern "C" void SAL_CALL component_getImplementationEnvironment(
121 const sal_Char **ppEnvTypeName,
122 uno_Environment **
125 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
128 //---------------------------------------------------------------------------------------
129 extern "C" sal_Bool SAL_CALL component_writeInfo(
130 void*,
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 MacabDriver::getImplementationName_Static(),
141 MacabDriver::getSupportedServiceNames_Static(), xKey);
143 return sal_True;
145 catch (::com::sun::star::registry::InvalidRegistryException& )
147 OSL_ENSURE(sal_False, "MACAB::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
150 return sal_False;
153 //---------------------------------------------------------------------------------------
154 extern "C" void* SAL_CALL component_getFactory(
155 const sal_Char* pImplementationName,
156 void* pServiceManager,
157 void*)
159 void* pRet = 0;
160 if (pServiceManager)
162 ProviderRequest aReq(pServiceManager,pImplementationName);
164 aReq.CREATE_PROVIDER(
165 MacabDriver::getImplementationName_Static(),
166 MacabDriver::getSupportedServiceNames_Static(),
167 &MacabDriver::Create,
168 ::cppu::createSingleFactory)
171 if (aReq.xRet.is())
172 aReq.xRet->acquire();
174 pRet = aReq.getProvider();
177 return pRet;