1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "ado/ADriver.hxx" 31 #include <cppuhelper/factory.hxx> 32 33 using namespace connectivity::ado; 34 using ::rtl::OUString; 35 using ::com::sun::star::uno::Reference; 36 using ::com::sun::star::uno::Sequence; 37 using ::com::sun::star::lang::XSingleServiceFactory; 38 using ::com::sun::star::lang::XMultiServiceFactory; 39 40 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc) 41 ( 42 const Reference< XMultiServiceFactory > & rServiceManager, 43 const OUString & rComponentName, 44 ::cppu::ComponentInstantiation pCreateFunction, 45 const Sequence< OUString > & rServiceNames , 46 rtl_ModuleCount* _pT 47 ); 48 49 //--------------------------------------------------------------------------------------- 50 struct ProviderRequest 51 { 52 Reference< XSingleServiceFactory > xRet; 53 Reference< XMultiServiceFactory > const xServiceManager; 54 OUString const sImplementationName; 55 56 ProviderRequest( 57 void* pServiceManager, 58 sal_Char const* pImplementationName 59 ) 60 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager)) 61 , sImplementationName(OUString::createFromAscii(pImplementationName)) 62 { 63 } 64 65 inline 66 sal_Bool CREATE_PROVIDER( 67 const OUString& Implname, 68 const Sequence< OUString > & Services, 69 ::cppu::ComponentInstantiation Factory, 70 createFactoryFunc creator 71 ) 72 { 73 if (!xRet.is() && (Implname == sImplementationName)) 74 try 75 { 76 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0); 77 } 78 catch(...) 79 { 80 } 81 return xRet.is(); 82 } 83 84 void* getProvider() const { return xRet.get(); } 85 }; 86 87 //--------------------------------------------------------------------------------------- 88 89 extern "C" void SAL_CALL component_getImplementationEnvironment( 90 const sal_Char **ppEnvTypeName, 91 uno_Environment ** /*ppEnv*/ 92 ) 93 { 94 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ":affine"; 95 } 96 97 //--------------------------------------------------------------------------------------- 98 extern "C" void* SAL_CALL component_getFactory( 99 const sal_Char* pImplementationName, 100 void* pServiceManager, 101 void* /*pRegistryKey*/) 102 { 103 void* pRet = 0; 104 if (pServiceManager) 105 { 106 ProviderRequest aReq(pServiceManager,pImplementationName); 107 108 aReq.CREATE_PROVIDER( 109 ODriver::getImplementationName_Static(), 110 ODriver::getSupportedServiceNames_Static(), 111 ODriver_CreateInstance, ::cppu::createSingleFactory) 112 ; 113 114 if(aReq.xRet.is()) 115 aReq.xRet->acquire(); 116 117 pRet = aReq.getProvider(); 118 } 119 120 return pRet; 121 }; 122 123 124