Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <uifactory/uielementfactorymanager.hxx>
30 : : #include <uifactory/windowcontentfactorymanager.hxx>
31 : : #include <threadhelp/resetableguard.hxx>
32 : : #include "services.h"
33 : :
34 : : #include "helper/mischelper.hxx"
35 : :
36 : : #include <com/sun/star/beans/PropertyValue.hpp>
37 : : #include <com/sun/star/beans/XPropertySet.hpp>
38 : : #include <com/sun/star/container/XNameAccess.hpp>
39 : : #include <com/sun/star/container/XNameContainer.hpp>
40 : : #include <com/sun/star/container/XContainer.hpp>
41 : : #include <com/sun/star/frame/XFrame.hpp>
42 : :
43 : : #include <rtl/ustrbuf.hxx>
44 : : #include <cppuhelper/weak.hxx>
45 : : #include <vcl/svapp.hxx>
46 : : #include <rtl/logfile.hxx>
47 : :
48 : : //_________________________________________________________________________________________________________________
49 : : // Defines
50 : : //_________________________________________________________________________________________________________________
51 : :
52 : : using namespace com::sun::star::uno;
53 : : using namespace com::sun::star::lang;
54 : : using namespace com::sun::star::beans;
55 : : using namespace com::sun::star::frame;
56 : : using namespace com::sun::star::container;
57 : : using namespace ::com::sun::star::ui;
58 : : using namespace ::com::sun::star::frame;
59 : :
60 : : //_________________________________________________________________________________________________________________
61 : : // Namespace
62 : : //_________________________________________________________________________________________________________________
63 : :
64 : : namespace framework
65 : : {
66 : :
67 : : // global function needed by both implementations
68 : 22080 : rtl::OUString getHashKeyFromStrings( const rtl::OUString& aType, const rtl::OUString& aName, const rtl::OUString& aModuleName )
69 : : {
70 [ + - ]: 22080 : rtl::OUStringBuffer aKey( aType );
71 [ + - ]: 22080 : aKey.appendAscii( "^" );
72 [ + - ]: 22080 : aKey.append( aName );
73 [ + - ]: 22080 : aKey.appendAscii( "^" );
74 [ + - ]: 22080 : aKey.append( aModuleName );
75 [ + - ]: 22080 : return aKey.makeStringAndClear();
76 : : }
77 : :
78 : :
79 : : //*****************************************************************************************************************
80 : : // Configuration access class for UIElementFactoryManager implementation
81 : : //*****************************************************************************************************************
82 : :
83 : :
84 : 113 : ConfigurationAccess_FactoryManager::ConfigurationAccess_FactoryManager( Reference< XMultiServiceFactory >& rServiceManager,const ::rtl::OUString& _sRoot ) :
85 : : ThreadHelpBase(),
86 : : m_aPropType( RTL_CONSTASCII_USTRINGPARAM( "Type" )),
87 : : m_aPropName( RTL_CONSTASCII_USTRINGPARAM( "Name" )),
88 : : m_aPropModule( RTL_CONSTASCII_USTRINGPARAM( "Module" )),
89 : : m_aPropFactory( RTL_CONSTASCII_USTRINGPARAM( "FactoryImplementation" )),
90 : : m_sRoot(_sRoot),
91 : : m_xServiceManager( rServiceManager ),
92 [ + - ][ + - ]: 113 : m_bConfigAccessInitialized( sal_False )
[ + - ][ + - ]
[ + - ][ + - ]
93 : : {
94 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::ConfigurationAccess_FactoryManager" );
95 [ + - ][ + - ]: 113 : m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance( SERVICENAME_CFGPROVIDER),UNO_QUERY );
[ + - ][ + - ]
[ + - ]
96 : 113 : }
97 : :
98 [ + - ][ + - ]: 103 : ConfigurationAccess_FactoryManager::~ConfigurationAccess_FactoryManager()
99 : : {
100 : : // SAFE
101 [ + - ]: 103 : ResetableGuard aLock( m_aLock );
102 : :
103 [ + - ]: 103 : Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
104 [ + + ]: 103 : if ( xContainer.is() )
105 [ + - ][ + - ]: 103 : xContainer->removeContainerListener(m_xConfigListener);
[ + - ]
106 [ - + ]: 206 : }
107 : :
108 : 7195 : rtl::OUString ConfigurationAccess_FactoryManager::getFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule ) const
109 : : {
110 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactorySpecifierFromTypeNameModule" );
111 : : // SAFE
112 [ + - ]: 7195 : ResetableGuard aLock( m_aLock );
113 : :
114 : : FactoryManagerMap::const_iterator pIter =
115 [ + - ][ + - ]: 7195 : m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rModule ));
116 [ + + ][ + - ]: 7195 : if ( pIter != m_aFactoryManagerMap.end() )
117 [ + - ]: 32 : return pIter->second;
118 : : else
119 : : {
120 [ + - ][ + - ]: 7163 : pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rtl::OUString() ));
121 [ - + ][ + - ]: 7163 : if ( pIter != m_aFactoryManagerMap.end() )
122 [ # # ]: 0 : return pIter->second;
123 : : else
124 : : {
125 : : // Support factories which uses a defined prefix before the ui name.
126 : 7163 : sal_Int32 nIndex = rName.indexOf( '_' );
127 [ - + ]: 7163 : if ( nIndex > 0 )
128 : : {
129 : 0 : rtl::OUString aName = rName.copy( 0, nIndex+1 );
130 [ # # ][ # # ]: 0 : pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, aName, rtl::OUString() ));
131 [ # # ][ # # ]: 0 : if ( pIter != m_aFactoryManagerMap.end() )
132 [ # # ][ # # ]: 0 : return pIter->second;
133 : : }
134 : :
135 [ + - ][ + - ]: 7163 : pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rtl::OUString(), rtl::OUString() ));
136 [ + - ][ + - ]: 7163 : if ( pIter != m_aFactoryManagerMap.end() )
137 [ + - ]: 7163 : return pIter->second;
138 : : }
139 : : }
140 : :
141 [ + - ]: 7195 : return rtl::OUString();
142 : : }
143 : :
144 : 2 : void ConfigurationAccess_FactoryManager::addFactorySpecifierToTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule, const rtl::OUString& rServiceSpecifier )
145 : : {
146 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::addFactorySpecifierToTypeNameModule" );
147 : : // SAFE
148 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
149 : :
150 [ + - ]: 2 : rtl::OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
151 : :
152 [ + - ]: 2 : FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
153 : :
154 [ - + ][ + - ]: 2 : if ( pIter != m_aFactoryManagerMap.end() )
155 [ # # ]: 0 : throw ElementExistException();
156 : : else
157 [ + - ][ + - ]: 2 : m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, rServiceSpecifier ));
158 : 2 : }
159 : :
160 : :
161 : 2 : void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule )
162 : : {
163 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::removeFactorySpecifierFromTypeNameModule" );
164 : : // SAFE
165 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
166 : :
167 [ + - ]: 2 : rtl::OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
168 : :
169 [ + - ]: 2 : FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
170 : :
171 [ - + ][ + - ]: 2 : if ( pIter == m_aFactoryManagerMap.end() )
172 [ # # ]: 0 : throw NoSuchElementException();
173 : : else
174 [ + - ][ + - ]: 2 : m_aFactoryManagerMap.erase( aHashKey );
175 : 2 : }
176 : :
177 : 2 : Sequence< Sequence< PropertyValue > > ConfigurationAccess_FactoryManager::getFactoriesDescription() const
178 : : {
179 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactoriesDescription" );
180 : : // SAFE
181 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
182 : :
183 [ + - ]: 2 : Sequence< Sequence< PropertyValue > > aSeqSeq;
184 : :
185 : 2 : sal_Int32 nIndex( 0 );
186 [ + - ]: 2 : FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.begin();
187 [ + - ][ + + ]: 14 : while ( pIter != m_aFactoryManagerMap.end() )
188 : : {
189 [ + - ]: 12 : rtl::OUString aFactory = pIter->first;
190 [ + - ]: 12 : if ( !aFactory.isEmpty() )
191 : : {
192 : 12 : sal_Int32 nToken = 0;
193 [ + - ]: 12 : Sequence< PropertyValue > aSeq( 1 );
194 : :
195 [ + - ]: 12 : aSeqSeq.realloc( aSeqSeq.getLength() + 1 );
196 [ + - ]: 12 : aSeq[0].Name = m_aPropType;
197 [ + - ][ + - ]: 12 : aSeq[0].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
198 [ + - ]: 12 : if ( nToken > 0 )
199 : : {
200 [ + - ]: 12 : aSeq.realloc( 2 );
201 [ + - ]: 12 : aSeq[1].Name = m_aPropName;
202 [ + - ][ + - ]: 12 : aSeq[1].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
203 [ + - ]: 12 : if ( nToken > 0 )
204 : : {
205 [ + - ]: 12 : aSeq.realloc( 3 );
206 [ + - ]: 12 : aSeq[2].Name = m_aPropModule;
207 [ + - ][ + - ]: 12 : aSeq[2].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
208 : : }
209 : : }
210 : :
211 [ + - ][ + - ]: 12 : aSeqSeq[nIndex++] = aSeq;
[ + - ]
212 : : }
213 : :
214 : 12 : ++pIter;
215 : 12 : }
216 : :
217 [ + - ]: 2 : return aSeqSeq;
218 : : }
219 : :
220 : : // container.XContainerListener
221 : 0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException)
222 : : {
223 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementInserted" );
224 : 0 : rtl::OUString aType;
225 : 0 : rtl::OUString aName;
226 : 0 : rtl::OUString aModule;
227 : 0 : rtl::OUString aService;
228 : :
229 : : // SAFE
230 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
231 : :
232 [ # # ][ # # ]: 0 : if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
233 : : {
234 : : // Create hash key from type, name and module as they are together a primary key to
235 : : // the UNO service that implements a user interface factory.
236 [ # # ]: 0 : rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
237 [ # # ]: 0 : m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
238 [ # # ]: 0 : }
239 : 0 : }
240 : :
241 : 0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException)
242 : : {
243 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementRemoved " );
244 : 0 : rtl::OUString aType;
245 : 0 : rtl::OUString aName;
246 : 0 : rtl::OUString aModule;
247 : 0 : rtl::OUString aService;
248 : :
249 : : // SAFE
250 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
251 : :
252 [ # # ][ # # ]: 0 : if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
253 : : {
254 : : // Create hash key from command and model as they are together a primary key to
255 : : // the UNO service that implements the popup menu controller.
256 [ # # ]: 0 : rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
257 [ # # ]: 0 : m_aFactoryManagerMap.erase( aHashKey );
258 [ # # ]: 0 : }
259 : 0 : }
260 : :
261 : 0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException)
262 : : {
263 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementReplaced" );
264 : 0 : rtl::OUString aType;
265 : 0 : rtl::OUString aName;
266 : 0 : rtl::OUString aModule;
267 : 0 : rtl::OUString aService;
268 : :
269 : : // SAFE
270 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
271 : :
272 [ # # ][ # # ]: 0 : if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
273 : : {
274 : : // Create hash key from command and model as they are together a primary key to
275 : : // the UNO service that implements the popup menu controller.
276 [ # # ]: 0 : rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
277 [ # # ]: 0 : m_aFactoryManagerMap.erase( aHashKey );
278 [ # # ]: 0 : m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
279 [ # # ]: 0 : }
280 : 0 : }
281 : :
282 : : // lang.XEventListener
283 : 0 : void SAL_CALL ConfigurationAccess_FactoryManager::disposing( const EventObject& ) throw(RuntimeException)
284 : : {
285 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::disposing" );
286 : : // SAFE
287 : : // remove our reference to the config access
288 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
289 [ # # ]: 0 : m_xConfigAccess.clear();
290 : 0 : }
291 : :
292 : 111 : void ConfigurationAccess_FactoryManager::readConfigurationData()
293 : : {
294 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::readConfigurationData" );
295 : : // SAFE
296 [ + - ]: 111 : ResetableGuard aLock( m_aLock );
297 : :
298 [ + - ]: 111 : if ( !m_bConfigAccessInitialized )
299 : : {
300 [ + - ]: 111 : Sequence< Any > aArgs( 1 );
301 : 111 : PropertyValue aPropValue;
302 : :
303 [ + - ]: 111 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
304 [ + - ]: 111 : aPropValue.Value <<= m_sRoot;
305 [ + - ][ + - ]: 111 : aArgs[0] <<= aPropValue;
306 : :
307 : : try
308 : : {
309 [ + - ][ + - ]: 111 : m_xConfigAccess.set( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ), UNO_QUERY );
[ + - ][ + - ]
[ # # ]
310 : : }
311 [ # # ]: 0 : catch ( const WrappedTargetException& )
312 : : {
313 : : }
314 : :
315 [ + - ]: 111 : m_bConfigAccessInitialized = sal_True;
316 : : }
317 : :
318 [ + - ]: 111 : if ( m_xConfigAccess.is() )
319 : : {
320 [ + - ][ + - ]: 111 : Sequence< rtl::OUString > aUIElementFactories = m_xConfigAccess->getElementNames();
321 : :
322 : 111 : rtl::OUString aType;
323 : 111 : rtl::OUString aName;
324 : 111 : rtl::OUString aModule;
325 : 111 : rtl::OUString aService;
326 : 111 : rtl::OUString aHashKey;
327 : 111 : Reference< XPropertySet > xPropertySet;
328 [ + + ]: 666 : for ( sal_Int32 i = 0; i < aUIElementFactories.getLength(); i++ )
329 : : {
330 [ + - ][ + - ]: 555 : if ( impl_getElementProps( m_xConfigAccess->getByName( aUIElementFactories[i] ), aType, aName, aModule, aService ))
[ + - ][ + - ]
[ + - ]
331 : : {
332 : : // Create hash key from type, name and module as they are together a primary key to
333 : : // the UNO service that implements the user interface element factory.
334 [ + - ]: 555 : aHashKey = getHashKeyFromStrings( aType, aName, aModule );
335 [ + - ]: 555 : m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
336 : : }
337 : : }
338 : :
339 [ + - ]: 111 : Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
340 [ + - ]: 111 : aLock.unlock();
341 : : // UNSAFE
342 [ + - ]: 111 : if ( xContainer.is() )
343 : : {
344 [ + - ][ + - ]: 111 : m_xConfigListener = new WeakContainerListener(this);
[ + - ][ + - ]
345 [ + - ][ + - ]: 111 : xContainer->addContainerListener(m_xConfigListener);
346 [ + - ]: 111 : }
347 [ + - ]: 111 : }
348 : 111 : }
349 : :
350 : 555 : sal_Bool ConfigurationAccess_FactoryManager::impl_getElementProps( const Any& aElement, rtl::OUString& rType, rtl::OUString& rName, rtl::OUString& rModule, rtl::OUString& rServiceSpecifier ) const
351 : : {
352 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::impl_getElementProps" );
353 : 555 : Reference< XPropertySet > xPropertySet;
354 [ + - ]: 555 : aElement >>= xPropertySet;
355 : :
356 [ + - ]: 555 : if ( xPropertySet.is() )
357 : : {
358 : : try
359 : : {
360 [ + - ][ + - ]: 555 : xPropertySet->getPropertyValue( m_aPropType ) >>= rType;
361 [ + - ][ + - ]: 555 : xPropertySet->getPropertyValue( m_aPropName ) >>= rName;
362 [ + - ][ + - ]: 555 : xPropertySet->getPropertyValue( m_aPropModule ) >>= rModule;
363 [ + - ][ + - ]: 555 : xPropertySet->getPropertyValue( m_aPropFactory ) >>= rServiceSpecifier;
364 : : }
365 [ # # ]: 0 : catch ( const com::sun::star::beans::UnknownPropertyException& )
366 : : {
367 : 0 : return sal_False;
368 : : }
369 [ # # ]: 0 : catch ( const com::sun::star::lang::WrappedTargetException& )
370 : : {
371 : 0 : return sal_False;
372 : : }
373 : : }
374 : :
375 [ # # # ]: 555 : return sal_True;
376 : : }
377 : :
378 : : //*****************************************************************************************************************
379 : : // XInterface, XTypeProvider, XServiceInfo
380 : : //*****************************************************************************************************************
381 [ + - ][ + - ]: 2991 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( UIElementFactoryManager ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ]
382 : : ::cppu::OWeakObject ,
383 : : SERVICENAME_UIELEMENTFACTORYMANAGER ,
384 : : IMPLEMENTATIONNAME_UIELEMENTFACTORYMANAGER
385 : : )
386 : :
387 : 113 : DEFINE_INIT_SERVICE ( UIElementFactoryManager, {} )
388 : :
389 : 113 : UIElementFactoryManager::UIElementFactoryManager( const Reference< XMultiServiceFactory >& xServiceManager ) :
390 : 113 : ThreadHelpBase( &Application::GetSolarMutex() ),
391 : : m_bConfigRead( sal_False ),
392 [ + - ]: 113 : m_xServiceManager( xServiceManager )
393 : : {
394 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::UIElementFactoryManager" );
395 [ + - ][ + - ]: 113 : m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories" )) );
396 : 113 : m_pConfigAccess->acquire();
397 [ + - ][ + - ]: 113 : m_xModuleManager = Reference< XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY );
[ + - ][ + - ]
[ + - ]
398 : 113 : }
399 : :
400 [ + - ]: 103 : UIElementFactoryManager::~UIElementFactoryManager()
401 : : {
402 [ + - ]: 103 : ResetableGuard aLock( m_aLock );
403 : :
404 : : // reduce reference count
405 [ + - ]: 103 : m_pConfigAccess->release();
406 [ - + ]: 206 : }
407 : :
408 : : // XUIElementFactory
409 : 7193 : Reference< XUIElement > SAL_CALL UIElementFactoryManager::createUIElement(
410 : : const ::rtl::OUString& ResourceURL,
411 : : const Sequence< PropertyValue >& Args )
412 : : throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
413 : : {
414 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::createUIElement" );
415 : : // SAFE
416 [ + - ]: 7193 : ResetableGuard aLock( m_aLock );
417 : :
418 [ + + ]: 7193 : if ( !m_bConfigRead )
419 : : {
420 : 111 : m_bConfigRead = sal_True;
421 [ + - ]: 111 : m_pConfigAccess->readConfigurationData();
422 : : }
423 : :
424 [ + - ]: 7193 : const rtl::OUString aPropFrame( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
425 : :
426 : 7193 : rtl::OUString aModuleId;
427 : 7193 : PropertyValue aPropValue;
428 : 7193 : Reference< XFrame > xFrame;
429 : :
430 : : // Retrieve the frame instance from the arguments to determine the module identifier. This must be provided
431 : : // to the search function. An empty module identifier is provided if the frame is missing or the module id cannot
432 : : // retrieve from it.
433 [ + + ]: 21575 : for ( int i = 0; i < Args.getLength(); i++ )
434 : : {
435 [ + + ]: 14382 : if ( Args[i].Name.equals( aPropFrame ))
436 [ + - ]: 7191 : Args[i].Value >>= xFrame;
437 : : }
438 : :
439 : 7193 : Reference< XModuleManager > xManager( m_xModuleManager );
440 [ + - ]: 7193 : aLock.unlock();
441 : :
442 : : // Determine the module identifier
443 : : try
444 : : {
445 [ + + ][ + - ]: 7193 : if ( xFrame.is() && xManager.is() )
[ + + ]
446 [ + - ][ + - ]: 7191 : aModuleId = xManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ) );
[ + - ]
447 : :
448 [ + - ]: 7193 : Reference< XUIElementFactory > xUIElementFactory = getFactory( ResourceURL, aModuleId );
449 [ + - ]: 7193 : if ( xUIElementFactory.is() )
450 [ + - ][ + - ]: 14386 : return xUIElementFactory->createUIElement( ResourceURL, Args );
[ - + ][ # # ]
451 : : }
452 [ # # ]: 0 : catch ( const UnknownModuleException& )
453 : : {
454 : : }
455 : :
456 [ + - ][ # # ]: 7193 : throw NoSuchElementException();
457 : : }
458 : :
459 : : // XUIElementFactoryRegistration
460 : 2 : Sequence< Sequence< PropertyValue > > SAL_CALL UIElementFactoryManager::getRegisteredFactories()
461 : : throw ( RuntimeException )
462 : : {
463 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getRegisteredFactories" );
464 : : // SAFE
465 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
466 : :
467 [ - + ]: 2 : if ( !m_bConfigRead )
468 : : {
469 : 0 : m_bConfigRead = sal_True;
470 [ # # ]: 0 : m_pConfigAccess->readConfigurationData();
471 : : }
472 : :
473 [ + - ][ + - ]: 2 : return m_pConfigAccess->getFactoriesDescription();
474 : : }
475 : :
476 : 7195 : Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( const ::rtl::OUString& aResourceURL, const ::rtl::OUString& aModuleId )
477 : : throw ( RuntimeException )
478 : : {
479 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactory" );
480 [ + - ]: 7195 : ResetableGuard aLock( m_aLock );
481 : :
482 [ - + ]: 7195 : if ( !m_bConfigRead )
483 : : {
484 : 0 : m_bConfigRead = sal_True;
485 [ # # ]: 0 : m_pConfigAccess->readConfigurationData();
486 : : }
487 : :
488 : 7195 : rtl::OUString aType;
489 : 7195 : rtl::OUString aName;
490 : :
491 [ + - ]: 7195 : WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
492 : :
493 : 7195 : Reference< XMultiServiceFactory > xSManager( m_xServiceManager );
494 : :
495 [ + - ]: 7195 : rtl::OUString aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
496 : :
497 [ + - ]: 7195 : aLock.unlock();
498 [ + - ]: 7195 : if ( !aServiceSpecifier.isEmpty() )
499 [ + - ][ + - ]: 7195 : return Reference< XUIElementFactory >( xSManager->createInstance( aServiceSpecifier ), UNO_QUERY );
[ + - ]
500 : : else
501 [ + - ]: 7195 : return Reference< XUIElementFactory >();
502 : : }
503 : :
504 : 2 : void SAL_CALL UIElementFactoryManager::registerFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleId, const ::rtl::OUString& aFactoryImplementationName )
505 : : throw ( ElementExistException, RuntimeException )
506 : : {
507 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::registerFactory" );
508 : : // SAFE
509 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
510 : :
511 [ - + ]: 2 : if ( !m_bConfigRead )
512 : : {
513 : 0 : m_bConfigRead = sal_True;
514 [ # # ]: 0 : m_pConfigAccess->readConfigurationData();
515 : : }
516 : :
517 [ + - ][ + - ]: 2 : m_pConfigAccess->addFactorySpecifierToTypeNameModule( aType, aName, aModuleId, aFactoryImplementationName );
518 : : // SAFE
519 : 2 : }
520 : :
521 : 2 : void SAL_CALL UIElementFactoryManager::deregisterFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleId )
522 : : throw ( NoSuchElementException, RuntimeException )
523 : : {
524 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::deregisterFactory" );
525 : : // SAFE
526 [ + - ]: 2 : ResetableGuard aLock( m_aLock );
527 : :
528 [ - + ]: 2 : if ( !m_bConfigRead )
529 : : {
530 : 0 : m_bConfigRead = sal_True;
531 [ # # ]: 0 : m_pConfigAccess->readConfigurationData();
532 : : }
533 : :
534 [ + - ][ + - ]: 2 : m_pConfigAccess->removeFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
535 : : // SAFE
536 : 2 : }
537 : :
538 : : } // namespace framework
539 : :
540 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|