merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Database / DriverSkeleton / SServices.cxx
blob986452675bb6b6977107866d374ff51de91b6ebd
1 /*************************************************************************
3 * $RCSfile: SServices.cxx,v $
5 * $Revision: 1.6 $
7 * last change: $Author: rt $ $Date: 2008-04-10 16:36:52 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 #include "SDriver.hxx"
42 #include <cppuhelper/factory.hxx>
43 #include <osl/diagnose.h>
45 using namespace connectivity::skeleton;
46 using ::rtl::OUString;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::registry::XRegistryKey;
50 using ::com::sun::star::lang::XSingleServiceFactory;
51 using ::com::sun::star::lang::XMultiServiceFactory;
53 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
55 const Reference< XMultiServiceFactory > & rServiceManager,
56 const OUString & rComponentName,
57 ::cppu::ComponentInstantiation pCreateFunction,
58 const Sequence< OUString > & rServiceNames,
59 rtl_ModuleCount* _pTemp
62 //***************************************************************************************
64 // Die vorgeschriebene C-Api muss erfuellt werden!
65 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
68 //---------------------------------------------------------------------------------------
69 void REGISTER_PROVIDER(
70 const OUString& aServiceImplName,
71 const Sequence< OUString>& Services,
72 const Reference< ::com::sun::star::registry::XRegistryKey > & xKey)
74 OUString aMainKeyName;
75 aMainKeyName = OUString::createFromAscii("/");
76 aMainKeyName += aServiceImplName;
77 aMainKeyName += OUString::createFromAscii("/UNO/SERVICES");
79 Reference< ::com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) );
80 OSL_ENSURE(xNewKey.is(), "SKELETON::component_writeInfo : could not create a registry key !");
82 for (sal_uInt32 i=0; i<Services.getLength(); ++i)
83 xNewKey->createKey(Services[i]);
87 //---------------------------------------------------------------------------------------
88 struct ProviderRequest
90 Reference< XSingleServiceFactory > xRet;
91 Reference< XMultiServiceFactory > const xServiceManager;
92 OUString const sImplementationName;
94 ProviderRequest(
95 void* pServiceManager,
96 sal_Char const* pImplementationName
98 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
99 , sImplementationName(OUString::createFromAscii(pImplementationName))
103 inline
104 sal_Bool CREATE_PROVIDER(
105 const OUString& Implname,
106 const Sequence< OUString > & Services,
107 ::cppu::ComponentInstantiation Factory,
108 createFactoryFunc creator
111 if (!xRet.is() && (Implname == sImplementationName))
112 try
114 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
116 catch(...)
119 return xRet.is();
122 void* getProvider() const { return xRet.get(); }
125 //---------------------------------------------------------------------------------------
127 extern "C" void SAL_CALL component_getImplementationEnvironment(
128 const sal_Char **ppEnvTypeName,
129 uno_Environment **ppEnv
132 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
135 //---------------------------------------------------------------------------------------
136 extern "C" sal_Bool SAL_CALL component_writeInfo(
137 void* pServiceManager,
138 void* pRegistryKey
141 if (pRegistryKey)
142 try
144 Reference< ::com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey*>(pRegistryKey));
146 REGISTER_PROVIDER(
147 SkeletonDriver::getImplementationName_Static(),
148 SkeletonDriver::getSupportedServiceNames_Static(), xKey);
150 return sal_True;
152 catch (::com::sun::star::registry::InvalidRegistryException& )
154 OSL_ENSURE(sal_False, "SKELETON::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
157 return sal_False;
160 //---------------------------------------------------------------------------------------
161 extern "C" void* SAL_CALL component_getFactory(
162 const sal_Char* pImplementationName,
163 void* pServiceManager,
164 void* pRegistryKey)
166 void* pRet = 0;
167 if (pServiceManager)
169 ProviderRequest aReq(pServiceManager,pImplementationName);
171 aReq.CREATE_PROVIDER(
172 SkeletonDriver::getImplementationName_Static(),
173 SkeletonDriver::getSupportedServiceNames_Static(),
174 SkeletonDriver_CreateInstance, ::cppu::createSingleFactory)
177 if(aReq.xRet.is())
178 aReq.xRet->acquire();
180 pRet = aReq.getProvider();
183 return pRet;