update credits
[LibreOffice.git] / dbaccess / source / shared / registrationhelper.cxx
blob9fdaf34e006e1e9557ca3a207dec250b60607da3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // be included in other cxx files
22 #ifndef _REGISTRATIONHELPER_CXX_INCLUDED_INDIRECTLY_
23 #error "don't build this file directly! use dbu_reghelper.cxx instead!"
24 #endif
26 using namespace ::com::sun::star;
27 using namespace ::comphelper;
28 using namespace ::cppu;
30 uno::Sequence< OUString >* OModuleRegistration::s_pImplementationNames = NULL;
31 uno::Sequence< uno::Sequence< OUString > >* OModuleRegistration::s_pSupportedServices = NULL;
32 uno::Sequence< sal_Int64 >* OModuleRegistration::s_pCreationFunctionPointers = NULL;
33 uno::Sequence< sal_Int64 >* OModuleRegistration::s_pFactoryFunctionPointers = NULL;
35 //--------------------------------------------------------------------------
36 void OModuleRegistration::registerComponent(
37 const OUString& _rImplementationName,
38 const uno::Sequence< OUString >& _rServiceNames,
39 ComponentInstantiation _pCreateFunction,
40 FactoryInstantiation _pFactoryFunction)
42 if (!s_pImplementationNames)
44 OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
45 "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
46 s_pImplementationNames = new uno::Sequence< OUString >;
47 s_pSupportedServices = new uno::Sequence< uno::Sequence< OUString > >;
48 s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >;
49 s_pFactoryFunctionPointers = new uno::Sequence< sal_Int64 >;
51 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
52 "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !");
54 OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
55 && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
56 && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
57 "OModuleRegistration::registerComponent : inconsistent state !");
59 sal_Int32 nOldLen = s_pImplementationNames->getLength();
60 s_pImplementationNames->realloc(nOldLen + 1);
61 s_pSupportedServices->realloc(nOldLen + 1);
62 s_pCreationFunctionPointers->realloc(nOldLen + 1);
63 s_pFactoryFunctionPointers->realloc(nOldLen + 1);
65 s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
66 s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
67 s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
68 s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
71 //--------------------------------------------------------------------------
72 void OModuleRegistration::revokeComponent(const OUString& _rImplementationName)
74 if (!s_pImplementationNames)
76 OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
77 return;
79 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
80 "OModuleRegistration::revokeComponent : inconsistent state (the pointers) !");
81 OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
82 && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
83 && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
84 "OModuleRegistration::revokeComponent : inconsistent state !");
86 sal_Int32 nLen = s_pImplementationNames->getLength();
87 const OUString* pImplNames = s_pImplementationNames->getConstArray();
88 for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
90 if (pImplNames->equals(_rImplementationName))
92 removeElementAt(*s_pImplementationNames, i);
93 removeElementAt(*s_pSupportedServices, i);
94 removeElementAt(*s_pCreationFunctionPointers, i);
95 removeElementAt(*s_pFactoryFunctionPointers, i);
96 break;
100 if (s_pImplementationNames->getLength() == 0)
102 delete s_pImplementationNames; s_pImplementationNames = NULL;
103 delete s_pSupportedServices; s_pSupportedServices = NULL;
104 delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
105 delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
109 //--------------------------------------------------------------------------
110 uno::Reference< uno::XInterface > OModuleRegistration::getComponentFactory(
111 const OUString& _rImplementationName,
112 const uno::Reference< lang::XMultiServiceFactory >& _rxServiceManager)
114 OSL_ENSURE(_rxServiceManager.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !");
115 OSL_ENSURE(!_rImplementationName.isEmpty(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !");
117 if (!s_pImplementationNames)
119 OSL_FAIL("OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
120 return NULL;
122 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
123 "OModuleRegistration::getComponentFactory : inconsistent state (the pointers) !");
124 OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
125 && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
126 && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
127 "OModuleRegistration::getComponentFactory : inconsistent state !");
130 uno::Reference< uno::XInterface > xReturn;
133 sal_Int32 nLen = s_pImplementationNames->getLength();
134 const OUString* pImplName = s_pImplementationNames->getConstArray();
135 const uno::Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
136 const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
137 const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
139 for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
141 if (pImplName->equals(_rImplementationName))
143 const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
144 const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
146 xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
147 if (xReturn.is())
149 xReturn->acquire();
150 return xReturn.get();
155 return NULL;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */