1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // no include "precompiled_dbaccess.hxx" because this file is meant to 25cdf0e10cSrcweir // be included in other cxx files 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _REGISTRATIONHELPER_CXX_INCLUDED_INDIRECTLY_ 28cdf0e10cSrcweir #error "don't build this file directly! use dbu_reghelper.cxx instead!" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace ::com::sun::star; 32cdf0e10cSrcweir using namespace ::comphelper; 33cdf0e10cSrcweir using namespace ::cppu; 34cdf0e10cSrcweir 35cdf0e10cSrcweir uno::Sequence< ::rtl::OUString >* OModuleRegistration::s_pImplementationNames = NULL; 36cdf0e10cSrcweir uno::Sequence< uno::Sequence< ::rtl::OUString > >* OModuleRegistration::s_pSupportedServices = NULL; 37cdf0e10cSrcweir uno::Sequence< sal_Int64 >* OModuleRegistration::s_pCreationFunctionPointers = NULL; 38cdf0e10cSrcweir uno::Sequence< sal_Int64 >* OModuleRegistration::s_pFactoryFunctionPointers = NULL; 39cdf0e10cSrcweir 40cdf0e10cSrcweir //-------------------------------------------------------------------------- 41cdf0e10cSrcweir void OModuleRegistration::registerComponent( 42cdf0e10cSrcweir const ::rtl::OUString& _rImplementationName, 43cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString >& _rServiceNames, 44cdf0e10cSrcweir ComponentInstantiation _pCreateFunction, 45cdf0e10cSrcweir FactoryInstantiation _pFactoryFunction) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir if (!s_pImplementationNames) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers, 50cdf0e10cSrcweir "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !"); 51cdf0e10cSrcweir s_pImplementationNames = new uno::Sequence< ::rtl::OUString >; 52cdf0e10cSrcweir s_pSupportedServices = new uno::Sequence< uno::Sequence< ::rtl::OUString > >; 53cdf0e10cSrcweir s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >; 54cdf0e10cSrcweir s_pFactoryFunctionPointers = new uno::Sequence< sal_Int64 >; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers, 57cdf0e10cSrcweir "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !"); 58cdf0e10cSrcweir 59cdf0e10cSrcweir OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength()) 60cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength()) 61cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()), 62cdf0e10cSrcweir "OModuleRegistration::registerComponent : inconsistent state !"); 63cdf0e10cSrcweir 64cdf0e10cSrcweir sal_Int32 nOldLen = s_pImplementationNames->getLength(); 65cdf0e10cSrcweir s_pImplementationNames->realloc(nOldLen + 1); 66cdf0e10cSrcweir s_pSupportedServices->realloc(nOldLen + 1); 67cdf0e10cSrcweir s_pCreationFunctionPointers->realloc(nOldLen + 1); 68cdf0e10cSrcweir s_pFactoryFunctionPointers->realloc(nOldLen + 1); 69cdf0e10cSrcweir 70cdf0e10cSrcweir s_pImplementationNames->getArray()[nOldLen] = _rImplementationName; 71cdf0e10cSrcweir s_pSupportedServices->getArray()[nOldLen] = _rServiceNames; 72cdf0e10cSrcweir s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction); 73cdf0e10cSrcweir s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir //-------------------------------------------------------------------------- 77cdf0e10cSrcweir void OModuleRegistration::revokeComponent(const ::rtl::OUString& _rImplementationName) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir if (!s_pImplementationNames) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir OSL_ENSURE(sal_False, "OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?"); 82cdf0e10cSrcweir return; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers, 85cdf0e10cSrcweir "OModuleRegistration::revokeComponent : inconsistent state (the pointers) !"); 86cdf0e10cSrcweir OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength()) 87cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength()) 88cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()), 89cdf0e10cSrcweir "OModuleRegistration::revokeComponent : inconsistent state !"); 90cdf0e10cSrcweir 91cdf0e10cSrcweir sal_Int32 nLen = s_pImplementationNames->getLength(); 92cdf0e10cSrcweir const ::rtl::OUString* pImplNames = s_pImplementationNames->getConstArray(); 93cdf0e10cSrcweir for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir if (pImplNames->equals(_rImplementationName)) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir removeElementAt(*s_pImplementationNames, i); 98cdf0e10cSrcweir removeElementAt(*s_pSupportedServices, i); 99cdf0e10cSrcweir removeElementAt(*s_pCreationFunctionPointers, i); 100cdf0e10cSrcweir removeElementAt(*s_pFactoryFunctionPointers, i); 101cdf0e10cSrcweir break; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir if (s_pImplementationNames->getLength() == 0) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir delete s_pImplementationNames; s_pImplementationNames = NULL; 108cdf0e10cSrcweir delete s_pSupportedServices; s_pSupportedServices = NULL; 109cdf0e10cSrcweir delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL; 110cdf0e10cSrcweir delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir //-------------------------------------------------------------------------- 115cdf0e10cSrcweir uno::Reference< uno::XInterface > OModuleRegistration::getComponentFactory( 116cdf0e10cSrcweir const ::rtl::OUString& _rImplementationName, 117cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& _rxServiceManager) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir OSL_ENSURE(_rxServiceManager.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !"); 120cdf0e10cSrcweir OSL_ENSURE(_rImplementationName.getLength(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !"); 121cdf0e10cSrcweir 122cdf0e10cSrcweir if (!s_pImplementationNames) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir OSL_ENSURE(sal_False, "OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?"); 125cdf0e10cSrcweir return NULL; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers, 128cdf0e10cSrcweir "OModuleRegistration::getComponentFactory : inconsistent state (the pointers) !"); 129cdf0e10cSrcweir OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength()) 130cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength()) 131cdf0e10cSrcweir && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()), 132cdf0e10cSrcweir "OModuleRegistration::getComponentFactory : inconsistent state !"); 133cdf0e10cSrcweir 134cdf0e10cSrcweir 135cdf0e10cSrcweir uno::Reference< uno::XInterface > xReturn; 136cdf0e10cSrcweir 137cdf0e10cSrcweir 138cdf0e10cSrcweir sal_Int32 nLen = s_pImplementationNames->getLength(); 139cdf0e10cSrcweir const ::rtl::OUString* pImplName = s_pImplementationNames->getConstArray(); 140cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString >* pServices = s_pSupportedServices->getConstArray(); 141cdf0e10cSrcweir const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray(); 142cdf0e10cSrcweir const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray(); 143cdf0e10cSrcweir 144cdf0e10cSrcweir for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir if (pImplName->equals(_rImplementationName)) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction); 149cdf0e10cSrcweir const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction); 150cdf0e10cSrcweir 151cdf0e10cSrcweir xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL); 152cdf0e10cSrcweir if (xReturn.is()) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir xReturn->acquire(); 155cdf0e10cSrcweir return xReturn.get(); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir return NULL; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir 164