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