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