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