masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / inc / forms_module_impl.hxx
blobd10527075ae3c4bbe8d6558d84813e9e6dce227e
1 #ifndef FORMS_MODULE_IMPLEMENTATION_INCLUDE_CONTEXT
2 #error "not to be included directly! use 'foo_module.hxx instead'!"
3 #endif
5 #ifndef FORMS_MODULE_NAMESPACE
6 #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!"
7 #endif
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 //=========================================================================
23 //= OFormsModule
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 ?");
77 return;
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);
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 Reference< XInterface > OFormsModule::getComponentFactory(
111 const ::rtl::OUString& _rImplementationName,
112 const Reference< XMultiServiceFactory >& _rxServiceManager)
114 OSL_ENSURE(_rxServiceManager.is(), "OFormsModule::getComponentFactory : invalid argument (service manager) !");
115 OSL_ENSURE(_rImplementationName.getLength(), "OFormsModule::getComponentFactory : invalid argument (implementation name) !");
117 if (!s_pImplementationNames)
119 OSL_ASSERT("OFormsModule::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 "OFormsModule::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 "OFormsModule::getComponentFactory : inconsistent state !");
130 Reference< XInterface > xReturn;
133 sal_Int32 nLen = s_pImplementationNames->getLength();
134 const ::rtl::OUString* pImplName = s_pImplementationNames->getConstArray();
135 const Sequence< ::rtl::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;
158 //.........................................................................
159 } // namespace FORMS_MODULE_NAMESPACE
160 //.........................................................................