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