1 #ifndef FORMS_MODULE_IMPLEMENTATION_INCLUDE_CONTEXT
2 #error "not to be included directly! use 'foo_module.hxx instead'!"
5 #ifndef FORMS_MODULE_NAMESPACE
6 #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!"
9 #include <comphelper/sequence.hxx>
11 //.........................................................................
12 namespace FORMS_MODULE_NAMESPACE
14 //.........................................................................
16 using namespace ::com::sun::star::uno
;
17 using namespace ::com::sun::star::lang
;
18 using namespace ::com::sun::star::registry
;
19 using namespace ::comphelper
;
20 using namespace ::cppu
;
22 //=========================================================================
24 //=========================================================================
26 //--------------------------------------------------------------------------
27 //- registration helper
28 //--------------------------------------------------------------------------
30 Sequence
< ::rtl::OUString
>* OFormsModule::s_pImplementationNames
= NULL
;
31 Sequence
< Sequence
< ::rtl::OUString
> >* OFormsModule::s_pSupportedServices
= NULL
;
32 Sequence
< sal_Int64
>* OFormsModule::s_pCreationFunctionPointers
= NULL
;
33 Sequence
< sal_Int64
>* OFormsModule::s_pFactoryFunctionPointers
= NULL
;
35 //--------------------------------------------------------------------------
36 void OFormsModule::registerComponent(
37 const ::rtl::OUString
& _rImplementationName
,
38 const Sequence
< ::rtl::OUString
>& _rServiceNames
,
39 ComponentInstantiation _pCreateFunction
,
40 FactoryInstantiation _pFactoryFunction
)
42 if (!s_pImplementationNames
)
44 OSL_ENSURE(!s_pSupportedServices
&& !s_pCreationFunctionPointers
&& !s_pFactoryFunctionPointers
,
45 "OFormsModule::registerComponent : inconsistent state (the pointers (1)) !");
46 s_pImplementationNames
= new Sequence
< ::rtl::OUString
>;
47 s_pSupportedServices
= new Sequence
< Sequence
< ::rtl::OUString
> >;
48 s_pCreationFunctionPointers
= new Sequence
< sal_Int64
>;
49 s_pFactoryFunctionPointers
= new Sequence
< sal_Int64
>;
51 OSL_ENSURE(s_pImplementationNames
&& s_pSupportedServices
&& s_pCreationFunctionPointers
&& s_pFactoryFunctionPointers
,
52 "OFormsModule::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 "OFormsModule::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 OFormsModule::revokeComponent(const ::rtl::OUString
& _rImplementationName
)
74 if (!s_pImplementationNames
)
76 OSL_ASSERT("OFormsModule::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
79 OSL_ENSURE(s_pImplementationNames
&& s_pSupportedServices
&& s_pCreationFunctionPointers
&& s_pFactoryFunctionPointers
,
80 "OFormsModule::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 "OFormsModule::revokeComponent : inconsistent state !");
86 sal_Int32 nLen
= s_pImplementationNames
->getLength();
87 const ::rtl::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
);
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 sal_Bool
OFormsModule::writeComponentInfos(
111 const Reference
< XMultiServiceFactory
>& /*_rxServiceManager*/,
112 const Reference
< XRegistryKey
>& _rxRootKey
)
114 OSL_ENSURE(_rxRootKey
.is(), "OFormsModule::writeComponentInfos : invalid argument !");
116 if (!s_pImplementationNames
)
118 OSL_ASSERT("OFormsModule::writeComponentInfos : have no class infos ! Are you sure called this method at the right time ?");
121 OSL_ENSURE(s_pImplementationNames
&& s_pSupportedServices
&& s_pCreationFunctionPointers
&& s_pFactoryFunctionPointers
,
122 "OFormsModule::writeComponentInfos : inconsistent state (the pointers) !");
123 OSL_ENSURE( (s_pImplementationNames
->getLength() == s_pSupportedServices
->getLength())
124 && (s_pImplementationNames
->getLength() == s_pCreationFunctionPointers
->getLength())
125 && (s_pImplementationNames
->getLength() == s_pFactoryFunctionPointers
->getLength()),
126 "OFormsModule::writeComponentInfos : inconsistent state !");
128 sal_Int32 nLen
= s_pImplementationNames
->getLength();
129 const ::rtl::OUString
* pImplName
= s_pImplementationNames
->getConstArray();
130 const Sequence
< ::rtl::OUString
>* pServices
= s_pSupportedServices
->getConstArray();
132 ::rtl::OUString
sRootKey("/", 1, RTL_TEXTENCODING_ASCII_US
);
133 for (sal_Int32 i
=0; i
<nLen
; ++i
, ++pImplName
, ++pServices
)
135 ::rtl::OUString
aMainKeyName(sRootKey
);
136 aMainKeyName
+= *pImplName
;
137 aMainKeyName
+= ::rtl::OUString::createFromAscii("/UNO/SERVICES");
141 Reference
< XRegistryKey
> xNewKey( _rxRootKey
->createKey(aMainKeyName
) );
143 const ::rtl::OUString
* pService
= pServices
->getConstArray();
144 for (sal_Int32 j
=0; j
<pServices
->getLength(); ++j
, ++pService
)
145 xNewKey
->createKey(*pService
);
149 OSL_ASSERT("OFormsModule::writeComponentInfos : something went wrong while creating the keys !");
157 //--------------------------------------------------------------------------
158 Reference
< XInterface
> OFormsModule::getComponentFactory(
159 const ::rtl::OUString
& _rImplementationName
,
160 const Reference
< XMultiServiceFactory
>& _rxServiceManager
)
162 OSL_ENSURE(_rxServiceManager
.is(), "OFormsModule::getComponentFactory : invalid argument (service manager) !");
163 OSL_ENSURE(_rImplementationName
.getLength(), "OFormsModule::getComponentFactory : invalid argument (implementation name) !");
165 if (!s_pImplementationNames
)
167 OSL_ASSERT("OFormsModule::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
170 OSL_ENSURE(s_pImplementationNames
&& s_pSupportedServices
&& s_pCreationFunctionPointers
&& s_pFactoryFunctionPointers
,
171 "OFormsModule::getComponentFactory : inconsistent state (the pointers) !");
172 OSL_ENSURE( (s_pImplementationNames
->getLength() == s_pSupportedServices
->getLength())
173 && (s_pImplementationNames
->getLength() == s_pCreationFunctionPointers
->getLength())
174 && (s_pImplementationNames
->getLength() == s_pFactoryFunctionPointers
->getLength()),
175 "OFormsModule::getComponentFactory : inconsistent state !");
178 Reference
< XInterface
> xReturn
;
181 sal_Int32 nLen
= s_pImplementationNames
->getLength();
182 const ::rtl::OUString
* pImplName
= s_pImplementationNames
->getConstArray();
183 const Sequence
< ::rtl::OUString
>* pServices
= s_pSupportedServices
->getConstArray();
184 const sal_Int64
* pComponentFunction
= s_pCreationFunctionPointers
->getConstArray();
185 const sal_Int64
* pFactoryFunction
= s_pFactoryFunctionPointers
->getConstArray();
187 for (sal_Int32 i
=0; i
<nLen
; ++i
, ++pImplName
, ++pServices
, ++pComponentFunction
, ++pFactoryFunction
)
189 if (pImplName
->equals(_rImplementationName
))
191 const FactoryInstantiation FactoryInstantiationFunction
= reinterpret_cast<const FactoryInstantiation
>(*pFactoryFunction
);
192 const ComponentInstantiation ComponentInstantiationFunction
= reinterpret_cast<const ComponentInstantiation
>(*pComponentFunction
);
194 xReturn
= FactoryInstantiationFunction( _rxServiceManager
, *pImplName
, ComponentInstantiationFunction
, *pServices
, NULL
);
198 return xReturn
.get();
206 //.........................................................................
207 } // namespace FORMS_MODULE_NAMESPACE
208 //.........................................................................