1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "services/modulemanager.hxx"
32*cdf0e10cSrcweir #include "services/frame.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir //_______________________________________________
35*cdf0e10cSrcweir // own includes
36*cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
37*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
38*cdf0e10cSrcweir #include <services.h>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //_______________________________________________
41*cdf0e10cSrcweir // interface includes
42*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/XModule.hpp>
46*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
47*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
48*cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
49*cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //_______________________________________________
52*cdf0e10cSrcweir // other includes
53*cdf0e10cSrcweir #include <rtl/logfile.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace framework
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir static const ::rtl::OUString CFGPATH_FACTORIES     = ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Office/Factories");
59*cdf0e10cSrcweir static const ::rtl::OUString MODULEPROP_IDENTIFIER = ::rtl::OUString::createFromAscii("ooSetupFactoryModuleIdentifier" );
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir /*-----------------------------------------------
62*cdf0e10cSrcweir     04.12.2003 09:32
63*cdf0e10cSrcweir -----------------------------------------------*/
64*cdf0e10cSrcweir DEFINE_XINTERFACE_7(ModuleManager                                    ,
65*cdf0e10cSrcweir                     OWeakObject                                      ,
66*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::lang::XTypeProvider       ),
67*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::lang::XServiceInfo        ),
68*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::container::XNameReplace   ),
69*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::container::XNameAccess    ),
70*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::container::XElementAccess ),
71*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::container::XContainerQuery),
72*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::frame::XModuleManager     ))
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir /*-----------------------------------------------
75*cdf0e10cSrcweir     04.12.2003 09:32
76*cdf0e10cSrcweir -----------------------------------------------*/
77*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_7(ModuleManager                  ,
78*cdf0e10cSrcweir                        css::lang::XTypeProvider       ,
79*cdf0e10cSrcweir                        css::lang::XServiceInfo        ,
80*cdf0e10cSrcweir                        css::container::XNameReplace   ,
81*cdf0e10cSrcweir                        css::container::XNameAccess    ,
82*cdf0e10cSrcweir                        css::container::XElementAccess ,
83*cdf0e10cSrcweir                        css::container::XContainerQuery,
84*cdf0e10cSrcweir                        css::frame::XModuleManager     )
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir /*-----------------------------------------------
87*cdf0e10cSrcweir     04.12.2003 09:35
88*cdf0e10cSrcweir -----------------------------------------------*/
89*cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(ModuleManager                   ,
90*cdf0e10cSrcweir                                        ::cppu::OWeakObject             ,
91*cdf0e10cSrcweir                                        SERVICENAME_MODULEMANAGER       ,
92*cdf0e10cSrcweir                                        IMPLEMENTATIONNAME_MODULEMANAGER)
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir /*-----------------------------------------------
95*cdf0e10cSrcweir     04.12.2003 09:35
96*cdf0e10cSrcweir -----------------------------------------------*/
97*cdf0e10cSrcweir DEFINE_INIT_SERVICE(
98*cdf0e10cSrcweir                     ModuleManager,
99*cdf0e10cSrcweir                     {
100*cdf0e10cSrcweir                         /*Attention
101*cdf0e10cSrcweir                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
102*cdf0e10cSrcweir                             to create a new instance of this class by our own supported service factory.
103*cdf0e10cSrcweir                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
104*cdf0e10cSrcweir                         */
105*cdf0e10cSrcweir                     }
106*cdf0e10cSrcweir                    )
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir /*-----------------------------------------------
109*cdf0e10cSrcweir     04.12.2003 09:30
110*cdf0e10cSrcweir -----------------------------------------------*/
111*cdf0e10cSrcweir ModuleManager::ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
112*cdf0e10cSrcweir     : ThreadHelpBase(     )
113*cdf0e10cSrcweir     , m_xSMGR       (xSMGR)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /*-----------------------------------------------
118*cdf0e10cSrcweir     10.12.2003 11:59
119*cdf0e10cSrcweir -----------------------------------------------*/
120*cdf0e10cSrcweir ModuleManager::~ModuleManager()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     if (m_xCFG.is())
123*cdf0e10cSrcweir         m_xCFG.clear();
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir /*-----------------------------------------------
127*cdf0e10cSrcweir     10.12.2003 11:02
128*cdf0e10cSrcweir -----------------------------------------------*/
129*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ModuleManager::identify(const css::uno::Reference< css::uno::XInterface >& xModule)
130*cdf0e10cSrcweir     throw(css::lang::IllegalArgumentException,
131*cdf0e10cSrcweir           css::frame::UnknownModuleException,
132*cdf0e10cSrcweir           css::uno::RuntimeException         )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     // valid parameter?
135*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame >      xFrame     (xModule, css::uno::UNO_QUERY);
136*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow >       xWindow    (xModule, css::uno::UNO_QUERY);
137*cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xController(xModule, css::uno::UNO_QUERY);
138*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel >      xModel     (xModule, css::uno::UNO_QUERY);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     if (
141*cdf0e10cSrcweir         (!xFrame.is()     ) &&
142*cdf0e10cSrcweir         (!xWindow.is()    ) &&
143*cdf0e10cSrcweir         (!xController.is()) &&
144*cdf0e10cSrcweir         (!xModel.is()     )
145*cdf0e10cSrcweir        )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         throw css::lang::IllegalArgumentException(
148*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("Given module is not a frame nor a window, controller or model."),
149*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this),
150*cdf0e10cSrcweir                 1);
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	if (xFrame.is())
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir 		xController = xFrame->getController();
156*cdf0e10cSrcweir         xWindow     = xFrame->getComponentWindow();
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir     if (xController.is())
159*cdf0e10cSrcweir         xModel = xController->getModel();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     // modules are implemented by the deepest component in hierarchy ...
162*cdf0e10cSrcweir     // Means: model -> controller -> window
163*cdf0e10cSrcweir     // No fallbacks to higher components are allowed !
164*cdf0e10cSrcweir     // Note : A frame provides access to module components only ... but it's not a module by himself.
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     ::rtl::OUString sModule;
167*cdf0e10cSrcweir     if (xModel.is())
168*cdf0e10cSrcweir         sModule = implts_identify(xModel);
169*cdf0e10cSrcweir     else
170*cdf0e10cSrcweir     if (xController.is())
171*cdf0e10cSrcweir         sModule = implts_identify(xController);
172*cdf0e10cSrcweir     else
173*cdf0e10cSrcweir     if (xWindow.is())
174*cdf0e10cSrcweir         sModule = implts_identify(xWindow);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     if (sModule.getLength() < 1)
177*cdf0e10cSrcweir         throw css::frame::UnknownModuleException(
178*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("Cant find suitable module for the given component."),
179*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     return sModule;
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir /*-----------------------------------------------
185*cdf0e10cSrcweir     08.03.2007 09:55
186*cdf0e10cSrcweir -----------------------------------------------*/
187*cdf0e10cSrcweir void SAL_CALL ModuleManager::replaceByName(const ::rtl::OUString& sName ,
188*cdf0e10cSrcweir                                            const css::uno::Any&   aValue)
189*cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException   ,
190*cdf0e10cSrcweir            css::container::NoSuchElementException,
191*cdf0e10cSrcweir            css::lang::WrappedTargetException     ,
192*cdf0e10cSrcweir            css::uno::RuntimeException            )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lProps(aValue);
195*cdf0e10cSrcweir     if (lProps.empty() )
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         throw css::lang::IllegalArgumentException(
198*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("No properties given to replace part of module."),
199*cdf0e10cSrcweir                 static_cast< css::container::XNameAccess* >(this),
200*cdf0e10cSrcweir                 2);
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     // SAFE -> ----------------------------------
204*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
205*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
206*cdf0e10cSrcweir     aReadLock.unlock();
207*cdf0e10cSrcweir     // <- SAFE ----------------------------------
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     // get access to the element
210*cdf0e10cSrcweir     // Note: Dont use impl_getConfig() method here. Because it creates a readonly access only, further
211*cdf0e10cSrcweir     // it cache it as a member of this module manager instance. If we change some props there ... but dont
212*cdf0e10cSrcweir     // flush changes (because an error occured) we will read them later. If we use a different config access
213*cdf0e10cSrcweir     // we can close it without a flush ... and our read data wont be affected .-)
214*cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface >         xCfg      = ::comphelper::ConfigurationHelper::openConfig(
215*cdf0e10cSrcweir                                                                         xSMGR,
216*cdf0e10cSrcweir                                                                         CFGPATH_FACTORIES,
217*cdf0e10cSrcweir                                                                         ::comphelper::ConfigurationHelper::E_STANDARD);
218*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess >  xModules (xCfg, css::uno::UNO_QUERY_THROW);
219*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameReplace > xModule  ;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     xModules->getByName(sName) >>= xModule;
222*cdf0e10cSrcweir     if (!xModule.is())
223*cdf0e10cSrcweir     {
224*cdf0e10cSrcweir         throw css::uno::RuntimeException(
225*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("Was not able to get write access to the requested module entry inside configuration."),
226*cdf0e10cSrcweir                 static_cast< css::container::XNameAccess* >(this));
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap::const_iterator pProp;
230*cdf0e10cSrcweir     for (  pProp  = lProps.begin();
231*cdf0e10cSrcweir            pProp != lProps.end()  ;
232*cdf0e10cSrcweir          ++pProp                  )
233*cdf0e10cSrcweir     {
234*cdf0e10cSrcweir         const ::rtl::OUString& sPropName  = pProp->first;
235*cdf0e10cSrcweir         const css::uno::Any&   aPropValue = pProp->second;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         // let "NoSuchElementException" out ! We support the same API ...
238*cdf0e10cSrcweir         // and without a flush() at the end all changed data before will be ignored !
239*cdf0e10cSrcweir         xModule->replaceByName(sPropName, aPropValue);
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     ::comphelper::ConfigurationHelper::flush(xCfg);
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir /*-----------------------------------------------
246*cdf0e10cSrcweir     10.12.2003 12:05
247*cdf0e10cSrcweir -----------------------------------------------*/
248*cdf0e10cSrcweir css::uno::Any SAL_CALL ModuleManager::getByName(const ::rtl::OUString& sName)
249*cdf0e10cSrcweir     throw(css::container::NoSuchElementException,
250*cdf0e10cSrcweir           css::lang::WrappedTargetException     ,
251*cdf0e10cSrcweir           css::uno::RuntimeException            )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     // get access to the element
254*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCFG = implts_getConfig();
255*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xModule;
256*cdf0e10cSrcweir     xCFG->getByName(sName) >>= xModule;
257*cdf0e10cSrcweir     if (!xModule.is())
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         throw css::uno::RuntimeException(
260*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("Was not able to get write access to the requested module entry inside configuration."),
261*cdf0e10cSrcweir                 static_cast< css::container::XNameAccess* >(this));
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     // convert it to seq< PropertyValue >
265*cdf0e10cSrcweir     const css::uno::Sequence< ::rtl::OUString > lPropNames = xModule->getElementNames();
266*cdf0e10cSrcweir           ::comphelper::SequenceAsHashMap       lProps     ;
267*cdf0e10cSrcweir           sal_Int32                             c          = lPropNames.getLength();
268*cdf0e10cSrcweir           sal_Int32                             i          = 0;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     lProps[MODULEPROP_IDENTIFIER] <<= sName;
271*cdf0e10cSrcweir     for (i=0; i<c; ++i)
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         const ::rtl::OUString& sPropName         = lPropNames[i];
274*cdf0e10cSrcweir                                lProps[sPropName] = xModule->getByName(sPropName);
275*cdf0e10cSrcweir     }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     return css::uno::makeAny(lProps.getAsConstPropertyValueList());
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir /*-----------------------------------------------
281*cdf0e10cSrcweir     10.12.2003 11:58
282*cdf0e10cSrcweir -----------------------------------------------*/
283*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL ModuleManager::getElementNames()
284*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCFG = implts_getConfig();
287*cdf0e10cSrcweir     return xCFG->getElementNames();
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir /*-----------------------------------------------
291*cdf0e10cSrcweir     10.12.2003 11:57
292*cdf0e10cSrcweir -----------------------------------------------*/
293*cdf0e10cSrcweir sal_Bool SAL_CALL ModuleManager::hasByName(const ::rtl::OUString& sName)
294*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCFG = implts_getConfig();
297*cdf0e10cSrcweir     return xCFG->hasByName(sName);
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir /*-----------------------------------------------
301*cdf0e10cSrcweir     10.12.2003 11:35
302*cdf0e10cSrcweir -----------------------------------------------*/
303*cdf0e10cSrcweir css::uno::Type SAL_CALL ModuleManager::getElementType()
304*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     return ::getCppuType((const css::uno::Sequence< css::beans::PropertyValue >*)0);
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir /*-----------------------------------------------
310*cdf0e10cSrcweir     10.12.2003 11:56
311*cdf0e10cSrcweir -----------------------------------------------*/
312*cdf0e10cSrcweir sal_Bool SAL_CALL ModuleManager::hasElements()
313*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCFG = implts_getConfig();
316*cdf0e10cSrcweir     return xCFG->hasElements();
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir /*-----------------------------------------------
320*cdf0e10cSrcweir     07.03.2007 12:55
321*cdf0e10cSrcweir -----------------------------------------------*/
322*cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > SAL_CALL ModuleManager::createSubSetEnumerationByQuery(const ::rtl::OUString&)
323*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir     return css::uno::Reference< css::container::XEnumeration >();
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir /*-----------------------------------------------
329*cdf0e10cSrcweir     07.03.2007 12:55
330*cdf0e10cSrcweir -----------------------------------------------*/
331*cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > SAL_CALL ModuleManager::createSubSetEnumerationByProperties(const css::uno::Sequence< css::beans::NamedValue >& lProperties)
332*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap                 lSearchProps (lProperties);
335*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString >           lModules     = getElementNames();
336*cdf0e10cSrcweir     sal_Int32                                       c            = lModules.getLength();
337*cdf0e10cSrcweir     sal_Int32                                       i            = 0;
338*cdf0e10cSrcweir     ::comphelper::SequenceAsVector< css::uno::Any > lResult      ;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     for (i=0; i<c; ++i)
341*cdf0e10cSrcweir     {
342*cdf0e10cSrcweir         try
343*cdf0e10cSrcweir         {
344*cdf0e10cSrcweir             const ::rtl::OUString&                sModule      = lModules[i];
345*cdf0e10cSrcweir                   ::comphelper::SequenceAsHashMap lModuleProps = getByName(sModule);
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir             if (lModuleProps.match(lSearchProps))
348*cdf0e10cSrcweir                 lResult.push_back(css::uno::makeAny(lModuleProps.getAsConstPropertyValueList()));
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir         catch(const css::uno::Exception&)
351*cdf0e10cSrcweir             {}
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     ::comphelper::OAnyEnumeration*                      pEnum = new ::comphelper::OAnyEnumeration(lResult.getAsConstList());
355*cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
356*cdf0e10cSrcweir     return xEnum;
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir /*-----------------------------------------------
360*cdf0e10cSrcweir     14.12.2003 09:45
361*cdf0e10cSrcweir -----------------------------------------------*/
362*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > ModuleManager::implts_getConfig()
363*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir     // SAFE -> ----------------------------------
366*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
367*cdf0e10cSrcweir     if (m_xCFG.is())
368*cdf0e10cSrcweir         return m_xCFG;
369*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
370*cdf0e10cSrcweir     aReadLock.unlock();
371*cdf0e10cSrcweir     // <- SAFE ----------------------------------
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xCfg;
374*cdf0e10cSrcweir     try
375*cdf0e10cSrcweir     {
376*cdf0e10cSrcweir         xCfg = ::comphelper::ConfigurationHelper::openConfig(
377*cdf0e10cSrcweir                     xSMGR,
378*cdf0e10cSrcweir                     CFGPATH_FACTORIES,
379*cdf0e10cSrcweir                     ::comphelper::ConfigurationHelper::E_READONLY);
380*cdf0e10cSrcweir     }
381*cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
382*cdf0e10cSrcweir         { throw exRun; }
383*cdf0e10cSrcweir     catch(const css::uno::Exception&)
384*cdf0e10cSrcweir         { xCfg.clear(); }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     // SAFE -> ----------------------------------
387*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
388*cdf0e10cSrcweir     m_xCFG = css::uno::Reference< css::container::XNameAccess >(xCfg, css::uno::UNO_QUERY_THROW);
389*cdf0e10cSrcweir     return m_xCFG;
390*cdf0e10cSrcweir     // <- SAFE ----------------------------------
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir /*-----------------------------------------------
394*cdf0e10cSrcweir     30.01.2004 07:54
395*cdf0e10cSrcweir -----------------------------------------------*/
396*cdf0e10cSrcweir ::rtl::OUString ModuleManager::implts_identify(const css::uno::Reference< css::uno::XInterface >& xComponent)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     // Search for an optional (!) interface XModule first.
399*cdf0e10cSrcweir     // Its used to overrule an existing service name. Used e.g. by our database form designer
400*cdf0e10cSrcweir     // which uses a writer module internaly.
401*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModule > xModule(xComponent, css::uno::UNO_QUERY);
402*cdf0e10cSrcweir     if (xModule.is())
403*cdf0e10cSrcweir         return xModule->getIdentifier();
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     // detect modules in a generic way ...
406*cdf0e10cSrcweir     // comparing service names with configured entries ...
407*cdf0e10cSrcweir     css::uno::Reference< css::lang::XServiceInfo > xInfo(xComponent, css::uno::UNO_QUERY);
408*cdf0e10cSrcweir     if (!xInfo.is())
409*cdf0e10cSrcweir         return ::rtl::OUString();
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     const css::uno::Sequence< ::rtl::OUString > lKnownModules = getElementNames();
412*cdf0e10cSrcweir     const ::rtl::OUString*                      pKnownModules = lKnownModules.getConstArray();
413*cdf0e10cSrcweir           sal_Int32                             c             = lKnownModules.getLength();
414*cdf0e10cSrcweir           sal_Int32                             i             = 0;
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     for (i=0; i<c; ++i)
417*cdf0e10cSrcweir     {
418*cdf0e10cSrcweir         if (xInfo->supportsService(pKnownModules[i]))
419*cdf0e10cSrcweir             return pKnownModules[i];
420*cdf0e10cSrcweir     }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir     return ::rtl::OUString();
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir } // namespace framework
426