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_stoc.hxx" 30*cdf0e10cSrcweir #include <osl/mutex.hxx> 31*cdf0e10cSrcweir #include <osl/diagnose.h> 32*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <hash_map> 35*cdf0e10cSrcweir #include <hash_set> 36*cdf0e10cSrcweir #include <list> 37*cdf0e10cSrcweir #include <uno/mapping.hxx> 38*cdf0e10cSrcweir #include <uno/dispatcher.h> 39*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 40*cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/component.hxx> 42*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 43*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE1_HXX 44*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 47*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ 48*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 49*cdf0e10cSrcweir #endif 50*cdf0e10cSrcweir #include <rtl/unload.h> 51*cdf0e10cSrcweir #include <cppuhelper/component_context.hxx> 52*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 53*cdf0e10cSrcweir #include <cppuhelper/compbase8.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/container/XElementAccess.hpp> 70*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 71*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp> 72*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 73*cdf0e10cSrcweir #include <com/sun/star/uno/XUnloadingPreference.hpp> 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir #include <bootstrapservices.hxx> 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir using namespace com::sun::star; 81*cdf0e10cSrcweir using namespace com::sun::star::uno; 82*cdf0e10cSrcweir using namespace com::sun::star::beans; 83*cdf0e10cSrcweir using namespace com::sun::star::registry; 84*cdf0e10cSrcweir using namespace com::sun::star::lang; 85*cdf0e10cSrcweir using namespace com::sun::star::container; 86*cdf0e10cSrcweir using namespace cppu; 87*cdf0e10cSrcweir using namespace osl; 88*cdf0e10cSrcweir using namespace rtl; 89*cdf0e10cSrcweir using namespace std; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir namespace stoc_bootstrap 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir Sequence< OUString > smgr_wrapper_getSupportedServiceNames() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir static Sequence < OUString > *pNames = 0; 98*cdf0e10cSrcweir if( ! pNames ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 101*cdf0e10cSrcweir if( !pNames ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir static Sequence< OUString > seqNames(1); 104*cdf0e10cSrcweir seqNames.getArray()[0] = OUString( 105*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory") ); 106*cdf0e10cSrcweir pNames = &seqNames; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir return *pNames; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir OUString smgr_wrapper_getImplementationName() 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir static OUString *pImplName = 0; 115*cdf0e10cSrcweir if( ! pImplName ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 118*cdf0e10cSrcweir if( ! pImplName ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir static OUString implName( 121*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.OServiceManagerWrapper" ) ); 122*cdf0e10cSrcweir pImplName = &implName; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir return *pImplName; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir Sequence< OUString > smgr_getSupportedServiceNames() 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir static Sequence < OUString > *pNames = 0; 131*cdf0e10cSrcweir if( ! pNames ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 134*cdf0e10cSrcweir if( !pNames ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir static Sequence< OUString > seqNames(2); 137*cdf0e10cSrcweir seqNames.getArray()[0] = OUString( 138*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory") ); 139*cdf0e10cSrcweir seqNames.getArray()[1] = OUString( 140*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.ServiceManager") ); 141*cdf0e10cSrcweir pNames = &seqNames; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir return *pNames; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir OUString smgr_getImplementationName() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir static OUString *pImplName = 0; 150*cdf0e10cSrcweir if( ! pImplName ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 153*cdf0e10cSrcweir if( ! pImplName ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir static OUString implName( 156*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.OServiceManager" ) ); 157*cdf0e10cSrcweir pImplName = &implName; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir return *pImplName; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir Sequence< OUString > regsmgr_getSupportedServiceNames() 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir static Sequence < OUString > *pNames = 0; 166*cdf0e10cSrcweir if( ! pNames ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 169*cdf0e10cSrcweir if( !pNames ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir static Sequence< OUString > seqNames(2); 172*cdf0e10cSrcweir seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory")); 173*cdf0e10cSrcweir seqNames.getArray()[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.RegistryServiceManager")); 174*cdf0e10cSrcweir pNames = &seqNames; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir return *pNames; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir OUString regsmgr_getImplementationName() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir static OUString *pImplName = 0; 183*cdf0e10cSrcweir if( ! pImplName ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 186*cdf0e10cSrcweir if( ! pImplName ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir static OUString implName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.ORegistryServiceManager" ) ); 189*cdf0e10cSrcweir pImplName = &implName; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir return *pImplName; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir namespace stoc_smgr 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir static Sequence< sal_Int8 > smgr_getImplementationId() 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir static OImplementationId * s_pId = 0; 201*cdf0e10cSrcweir if (! s_pId) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 204*cdf0e10cSrcweir if (! s_pId) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir static OImplementationId s_aId; 207*cdf0e10cSrcweir s_pId = &s_aId; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir return s_pId->getImplementationId(); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir static Sequence< OUString > retrieveAsciiValueList( 215*cdf0e10cSrcweir const Reference< XSimpleRegistry > &xReg, const OUString &keyName ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir Reference< XEnumerationAccess > xAccess( xReg, UNO_QUERY ); 218*cdf0e10cSrcweir Sequence< OUString > seq; 219*cdf0e10cSrcweir if( xAccess.is() ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir Reference< XEnumeration > xEnum = xAccess->createEnumeration(); 222*cdf0e10cSrcweir while( xEnum.is() && xEnum->hasMoreElements() ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir Reference< XSimpleRegistry > xTempReg; 225*cdf0e10cSrcweir xEnum->nextElement() >>= xTempReg; 226*cdf0e10cSrcweir if( xTempReg.is() ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir Sequence< OUString > seq2 = retrieveAsciiValueList( xTempReg, keyName ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if( seq2.getLength() ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir sal_Int32 n1Len = seq.getLength(); 233*cdf0e10cSrcweir sal_Int32 n2Len = seq2.getLength(); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir seq.realloc( n1Len + n2Len ); 236*cdf0e10cSrcweir const OUString *pSource = seq2.getConstArray(); 237*cdf0e10cSrcweir OUString *pTarget = seq.getArray(); 238*cdf0e10cSrcweir for( int i = 0 ; i < n2Len ; i ++ ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir pTarget[i+n1Len] = pSource[i]; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else if( xReg.is () ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir try 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir Reference< XRegistryKey > rRootKey = xReg->getRootKey(); 251*cdf0e10cSrcweir if( rRootKey.is() ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir Reference<XRegistryKey > xKey = rRootKey->openKey(keyName); 254*cdf0e10cSrcweir if( xKey.is() ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir seq = xKey->getAsciiListValue(); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir catch( InvalidRegistryException & ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir catch (InvalidValueException &) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir return seq; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir /***************************************************************************** 271*cdf0e10cSrcweir Enumeration by ServiceName 272*cdf0e10cSrcweir *****************************************************************************/ 273*cdf0e10cSrcweir struct hashRef_Impl 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir size_t operator()(const Reference<XInterface > & rName) const 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir // query to XInterface. The cast to XInterface* must be the same for the same object 278*cdf0e10cSrcweir Reference<XInterface > x( Reference<XInterface >::query( rName ) ); 279*cdf0e10cSrcweir return (size_t)x.get(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir }; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir struct equaltoRef_Impl 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir size_t operator()(const Reference<XInterface > & rName1, const Reference<XInterface > & rName2 ) const 286*cdf0e10cSrcweir { return rName1 == rName2; } 287*cdf0e10cSrcweir }; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir typedef hash_set 290*cdf0e10cSrcweir < 291*cdf0e10cSrcweir Reference<XInterface >, 292*cdf0e10cSrcweir hashRef_Impl, 293*cdf0e10cSrcweir equaltoRef_Impl 294*cdf0e10cSrcweir > HashSet_Ref; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir class ServiceEnumeration_Impl : public WeakImplHelper1< XEnumeration > 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir public: 300*cdf0e10cSrcweir ServiceEnumeration_Impl( const Sequence< Reference<XInterface > > & rFactories ) 301*cdf0e10cSrcweir : aFactories( rFactories ) 302*cdf0e10cSrcweir , nIt( 0 ) 303*cdf0e10cSrcweir { g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); } 304*cdf0e10cSrcweir virtual ~ServiceEnumeration_Impl() 305*cdf0e10cSrcweir { g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // XEnumeration 308*cdf0e10cSrcweir sal_Bool SAL_CALL hasMoreElements() 309*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 310*cdf0e10cSrcweir Any SAL_CALL nextElement() 311*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 312*cdf0e10cSrcweir private: 313*cdf0e10cSrcweir Mutex aMutex; 314*cdf0e10cSrcweir Sequence< Reference<XInterface > > aFactories; 315*cdf0e10cSrcweir sal_Int32 nIt; 316*cdf0e10cSrcweir }; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // XEnumeration 319*cdf0e10cSrcweir sal_Bool ServiceEnumeration_Impl::hasMoreElements() throw(::com::sun::star::uno::RuntimeException) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir MutexGuard aGuard( aMutex ); 322*cdf0e10cSrcweir return nIt != aFactories.getLength(); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // XEnumeration 326*cdf0e10cSrcweir Any ServiceEnumeration_Impl::nextElement() 327*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir MutexGuard aGuard( aMutex ); 330*cdf0e10cSrcweir if( nIt == aFactories.getLength() ) 331*cdf0e10cSrcweir throw NoSuchElementException(); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir return Any( &aFactories.getConstArray()[nIt++], ::getCppuType( (const Reference<XInterface > *)0 ) ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir //================================================================================================== 337*cdf0e10cSrcweir class PropertySetInfo_Impl : public WeakImplHelper1< beans::XPropertySetInfo > 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir Sequence< beans::Property > m_properties; 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir public: 342*cdf0e10cSrcweir inline PropertySetInfo_Impl( Sequence< beans::Property > const & properties ) SAL_THROW( () ) 343*cdf0e10cSrcweir : m_properties( properties ) 344*cdf0e10cSrcweir {} 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir // XPropertySetInfo impl 347*cdf0e10cSrcweir virtual Sequence< beans::Property > SAL_CALL getProperties() 348*cdf0e10cSrcweir throw (RuntimeException); 349*cdf0e10cSrcweir virtual beans::Property SAL_CALL getPropertyByName( OUString const & name ) 350*cdf0e10cSrcweir throw (beans::UnknownPropertyException, RuntimeException); 351*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasPropertyByName( OUString const & name ) 352*cdf0e10cSrcweir throw (RuntimeException); 353*cdf0e10cSrcweir }; 354*cdf0e10cSrcweir //__________________________________________________________________________________________________ 355*cdf0e10cSrcweir Sequence< beans::Property > PropertySetInfo_Impl::getProperties() 356*cdf0e10cSrcweir throw (RuntimeException) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir return m_properties; 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir //__________________________________________________________________________________________________ 361*cdf0e10cSrcweir beans::Property PropertySetInfo_Impl::getPropertyByName( OUString const & name ) 362*cdf0e10cSrcweir throw (beans::UnknownPropertyException, RuntimeException) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir beans::Property const * p = m_properties.getConstArray(); 365*cdf0e10cSrcweir for ( sal_Int32 nPos = m_properties.getLength(); nPos--; ) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir if (p[ nPos ].Name.equals( name )) 368*cdf0e10cSrcweir return p[ nPos ]; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir throw beans::UnknownPropertyException( 371*cdf0e10cSrcweir OUSTR("unknown property: ") + name, Reference< XInterface >() ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir //__________________________________________________________________________________________________ 374*cdf0e10cSrcweir sal_Bool PropertySetInfo_Impl::hasPropertyByName( OUString const & name ) 375*cdf0e10cSrcweir throw (RuntimeException) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir beans::Property const * p = m_properties.getConstArray(); 378*cdf0e10cSrcweir for ( sal_Int32 nPos = m_properties.getLength(); nPos--; ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir if (p[ nPos ].Name.equals( name )) 381*cdf0e10cSrcweir return sal_True; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir return sal_False; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir /***************************************************************************** 388*cdf0e10cSrcweir Enumeration by implementation 389*cdf0e10cSrcweir *****************************************************************************/ 390*cdf0e10cSrcweir class ImplementationEnumeration_Impl : public WeakImplHelper1< XEnumeration > 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir public: 393*cdf0e10cSrcweir ImplementationEnumeration_Impl( const HashSet_Ref & rImplementationMap ) 394*cdf0e10cSrcweir : aImplementationMap( rImplementationMap ) 395*cdf0e10cSrcweir , aIt( aImplementationMap.begin() ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir virtual ~ImplementationEnumeration_Impl(); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // XEnumeration 402*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasMoreElements() 403*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 404*cdf0e10cSrcweir virtual Any SAL_CALL nextElement() 405*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir private: 408*cdf0e10cSrcweir Mutex aMutex; 409*cdf0e10cSrcweir HashSet_Ref aImplementationMap; 410*cdf0e10cSrcweir HashSet_Ref::iterator aIt; 411*cdf0e10cSrcweir sal_Int32 nNext; 412*cdf0e10cSrcweir Reference<XInterface > xNext; 413*cdf0e10cSrcweir }; 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir ImplementationEnumeration_Impl::~ImplementationEnumeration_Impl() 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir // XEnumeration 421*cdf0e10cSrcweir sal_Bool ImplementationEnumeration_Impl::hasMoreElements() 422*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir MutexGuard aGuard( aMutex ); 425*cdf0e10cSrcweir return aIt != aImplementationMap.end(); 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir // XEnumeration 429*cdf0e10cSrcweir Any ImplementationEnumeration_Impl::nextElement() 430*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir MutexGuard aGuard( aMutex ); 433*cdf0e10cSrcweir if( aIt == aImplementationMap.end() ) 434*cdf0e10cSrcweir throw NoSuchElementException(); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir Any ret( &(*aIt), ::getCppuType( (const Reference<XInterface > *)0 ) ); 437*cdf0e10cSrcweir ++aIt; 438*cdf0e10cSrcweir return ret; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir /***************************************************************************** 442*cdf0e10cSrcweir Hash tables 443*cdf0e10cSrcweir *****************************************************************************/ 444*cdf0e10cSrcweir struct equalOWString_Impl 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir sal_Bool operator()(const OUString & s1, const OUString & s2) const 447*cdf0e10cSrcweir { return s1 == s2; } 448*cdf0e10cSrcweir }; 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir struct hashOWString_Impl 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir size_t operator()(const OUString & rName) const 453*cdf0e10cSrcweir { return rName.hashCode(); } 454*cdf0e10cSrcweir }; 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir typedef hash_set 457*cdf0e10cSrcweir < 458*cdf0e10cSrcweir OUString, 459*cdf0e10cSrcweir hashOWString_Impl, 460*cdf0e10cSrcweir equalOWString_Impl 461*cdf0e10cSrcweir > HashSet_OWString; 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir typedef hash_multimap 464*cdf0e10cSrcweir < 465*cdf0e10cSrcweir OUString, 466*cdf0e10cSrcweir Reference<XInterface >, 467*cdf0e10cSrcweir hashOWString_Impl, 468*cdf0e10cSrcweir equalOWString_Impl 469*cdf0e10cSrcweir > HashMultimap_OWString_Interface; 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir typedef hash_map 472*cdf0e10cSrcweir < 473*cdf0e10cSrcweir OUString, 474*cdf0e10cSrcweir Reference<XInterface >, 475*cdf0e10cSrcweir hashOWString_Impl, 476*cdf0e10cSrcweir equalOWString_Impl 477*cdf0e10cSrcweir > HashMap_OWString_Interface; 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir /***************************************************************************** 480*cdf0e10cSrcweir class OServiceManager_Listener 481*cdf0e10cSrcweir *****************************************************************************/ 482*cdf0e10cSrcweir class OServiceManager_Listener : public WeakImplHelper1< XEventListener > 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir private: 485*cdf0e10cSrcweir WeakReference<XSet > xSMgr; 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir public: 488*cdf0e10cSrcweir OServiceManager_Listener( const Reference<XSet > & rSMgr ) 489*cdf0e10cSrcweir : xSMgr( rSMgr ) 490*cdf0e10cSrcweir {} 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir // XEventListener 493*cdf0e10cSrcweir virtual void SAL_CALL disposing(const EventObject & rEvt ) throw(::com::sun::star::uno::RuntimeException); 494*cdf0e10cSrcweir }; 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir void OServiceManager_Listener::disposing(const EventObject & rEvt ) 497*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir Reference<XSet > x( xSMgr ); 500*cdf0e10cSrcweir if( x.is() ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir try 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir x->remove( Any( &rEvt.Source, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir catch( const IllegalArgumentException & ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir OSL_ENSURE( sal_False, "IllegalArgumentException catched" ); 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir catch( const NoSuchElementException & ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir OSL_ENSURE( sal_False, "NoSuchElementException catched" ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir /***************************************************************************** 519*cdf0e10cSrcweir class OServiceManager 520*cdf0e10cSrcweir *****************************************************************************/ 521*cdf0e10cSrcweir struct OServiceManagerMutex 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir Mutex m_mutex; 524*cdf0e10cSrcweir }; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir extern "C" void SAL_CALL smgrUnloadingListener(void* id); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir typedef WeakComponentImplHelper8< 529*cdf0e10cSrcweir lang::XMultiServiceFactory, lang::XMultiComponentFactory, lang::XServiceInfo, 530*cdf0e10cSrcweir lang::XInitialization, lang::XUnoTunnel, 531*cdf0e10cSrcweir container::XSet, container::XContentEnumerationAccess, 532*cdf0e10cSrcweir beans::XPropertySet > t_OServiceManager_impl; 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir class OServiceManager 535*cdf0e10cSrcweir : public OServiceManagerMutex 536*cdf0e10cSrcweir , public t_OServiceManager_impl 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir public: 539*cdf0e10cSrcweir friend void SAL_CALL smgrUnloadingListener(void* id); 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir OServiceManager( Reference< XComponentContext > const & xContext ); 542*cdf0e10cSrcweir virtual ~OServiceManager(); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir // XUnoTunnel 545*cdf0e10cSrcweir sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id ) 546*cdf0e10cSrcweir throw (RuntimeException); 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir // XInitialization 549*cdf0e10cSrcweir void SAL_CALL initialize( Sequence< Any > const & args ) 550*cdf0e10cSrcweir throw (Exception); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir // XServiceInfo 553*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); 554*cdf0e10cSrcweir static OUString getImplementationName_Static() throw(::com::sun::star::uno::RuntimeException) 555*cdf0e10cSrcweir { return stoc_bootstrap::smgr_getImplementationName(); } 556*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(::com::sun::star::uno::RuntimeException); 557*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // XMultiComponentFactory 560*cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithContext( 561*cdf0e10cSrcweir OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext ) 562*cdf0e10cSrcweir throw (Exception, RuntimeException); 563*cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( 564*cdf0e10cSrcweir OUString const & rServiceSpecifier, 565*cdf0e10cSrcweir Sequence< Any > const & rArguments, 566*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 567*cdf0e10cSrcweir throw (Exception, RuntimeException); 568*cdf0e10cSrcweir // virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() 569*cdf0e10cSrcweir // throw (RuntimeException); 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir // XMultiServiceFactory 572*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException); 573*cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstance(const OUString &) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 574*cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString &, const Sequence<Any >& Arguments) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir // The same as the getAvailableServiceNames, but only uique names 577*cdf0e10cSrcweir Sequence< OUString > getUniqueAvailableServiceNames( 578*cdf0e10cSrcweir HashSet_OWString & aNameSet ); 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir // XElementAccess 581*cdf0e10cSrcweir virtual Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException); 582*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException); 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // XEnumerationAccess 585*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException); 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir // XSet 588*cdf0e10cSrcweir virtual sal_Bool SAL_CALL has( const Any & Element ) throw(::com::sun::star::uno::RuntimeException); 589*cdf0e10cSrcweir virtual void SAL_CALL insert( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 590*cdf0e10cSrcweir virtual void SAL_CALL remove( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir // XContentEnumerationAccess 593*cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); 594*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException); 595*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration( 596*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ) 597*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir // XComponent 600*cdf0e10cSrcweir virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // XPropertySet 603*cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() 604*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 605*cdf0e10cSrcweir void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue) 606*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 607*cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName) 608*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 609*cdf0e10cSrcweir void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) 610*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 611*cdf0e10cSrcweir void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) 612*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 613*cdf0e10cSrcweir void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) 614*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 615*cdf0e10cSrcweir void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) 616*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir protected: 619*cdf0e10cSrcweir inline bool is_disposed() const SAL_THROW( (lang::DisposedException) ); 620*cdf0e10cSrcweir inline void check_undisposed() const SAL_THROW( (lang::DisposedException) ); 621*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir sal_Bool haveFactoryWithThisImplementation(const OUString& aImplName); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir virtual Sequence< Reference< XInterface > > queryServiceFactories( 626*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ); 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir Reference< XComponentContext > m_xContext; 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > m_xPropertyInfo; 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir sal_Int32 m_nUnloadingListenerId; 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir // Does clean up when the unloading mechanism has been set off. It is called from 635*cdf0e10cSrcweir // the listener function smgrUnloadingListener. 636*cdf0e10cSrcweir void onUnloadingNotify(); 637*cdf0e10cSrcweir // factories which have been loaded and not inserted( by XSet::insert) 638*cdf0e10cSrcweir // are remembered by this set. Those factories 639*cdf0e10cSrcweir // are not released on a call to onUnloadingNotify 640*cdf0e10cSrcweir HashSet_Ref m_SetLoadedFactories; 641*cdf0e10cSrcweir private: 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir Reference<XEventListener > getFactoryListener(); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir HashMultimap_OWString_Interface m_ServiceMap; 647*cdf0e10cSrcweir HashSet_Ref m_ImplementationMap; 648*cdf0e10cSrcweir HashMap_OWString_Interface m_ImplementationNameMap; 649*cdf0e10cSrcweir Reference<XEventListener > xFactoryListener; 650*cdf0e10cSrcweir bool m_bInDisposing; 651*cdf0e10cSrcweir }; 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir //______________________________________________________________________________ 655*cdf0e10cSrcweir inline bool OServiceManager::is_disposed() const 656*cdf0e10cSrcweir SAL_THROW( (lang::DisposedException) ) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir // ought to be guarded by m_mutex: 659*cdf0e10cSrcweir return (m_bInDisposing || rBHelper.bDisposed); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir //______________________________________________________________________________ 663*cdf0e10cSrcweir inline void OServiceManager::check_undisposed() const 664*cdf0e10cSrcweir SAL_THROW( (lang::DisposedException) ) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir if (is_disposed()) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir throw lang::DisposedException( 669*cdf0e10cSrcweir OUSTR("service manager instance has already been disposed!"), 670*cdf0e10cSrcweir (OWeakObject *)this ); 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir //################################################################################################## 675*cdf0e10cSrcweir //################################################################################################## 676*cdf0e10cSrcweir //################################################################################################## 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir class OServiceManagerWrapper : public OServiceManagerMutex, public t_OServiceManager_impl 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir Reference< XComponentContext > m_xContext; 681*cdf0e10cSrcweir OServiceManager * m_root; 682*cdf0e10cSrcweir inline OServiceManager * getRoot() SAL_THROW( (RuntimeException) ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir if (! m_root) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir throw lang::DisposedException( 687*cdf0e10cSrcweir OUSTR("service manager instance has already been disposed!"), 688*cdf0e10cSrcweir Reference< XInterface >() ); 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir return m_root; 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir protected: 694*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir public: 697*cdf0e10cSrcweir OServiceManagerWrapper( 698*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 699*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ); 700*cdf0e10cSrcweir virtual ~OServiceManagerWrapper() SAL_THROW( () ); 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir // XUnoTunnel 703*cdf0e10cSrcweir sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id ) throw (RuntimeException) 704*cdf0e10cSrcweir { return getRoot()->getSomething( id ); } 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir // XInitialization 707*cdf0e10cSrcweir void SAL_CALL initialize( Sequence< Any > const & args ) throw (Exception) 708*cdf0e10cSrcweir { getRoot()->initialize( args ); } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir // XServiceInfo 711*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw (RuntimeException) 712*cdf0e10cSrcweir { return getRoot()->getImplementationName(); } 713*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (RuntimeException) 714*cdf0e10cSrcweir { return getRoot()->supportsService( ServiceName ); } 715*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException) 716*cdf0e10cSrcweir { return getRoot()->getSupportedServiceNames(); } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir // XMultiComponentFactory 719*cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithContext( 720*cdf0e10cSrcweir OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext ) 721*cdf0e10cSrcweir throw (Exception, RuntimeException) 722*cdf0e10cSrcweir { return getRoot()->createInstanceWithContext( rServiceSpecifier, xContext ); } 723*cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( 724*cdf0e10cSrcweir OUString const & rServiceSpecifier, 725*cdf0e10cSrcweir Sequence< Any > const & rArguments, 726*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 727*cdf0e10cSrcweir throw (Exception, RuntimeException) 728*cdf0e10cSrcweir { return getRoot()->createInstanceWithArgumentsAndContext( rServiceSpecifier, rArguments, xContext ); } 729*cdf0e10cSrcweir // virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() 730*cdf0e10cSrcweir // throw (RuntimeException); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir // XMultiServiceFactory 733*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException) 734*cdf0e10cSrcweir { return getRoot()->getAvailableServiceNames(); } 735*cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstance(const OUString & name) throw (Exception) 736*cdf0e10cSrcweir { return getRoot()->createInstanceWithContext( name, m_xContext ); } 737*cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString & name, const Sequence<Any >& Arguments) throw (Exception) 738*cdf0e10cSrcweir { return getRoot()->createInstanceWithArgumentsAndContext( name, Arguments, m_xContext ); } 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir // XElementAccess 741*cdf0e10cSrcweir virtual Type SAL_CALL getElementType() throw (RuntimeException) 742*cdf0e10cSrcweir { return getRoot()->getElementType(); } 743*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw (RuntimeException) 744*cdf0e10cSrcweir { return getRoot()->hasElements(); } 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir // XEnumerationAccess 747*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw (RuntimeException) 748*cdf0e10cSrcweir { return getRoot()->createEnumeration(); } 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir // XSet 751*cdf0e10cSrcweir virtual sal_Bool SAL_CALL has( const Any & Element ) throw (RuntimeException) 752*cdf0e10cSrcweir { return getRoot()->has( Element ); } 753*cdf0e10cSrcweir virtual void SAL_CALL insert( const Any & Element ) throw (lang::IllegalArgumentException, container::ElementExistException, RuntimeException) 754*cdf0e10cSrcweir { getRoot()->insert( Element ); } 755*cdf0e10cSrcweir virtual void SAL_CALL remove( const Any & Element ) throw (lang::IllegalArgumentException, container::NoSuchElementException, RuntimeException) 756*cdf0e10cSrcweir { getRoot()->remove( Element ); } 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir // XContentEnumerationAccess 759*cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); 760*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw (RuntimeException) 761*cdf0e10cSrcweir { return getRoot()->createContentEnumeration( aServiceName, m_xContext ); } 762*cdf0e10cSrcweir 763*cdf0e10cSrcweir // XPropertySet 764*cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException) 765*cdf0e10cSrcweir { return getRoot()->getPropertySetInfo(); } 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue) 768*cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException); 769*cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName) 770*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException); 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) 773*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) 774*cdf0e10cSrcweir { getRoot()->addPropertyChangeListener( PropertyName, aListener ); } 775*cdf0e10cSrcweir void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) 776*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) 777*cdf0e10cSrcweir { getRoot()->removePropertyChangeListener( PropertyName, aListener ); } 778*cdf0e10cSrcweir void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) 779*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) 780*cdf0e10cSrcweir { getRoot()->addVetoableChangeListener( PropertyName, aListener ); } 781*cdf0e10cSrcweir void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) 782*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) 783*cdf0e10cSrcweir { getRoot()->removeVetoableChangeListener( PropertyName, aListener ); } 784*cdf0e10cSrcweir }; 785*cdf0e10cSrcweir //__________________________________________________________________________________________________ 786*cdf0e10cSrcweir void SAL_CALL OServiceManagerWrapper::setPropertyValue( 787*cdf0e10cSrcweir const OUString& PropertyName, const Any& aValue ) 788*cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException, 789*cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException) 790*cdf0e10cSrcweir { 791*cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir Reference< XComponentContext > xContext; 794*cdf0e10cSrcweir if (aValue >>= xContext) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 797*cdf0e10cSrcweir m_xContext = xContext; 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir else 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir throw IllegalArgumentException( 802*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ), 803*cdf0e10cSrcweir (OWeakObject *)this, 1 ); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir else 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir getRoot()->setPropertyValue( PropertyName, aValue ); 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir //__________________________________________________________________________________________________ 812*cdf0e10cSrcweir Any SAL_CALL OServiceManagerWrapper::getPropertyValue( 813*cdf0e10cSrcweir const OUString& PropertyName ) 814*cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) 817*cdf0e10cSrcweir { 818*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 819*cdf0e10cSrcweir if( m_xContext.is() ) 820*cdf0e10cSrcweir return makeAny( m_xContext ); 821*cdf0e10cSrcweir else 822*cdf0e10cSrcweir return Any(); 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir else 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir return getRoot()->getPropertyValue( PropertyName ); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir //__________________________________________________________________________________________________ 830*cdf0e10cSrcweir void OServiceManagerWrapper::disposing() 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir m_xContext.clear(); 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir if (m_root) 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir // no m_root->dispose(), because every context disposes its service manager... 837*cdf0e10cSrcweir m_root->release(); 838*cdf0e10cSrcweir m_root = 0; 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir //__________________________________________________________________________________________________ 842*cdf0e10cSrcweir OServiceManagerWrapper::~OServiceManagerWrapper() SAL_THROW( () ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir if (m_root) 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir m_root->release(); 847*cdf0e10cSrcweir m_root = 0; 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 851*cdf0e10cSrcweir } 852*cdf0e10cSrcweir //__________________________________________________________________________________________________ 853*cdf0e10cSrcweir OServiceManagerWrapper::OServiceManagerWrapper( 854*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 855*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 856*cdf0e10cSrcweir : t_OServiceManager_impl( m_mutex ) 857*cdf0e10cSrcweir , m_xContext( xContext ) 858*cdf0e10cSrcweir , m_root( 0 ) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir Reference< XUnoTunnel > xTunnel( m_xContext->getServiceManager(), UNO_QUERY ); 863*cdf0e10cSrcweir OSL_ASSERT( xTunnel.is() ); 864*cdf0e10cSrcweir if (xTunnel.is()) 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir m_root = reinterpret_cast< OServiceManager * >( 867*cdf0e10cSrcweir xTunnel->getSomething( smgr_getImplementationId() ) ); 868*cdf0e10cSrcweir OSL_ASSERT( m_root ); 869*cdf0e10cSrcweir if (m_root) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir m_root->acquire(); 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir } 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir if (! m_root) 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir throw RuntimeException( 878*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("can only wrap OServiceManager instances!") ), 879*cdf0e10cSrcweir Reference< XInterface >() ); 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir } 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir //################################################################################################## 884*cdf0e10cSrcweir //################################################################################################## 885*cdf0e10cSrcweir //################################################################################################## 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir // XUnoTunnel 888*cdf0e10cSrcweir sal_Int64 OServiceManager::getSomething( Sequence< sal_Int8 > const & id ) 889*cdf0e10cSrcweir throw (RuntimeException) 890*cdf0e10cSrcweir { 891*cdf0e10cSrcweir check_undisposed(); 892*cdf0e10cSrcweir if (id == smgr_getImplementationId()) 893*cdf0e10cSrcweir return reinterpret_cast< sal_Int64 >(this); 894*cdf0e10cSrcweir else 895*cdf0e10cSrcweir return 0; 896*cdf0e10cSrcweir } 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir /** 899*cdf0e10cSrcweir * Create a ServiceManager 900*cdf0e10cSrcweir */ 901*cdf0e10cSrcweir OServiceManager::OServiceManager( Reference< XComponentContext > const & xContext ) 902*cdf0e10cSrcweir : t_OServiceManager_impl( m_mutex ) 903*cdf0e10cSrcweir , m_xContext( xContext ) 904*cdf0e10cSrcweir , m_bInDisposing( false ) 905*cdf0e10cSrcweir { 906*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 907*cdf0e10cSrcweir m_nUnloadingListenerId= rtl_addUnloadingListener( smgrUnloadingListener, this); 908*cdf0e10cSrcweir } 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir /** 911*cdf0e10cSrcweir * Destroy the ServiceManager 912*cdf0e10cSrcweir */ 913*cdf0e10cSrcweir OServiceManager::~OServiceManager() 914*cdf0e10cSrcweir { 915*cdf0e10cSrcweir if( m_nUnloadingListenerId != 0) 916*cdf0e10cSrcweir rtl_removeUnloadingListener( m_nUnloadingListenerId ); 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir // Removes entries in m_ServiceMap, m_ImplementationNameMap and m_ImplementationNameMap 922*cdf0e10cSrcweir // if those entries have not been inserted through XSet::insert. Therefore the entries 923*cdf0e10cSrcweir // are compared with the entries in m_SetLoadedFactories. 924*cdf0e10cSrcweir void OServiceManager::onUnloadingNotify() 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir MutexGuard aGuard( m_mutex); 927*cdf0e10cSrcweir 928*cdf0e10cSrcweir typedef HashSet_Ref::const_iterator CIT_S; 929*cdf0e10cSrcweir typedef HashMultimap_OWString_Interface::iterator IT_MM; 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir CIT_S it_SetEnd= m_SetLoadedFactories.end(); 932*cdf0e10cSrcweir IT_MM it_end1= m_ServiceMap.end(); 933*cdf0e10cSrcweir list<IT_MM> listDeleteServiceMap; 934*cdf0e10cSrcweir typedef list<IT_MM>::const_iterator CIT_DMM; 935*cdf0e10cSrcweir // find occurences in m_ServiceMap 936*cdf0e10cSrcweir for(IT_MM it_i1= m_ServiceMap.begin(); it_i1 != it_end1; it_i1++) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir if( m_SetLoadedFactories.find( it_i1->second) != it_SetEnd) 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( it_i1->second, UNO_QUERY); 941*cdf0e10cSrcweir if( xunl.is()) 942*cdf0e10cSrcweir { 943*cdf0e10cSrcweir if( xunl->releaseOnNotification()) 944*cdf0e10cSrcweir listDeleteServiceMap.push_front( it_i1); 945*cdf0e10cSrcweir } 946*cdf0e10cSrcweir else 947*cdf0e10cSrcweir listDeleteServiceMap.push_front( it_i1); 948*cdf0e10cSrcweir } 949*cdf0e10cSrcweir } 950*cdf0e10cSrcweir // delete elements from m_ServiceMap 951*cdf0e10cSrcweir CIT_DMM it_end2= listDeleteServiceMap.end(); 952*cdf0e10cSrcweir for( CIT_DMM it_i2= listDeleteServiceMap.begin(); it_i2 != it_end2; it_i2++) 953*cdf0e10cSrcweir m_ServiceMap.erase( *it_i2); 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir // find elements in m_ImplementationNameMap 956*cdf0e10cSrcweir typedef HashMap_OWString_Interface::iterator IT_M; 957*cdf0e10cSrcweir IT_M it_end3= m_ImplementationNameMap.end(); 958*cdf0e10cSrcweir list<IT_M> listDeleteImplementationNameMap; 959*cdf0e10cSrcweir typedef list<IT_M>::const_iterator CIT_DM; 960*cdf0e10cSrcweir for( IT_M it_i3= m_ImplementationNameMap.begin(); it_i3 != it_end3; it_i3++) 961*cdf0e10cSrcweir { 962*cdf0e10cSrcweir if( m_SetLoadedFactories.find( it_i3->second) != it_SetEnd) 963*cdf0e10cSrcweir { 964*cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( it_i3->second, UNO_QUERY); 965*cdf0e10cSrcweir if( xunl.is()) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir if( xunl->releaseOnNotification()) 968*cdf0e10cSrcweir listDeleteImplementationNameMap.push_front( it_i3); 969*cdf0e10cSrcweir } 970*cdf0e10cSrcweir else 971*cdf0e10cSrcweir listDeleteImplementationNameMap.push_front( it_i3); 972*cdf0e10cSrcweir } 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir // delete elements from m_ImplementationNameMap 975*cdf0e10cSrcweir CIT_DM it_end4= listDeleteImplementationNameMap.end(); 976*cdf0e10cSrcweir for( CIT_DM it_i4= listDeleteImplementationNameMap.begin(); it_i4 != it_end4; it_i4++) 977*cdf0e10cSrcweir m_ImplementationNameMap.erase( *it_i4); 978*cdf0e10cSrcweir 979*cdf0e10cSrcweir // find elements in m_ImplementationMap 980*cdf0e10cSrcweir typedef HashSet_Ref::iterator IT_S; 981*cdf0e10cSrcweir IT_S it_end5= m_ImplementationMap.end(); 982*cdf0e10cSrcweir list<IT_S> listDeleteImplementationMap; 983*cdf0e10cSrcweir typedef list<IT_S>::const_iterator CIT_DS; 984*cdf0e10cSrcweir for( IT_S it_i5= m_ImplementationMap.begin(); it_i5 != it_end5; it_i5++) 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir if( m_SetLoadedFactories.find( *it_i5) != it_SetEnd) 987*cdf0e10cSrcweir { 988*cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( *it_i5, UNO_QUERY); 989*cdf0e10cSrcweir if( xunl.is()) 990*cdf0e10cSrcweir { 991*cdf0e10cSrcweir if( xunl->releaseOnNotification()) 992*cdf0e10cSrcweir listDeleteImplementationMap.push_front( it_i5); 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir else 995*cdf0e10cSrcweir listDeleteImplementationMap.push_front( it_i5); 996*cdf0e10cSrcweir } 997*cdf0e10cSrcweir } 998*cdf0e10cSrcweir // delete elements from m_ImplementationMap 999*cdf0e10cSrcweir CIT_DS it_end6= listDeleteImplementationMap.end(); 1000*cdf0e10cSrcweir for( CIT_DS it_i6= listDeleteImplementationMap.begin(); it_i6 != it_end6; it_i6++) 1001*cdf0e10cSrcweir m_ImplementationMap.erase( *it_i6); 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir // remove Event listener before the factories are released. 1004*cdf0e10cSrcweir IT_S it_end7= m_SetLoadedFactories.end(); 1005*cdf0e10cSrcweir 1006*cdf0e10cSrcweir Reference<XEventListener> xlistener= getFactoryListener(); 1007*cdf0e10cSrcweir for( IT_S it_i7= m_SetLoadedFactories.begin(); it_i7 != it_end7; it_i7++) 1008*cdf0e10cSrcweir { 1009*cdf0e10cSrcweir Reference<XComponent> xcomp( *it_i7, UNO_QUERY); 1010*cdf0e10cSrcweir if( xcomp.is()) 1011*cdf0e10cSrcweir xcomp->removeEventListener( xlistener); 1012*cdf0e10cSrcweir } 1013*cdf0e10cSrcweir // release the factories in m_SetLoadedFactories 1014*cdf0e10cSrcweir m_SetLoadedFactories.clear(); 1015*cdf0e10cSrcweir } 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir // XComponent 1018*cdf0e10cSrcweir void OServiceManager::dispose() 1019*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1020*cdf0e10cSrcweir { 1021*cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose) 1022*cdf0e10cSrcweir return; 1023*cdf0e10cSrcweir t_OServiceManager_impl::dispose(); 1024*cdf0e10cSrcweir } 1025*cdf0e10cSrcweir 1026*cdf0e10cSrcweir void OServiceManager::disposing() 1027*cdf0e10cSrcweir { 1028*cdf0e10cSrcweir // dispose all factories 1029*cdf0e10cSrcweir HashSet_Ref aImpls; 1030*cdf0e10cSrcweir { 1031*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1032*cdf0e10cSrcweir m_bInDisposing = true; 1033*cdf0e10cSrcweir aImpls = m_ImplementationMap; 1034*cdf0e10cSrcweir } 1035*cdf0e10cSrcweir HashSet_Ref::iterator aIt = aImpls.begin(); 1036*cdf0e10cSrcweir while( aIt != aImpls.end() ) 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir try 1039*cdf0e10cSrcweir { 1040*cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( *aIt++ ) ); 1041*cdf0e10cSrcweir if( xComp.is() ) 1042*cdf0e10cSrcweir xComp->dispose(); 1043*cdf0e10cSrcweir } 1044*cdf0e10cSrcweir catch (RuntimeException & exc) 1045*cdf0e10cSrcweir { 1046*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1047*cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 1048*cdf0e10cSrcweir OSL_TRACE( "### RuntimeException occured upon disposing factory: %s", str.getStr() ); 1049*cdf0e10cSrcweir #else 1050*cdf0e10cSrcweir (void) exc; // unused 1051*cdf0e10cSrcweir #endif 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir } 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweir // dispose 1056*cdf0e10cSrcweir HashSet_Ref aImplMap; 1057*cdf0e10cSrcweir { 1058*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1059*cdf0e10cSrcweir // erase all members 1060*cdf0e10cSrcweir m_ServiceMap = HashMultimap_OWString_Interface(); 1061*cdf0e10cSrcweir aImplMap = m_ImplementationMap; 1062*cdf0e10cSrcweir m_ImplementationMap = HashSet_Ref(); 1063*cdf0e10cSrcweir m_ImplementationNameMap = HashMap_OWString_Interface(); 1064*cdf0e10cSrcweir m_SetLoadedFactories= HashSet_Ref(); 1065*cdf0e10cSrcweir } 1066*cdf0e10cSrcweir 1067*cdf0e10cSrcweir m_xContext.clear(); 1068*cdf0e10cSrcweir 1069*cdf0e10cSrcweir // not only the Event should hold the object 1070*cdf0e10cSrcweir OSL_ASSERT( m_refCount != 1 ); 1071*cdf0e10cSrcweir 1072*cdf0e10cSrcweir // Revoke this service manager as unloading listener 1073*cdf0e10cSrcweir rtl_removeUnloadingListener( m_nUnloadingListenerId); 1074*cdf0e10cSrcweir m_nUnloadingListenerId=0; 1075*cdf0e10cSrcweir } 1076*cdf0e10cSrcweir 1077*cdf0e10cSrcweir // XPropertySet 1078*cdf0e10cSrcweir Reference<XPropertySetInfo > OServiceManager::getPropertySetInfo() 1079*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1080*cdf0e10cSrcweir { 1081*cdf0e10cSrcweir check_undisposed(); 1082*cdf0e10cSrcweir if (! m_xPropertyInfo.is()) 1083*cdf0e10cSrcweir { 1084*cdf0e10cSrcweir Sequence< beans::Property > seq( 1 ); 1085*cdf0e10cSrcweir seq[ 0 ] = beans::Property( 1086*cdf0e10cSrcweir OUSTR("DefaultContext"), -1, ::getCppuType( &m_xContext ), 0 ); 1087*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) ); 1088*cdf0e10cSrcweir 1089*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1090*cdf0e10cSrcweir if (! m_xPropertyInfo.is()) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir m_xPropertyInfo = xInfo; 1093*cdf0e10cSrcweir } 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir return m_xPropertyInfo; 1096*cdf0e10cSrcweir } 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir void OServiceManager::setPropertyValue( 1099*cdf0e10cSrcweir const OUString& PropertyName, const Any& aValue ) 1100*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1101*cdf0e10cSrcweir { 1102*cdf0e10cSrcweir check_undisposed(); 1103*cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) 1104*cdf0e10cSrcweir { 1105*cdf0e10cSrcweir Reference< XComponentContext > xContext; 1106*cdf0e10cSrcweir if (aValue >>= xContext) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1109*cdf0e10cSrcweir m_xContext = xContext; 1110*cdf0e10cSrcweir } 1111*cdf0e10cSrcweir else 1112*cdf0e10cSrcweir { 1113*cdf0e10cSrcweir throw IllegalArgumentException( 1114*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ), 1115*cdf0e10cSrcweir (OWeakObject *)this, 1 ); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir } 1118*cdf0e10cSrcweir else 1119*cdf0e10cSrcweir { 1120*cdf0e10cSrcweir throw UnknownPropertyException( 1121*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property ") ) + PropertyName, 1122*cdf0e10cSrcweir (OWeakObject *)this ); 1123*cdf0e10cSrcweir } 1124*cdf0e10cSrcweir } 1125*cdf0e10cSrcweir 1126*cdf0e10cSrcweir Any OServiceManager::getPropertyValue(const OUString& PropertyName) 1127*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1128*cdf0e10cSrcweir { 1129*cdf0e10cSrcweir check_undisposed(); 1130*cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) 1131*cdf0e10cSrcweir { 1132*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1133*cdf0e10cSrcweir if( m_xContext.is() ) 1134*cdf0e10cSrcweir return makeAny( m_xContext ); 1135*cdf0e10cSrcweir else 1136*cdf0e10cSrcweir return Any(); 1137*cdf0e10cSrcweir } 1138*cdf0e10cSrcweir else 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir UnknownPropertyException except; 1141*cdf0e10cSrcweir except.Message = OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager : unknown property " ) ); 1142*cdf0e10cSrcweir except.Message += PropertyName; 1143*cdf0e10cSrcweir throw except; 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir } 1146*cdf0e10cSrcweir 1147*cdf0e10cSrcweir void OServiceManager::addPropertyChangeListener( 1148*cdf0e10cSrcweir const OUString&, const Reference<XPropertyChangeListener >&) 1149*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1150*cdf0e10cSrcweir { 1151*cdf0e10cSrcweir check_undisposed(); 1152*cdf0e10cSrcweir throw UnknownPropertyException(); 1153*cdf0e10cSrcweir } 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir void OServiceManager::removePropertyChangeListener( 1156*cdf0e10cSrcweir const OUString&, const Reference<XPropertyChangeListener >&) 1157*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1158*cdf0e10cSrcweir { 1159*cdf0e10cSrcweir check_undisposed(); 1160*cdf0e10cSrcweir throw UnknownPropertyException(); 1161*cdf0e10cSrcweir } 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir void OServiceManager::addVetoableChangeListener( 1164*cdf0e10cSrcweir const OUString&, const Reference<XVetoableChangeListener >&) 1165*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1166*cdf0e10cSrcweir { 1167*cdf0e10cSrcweir check_undisposed(); 1168*cdf0e10cSrcweir throw UnknownPropertyException(); 1169*cdf0e10cSrcweir } 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir void OServiceManager::removeVetoableChangeListener( 1172*cdf0e10cSrcweir const OUString&, const Reference<XVetoableChangeListener >&) 1173*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1174*cdf0e10cSrcweir { 1175*cdf0e10cSrcweir check_undisposed(); 1176*cdf0e10cSrcweir throw UnknownPropertyException(); 1177*cdf0e10cSrcweir } 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir // OServiceManager 1180*cdf0e10cSrcweir Reference<XEventListener > OServiceManager::getFactoryListener() 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir check_undisposed(); 1183*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1184*cdf0e10cSrcweir if( !xFactoryListener.is() ) 1185*cdf0e10cSrcweir xFactoryListener = new OServiceManager_Listener( this ); 1186*cdf0e10cSrcweir return xFactoryListener; 1187*cdf0e10cSrcweir } 1188*cdf0e10cSrcweir 1189*cdf0e10cSrcweir // XMultiServiceFactory, XContentEnumeration 1190*cdf0e10cSrcweir Sequence< OUString > OServiceManager::getUniqueAvailableServiceNames( 1191*cdf0e10cSrcweir HashSet_OWString & aNameSet ) 1192*cdf0e10cSrcweir { 1193*cdf0e10cSrcweir check_undisposed(); 1194*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1195*cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator aSIt = m_ServiceMap.begin(); 1196*cdf0e10cSrcweir while( aSIt != m_ServiceMap.end() ) 1197*cdf0e10cSrcweir aNameSet.insert( (*aSIt++).first ); 1198*cdf0e10cSrcweir 1199*cdf0e10cSrcweir /* do not return the implementation names 1200*cdf0e10cSrcweir HashMap_OWString_Interface m_ImplementationNameMap; 1201*cdf0e10cSrcweir HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.begin(); 1202*cdf0e10cSrcweir while( aIt != m_ImplementationNameMap.end() ) 1203*cdf0e10cSrcweir aNameSet.insert( (*aIt++).first ); 1204*cdf0e10cSrcweir */ 1205*cdf0e10cSrcweir 1206*cdf0e10cSrcweir Sequence< OUString > aNames( aNameSet.size() ); 1207*cdf0e10cSrcweir OUString * pArray = aNames.getArray(); 1208*cdf0e10cSrcweir sal_Int32 i = 0; 1209*cdf0e10cSrcweir HashSet_OWString::iterator next = aNameSet.begin(); 1210*cdf0e10cSrcweir while( next != aNameSet.end() ) 1211*cdf0e10cSrcweir pArray[i++] = (*next++); 1212*cdf0e10cSrcweir 1213*cdf0e10cSrcweir return aNames; 1214*cdf0e10cSrcweir } 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir // XMultiComponentFactory 1217*cdf0e10cSrcweir Reference< XInterface > OServiceManager::createInstanceWithContext( 1218*cdf0e10cSrcweir OUString const & rServiceSpecifier, 1219*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 1220*cdf0e10cSrcweir throw (Exception, RuntimeException) 1221*cdf0e10cSrcweir { 1222*cdf0e10cSrcweir check_undisposed(); 1223*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1224*cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY ); 1225*cdf0e10cSrcweir OSL_ASSERT( xProps.is() ); 1226*cdf0e10cSrcweir if (xProps.is()) 1227*cdf0e10cSrcweir { 1228*cdf0e10cSrcweir Reference< XComponentContext > xDefContext; 1229*cdf0e10cSrcweir xProps->getPropertyValue( 1230*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext; 1231*cdf0e10cSrcweir OSL_ENSURE( 1232*cdf0e10cSrcweir xContext == xDefContext, 1233*cdf0e10cSrcweir "### default context of service manager singleton differs from context holding it!" ); 1234*cdf0e10cSrcweir } 1235*cdf0e10cSrcweir #endif 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir Sequence< Reference< XInterface > > factories( 1238*cdf0e10cSrcweir queryServiceFactories( rServiceSpecifier, xContext ) ); 1239*cdf0e10cSrcweir Reference< XInterface > const * p = factories.getConstArray(); 1240*cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos ) 1241*cdf0e10cSrcweir { 1242*cdf0e10cSrcweir try 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir Reference< XInterface > const & xFactory = p[ nPos ]; 1245*cdf0e10cSrcweir if (xFactory.is()) 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY ); 1248*cdf0e10cSrcweir if (xFac.is()) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir return xFac->createInstanceWithContext( xContext ); 1251*cdf0e10cSrcweir } 1252*cdf0e10cSrcweir else 1253*cdf0e10cSrcweir { 1254*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY ); 1255*cdf0e10cSrcweir if (xFac2.is()) 1256*cdf0e10cSrcweir { 1257*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1258*cdf0e10cSrcweir OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) ); 1259*cdf0e10cSrcweir OSL_TRACE( "### ignoring given context raising service %s !!!\n", aStr.getStr() ); 1260*cdf0e10cSrcweir #endif 1261*cdf0e10cSrcweir return xFac2->createInstance(); 1262*cdf0e10cSrcweir } 1263*cdf0e10cSrcweir } 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir } 1266*cdf0e10cSrcweir catch (lang::DisposedException & exc) 1267*cdf0e10cSrcweir { 1268*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1269*cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 1270*cdf0e10cSrcweir OSL_TRACE( "### DisposedException occured: %s", str.getStr() ); 1271*cdf0e10cSrcweir #else 1272*cdf0e10cSrcweir (void) exc; // unused 1273*cdf0e10cSrcweir #endif 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir } 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir return Reference< XInterface >(); 1278*cdf0e10cSrcweir } 1279*cdf0e10cSrcweir // XMultiComponentFactory 1280*cdf0e10cSrcweir Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext( 1281*cdf0e10cSrcweir OUString const & rServiceSpecifier, 1282*cdf0e10cSrcweir Sequence< Any > const & rArguments, 1283*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 1284*cdf0e10cSrcweir throw (Exception, RuntimeException) 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir check_undisposed(); 1287*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1288*cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY ); 1289*cdf0e10cSrcweir OSL_ASSERT( xProps.is() ); 1290*cdf0e10cSrcweir if (xProps.is()) 1291*cdf0e10cSrcweir { 1292*cdf0e10cSrcweir Reference< XComponentContext > xDefContext; 1293*cdf0e10cSrcweir xProps->getPropertyValue( 1294*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext; 1295*cdf0e10cSrcweir OSL_ENSURE( 1296*cdf0e10cSrcweir xContext == xDefContext, 1297*cdf0e10cSrcweir "### default context of service manager singleton differs from context holding it!" ); 1298*cdf0e10cSrcweir } 1299*cdf0e10cSrcweir #endif 1300*cdf0e10cSrcweir 1301*cdf0e10cSrcweir Sequence< Reference< XInterface > > factories( 1302*cdf0e10cSrcweir queryServiceFactories( rServiceSpecifier, xContext ) ); 1303*cdf0e10cSrcweir Reference< XInterface > const * p = factories.getConstArray(); 1304*cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos ) 1305*cdf0e10cSrcweir { 1306*cdf0e10cSrcweir try 1307*cdf0e10cSrcweir { 1308*cdf0e10cSrcweir Reference< XInterface > const & xFactory = p[ nPos ]; 1309*cdf0e10cSrcweir if (xFactory.is()) 1310*cdf0e10cSrcweir { 1311*cdf0e10cSrcweir Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY ); 1312*cdf0e10cSrcweir if (xFac.is()) 1313*cdf0e10cSrcweir { 1314*cdf0e10cSrcweir return xFac->createInstanceWithArgumentsAndContext( rArguments, xContext ); 1315*cdf0e10cSrcweir } 1316*cdf0e10cSrcweir else 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY ); 1319*cdf0e10cSrcweir if (xFac2.is()) 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1322*cdf0e10cSrcweir OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) ); 1323*cdf0e10cSrcweir OSL_TRACE( "### ignoring given context raising service %s !!!\n", aStr.getStr() ); 1324*cdf0e10cSrcweir #endif 1325*cdf0e10cSrcweir return xFac2->createInstanceWithArguments( rArguments ); 1326*cdf0e10cSrcweir } 1327*cdf0e10cSrcweir } 1328*cdf0e10cSrcweir } 1329*cdf0e10cSrcweir } 1330*cdf0e10cSrcweir catch (lang::DisposedException & exc) 1331*cdf0e10cSrcweir { 1332*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1333*cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 1334*cdf0e10cSrcweir OSL_TRACE( "### DisposedException occured: %s", str.getStr() ); 1335*cdf0e10cSrcweir #else 1336*cdf0e10cSrcweir (void) exc; // unused 1337*cdf0e10cSrcweir #endif 1338*cdf0e10cSrcweir } 1339*cdf0e10cSrcweir } 1340*cdf0e10cSrcweir 1341*cdf0e10cSrcweir return Reference< XInterface >(); 1342*cdf0e10cSrcweir } 1343*cdf0e10cSrcweir 1344*cdf0e10cSrcweir // XMultiServiceFactory, XMultiComponentFactory, XContentEnumeration 1345*cdf0e10cSrcweir Sequence< OUString > OServiceManager::getAvailableServiceNames() 1346*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1347*cdf0e10cSrcweir { 1348*cdf0e10cSrcweir check_undisposed(); 1349*cdf0e10cSrcweir // all names 1350*cdf0e10cSrcweir HashSet_OWString aNameSet; 1351*cdf0e10cSrcweir return getUniqueAvailableServiceNames( aNameSet ); 1352*cdf0e10cSrcweir } 1353*cdf0e10cSrcweir 1354*cdf0e10cSrcweir // XMultibleServiceFactory 1355*cdf0e10cSrcweir Reference<XInterface > OServiceManager::createInstance( 1356*cdf0e10cSrcweir const OUString& rServiceSpecifier ) 1357*cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1358*cdf0e10cSrcweir { 1359*cdf0e10cSrcweir return createInstanceWithContext( 1360*cdf0e10cSrcweir rServiceSpecifier, m_xContext ); 1361*cdf0e10cSrcweir } 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir // XMultibleServiceFactory 1364*cdf0e10cSrcweir Reference<XInterface > OServiceManager::createInstanceWithArguments( 1365*cdf0e10cSrcweir const OUString& rServiceSpecifier, 1366*cdf0e10cSrcweir const Sequence<Any >& rArguments ) 1367*cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1368*cdf0e10cSrcweir { 1369*cdf0e10cSrcweir return createInstanceWithArgumentsAndContext( 1370*cdf0e10cSrcweir rServiceSpecifier, rArguments, m_xContext ); 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir // XInitialization 1374*cdf0e10cSrcweir void OServiceManager::initialize( Sequence< Any > const & ) 1375*cdf0e10cSrcweir throw (Exception) 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir check_undisposed(); 1378*cdf0e10cSrcweir OSL_ENSURE( 0, "not impl!" ); 1379*cdf0e10cSrcweir } 1380*cdf0e10cSrcweir 1381*cdf0e10cSrcweir // XServiceInfo 1382*cdf0e10cSrcweir OUString OServiceManager::getImplementationName() 1383*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1384*cdf0e10cSrcweir { 1385*cdf0e10cSrcweir check_undisposed(); 1386*cdf0e10cSrcweir return getImplementationName_Static(); 1387*cdf0e10cSrcweir } 1388*cdf0e10cSrcweir 1389*cdf0e10cSrcweir // XServiceInfo 1390*cdf0e10cSrcweir sal_Bool OServiceManager::supportsService(const OUString& ServiceName) 1391*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1392*cdf0e10cSrcweir { 1393*cdf0e10cSrcweir check_undisposed(); 1394*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 1395*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 1396*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 1397*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 1398*cdf0e10cSrcweir return sal_True; 1399*cdf0e10cSrcweir return sal_False; 1400*cdf0e10cSrcweir } 1401*cdf0e10cSrcweir 1402*cdf0e10cSrcweir // XServiceInfo 1403*cdf0e10cSrcweir Sequence< OUString > OServiceManager::getSupportedServiceNames() 1404*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1405*cdf0e10cSrcweir { 1406*cdf0e10cSrcweir check_undisposed(); 1407*cdf0e10cSrcweir return stoc_bootstrap::smgr_getSupportedServiceNames(); 1408*cdf0e10cSrcweir } 1409*cdf0e10cSrcweir 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweir Sequence< Reference< XInterface > > OServiceManager::queryServiceFactories( 1412*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & ) 1413*cdf0e10cSrcweir { 1414*cdf0e10cSrcweir Sequence< Reference< XInterface > > ret; 1415*cdf0e10cSrcweir 1416*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1417*cdf0e10cSrcweir ::std::pair< 1418*cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator, 1419*cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator> p( 1420*cdf0e10cSrcweir m_ServiceMap.equal_range( aServiceName ) ); 1421*cdf0e10cSrcweir 1422*cdf0e10cSrcweir if (p.first == p.second) // no factories 1423*cdf0e10cSrcweir { 1424*cdf0e10cSrcweir // no service found, look for an implementation 1425*cdf0e10cSrcweir HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.find( aServiceName ); 1426*cdf0e10cSrcweir if( aIt != m_ImplementationNameMap.end() ) 1427*cdf0e10cSrcweir { 1428*cdf0e10cSrcweir Reference< XInterface > const & x = aIt->second; 1429*cdf0e10cSrcweir // an implementation found 1430*cdf0e10cSrcweir ret = Sequence< Reference< XInterface > >( &x, 1 ); 1431*cdf0e10cSrcweir } 1432*cdf0e10cSrcweir } 1433*cdf0e10cSrcweir else 1434*cdf0e10cSrcweir { 1435*cdf0e10cSrcweir ::std::vector< Reference< XInterface > > vec; 1436*cdf0e10cSrcweir vec.reserve( 4 ); 1437*cdf0e10cSrcweir while (p.first != p.second) 1438*cdf0e10cSrcweir { 1439*cdf0e10cSrcweir vec.push_back( p.first->second ); 1440*cdf0e10cSrcweir ++p.first; 1441*cdf0e10cSrcweir } 1442*cdf0e10cSrcweir ret = Sequence< Reference< XInterface > >( 1443*cdf0e10cSrcweir vec.empty() ? 0 : &vec[ 0 ], vec.size() ); 1444*cdf0e10cSrcweir } 1445*cdf0e10cSrcweir 1446*cdf0e10cSrcweir return ret; 1447*cdf0e10cSrcweir } 1448*cdf0e10cSrcweir 1449*cdf0e10cSrcweir // XContentEnumerationAccess 1450*cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createContentEnumeration( 1451*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ) 1452*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1453*cdf0e10cSrcweir { 1454*cdf0e10cSrcweir check_undisposed(); 1455*cdf0e10cSrcweir Sequence< Reference< XInterface > > factories( 1456*cdf0e10cSrcweir OServiceManager::queryServiceFactories( aServiceName, xContext ) ); 1457*cdf0e10cSrcweir if (factories.getLength()) 1458*cdf0e10cSrcweir return new ServiceEnumeration_Impl( factories ); 1459*cdf0e10cSrcweir else 1460*cdf0e10cSrcweir return Reference< XEnumeration >(); 1461*cdf0e10cSrcweir } 1462*cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createContentEnumeration( 1463*cdf0e10cSrcweir const OUString& aServiceName ) 1464*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1465*cdf0e10cSrcweir { 1466*cdf0e10cSrcweir return createContentEnumeration( aServiceName, m_xContext ); 1467*cdf0e10cSrcweir } 1468*cdf0e10cSrcweir 1469*cdf0e10cSrcweir // XEnumeration 1470*cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createEnumeration() throw(::com::sun::star::uno::RuntimeException) 1471*cdf0e10cSrcweir { 1472*cdf0e10cSrcweir check_undisposed(); 1473*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1474*cdf0e10cSrcweir return new ImplementationEnumeration_Impl( m_ImplementationMap ); 1475*cdf0e10cSrcweir } 1476*cdf0e10cSrcweir 1477*cdf0e10cSrcweir // XElementAccess 1478*cdf0e10cSrcweir Type OServiceManager::getElementType() 1479*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1480*cdf0e10cSrcweir { 1481*cdf0e10cSrcweir check_undisposed(); 1482*cdf0e10cSrcweir return ::getCppuType( (const Reference< XInterface > *)0 ); 1483*cdf0e10cSrcweir } 1484*cdf0e10cSrcweir 1485*cdf0e10cSrcweir // XElementAccess 1486*cdf0e10cSrcweir sal_Bool OServiceManager::hasElements() 1487*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1488*cdf0e10cSrcweir { 1489*cdf0e10cSrcweir check_undisposed(); 1490*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1491*cdf0e10cSrcweir return !m_ImplementationMap.empty(); 1492*cdf0e10cSrcweir } 1493*cdf0e10cSrcweir 1494*cdf0e10cSrcweir // XSet 1495*cdf0e10cSrcweir sal_Bool OServiceManager::has( const Any & Element ) 1496*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1497*cdf0e10cSrcweir { 1498*cdf0e10cSrcweir check_undisposed(); 1499*cdf0e10cSrcweir if( Element.getValueTypeClass() == TypeClass_INTERFACE ) 1500*cdf0e10cSrcweir { 1501*cdf0e10cSrcweir Reference<XInterface > xEle( Element, UNO_QUERY_THROW ); 1502*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1503*cdf0e10cSrcweir return m_ImplementationMap.find( xEle ) != 1504*cdf0e10cSrcweir m_ImplementationMap.end(); 1505*cdf0e10cSrcweir } 1506*cdf0e10cSrcweir else if (Element.getValueTypeClass() == TypeClass_STRING) 1507*cdf0e10cSrcweir { 1508*cdf0e10cSrcweir OUString const & implName = 1509*cdf0e10cSrcweir *reinterpret_cast< OUString const * >(Element.getValue()); 1510*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1511*cdf0e10cSrcweir return m_ImplementationNameMap.find( implName ) != 1512*cdf0e10cSrcweir m_ImplementationNameMap.end(); 1513*cdf0e10cSrcweir } 1514*cdf0e10cSrcweir return sal_False; 1515*cdf0e10cSrcweir } 1516*cdf0e10cSrcweir 1517*cdf0e10cSrcweir // XSet 1518*cdf0e10cSrcweir void OServiceManager::insert( const Any & Element ) 1519*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException) 1520*cdf0e10cSrcweir { 1521*cdf0e10cSrcweir check_undisposed(); 1522*cdf0e10cSrcweir if( Element.getValueTypeClass() != TypeClass_INTERFACE ) 1523*cdf0e10cSrcweir { 1524*cdf0e10cSrcweir throw IllegalArgumentException( 1525*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no interface given!") ), 1526*cdf0e10cSrcweir Reference< XInterface >(), 0 ); 1527*cdf0e10cSrcweir } 1528*cdf0e10cSrcweir Reference<XInterface > xEle( Element, UNO_QUERY_THROW ); 1529*cdf0e10cSrcweir 1530*cdf0e10cSrcweir { 1531*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1532*cdf0e10cSrcweir HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle ); 1533*cdf0e10cSrcweir if( aIt != m_ImplementationMap.end() ) 1534*cdf0e10cSrcweir { 1535*cdf0e10cSrcweir throw ElementExistException( 1536*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element already exists!") ), 1537*cdf0e10cSrcweir Reference< XInterface >() ); 1538*cdf0e10cSrcweir } 1539*cdf0e10cSrcweir 1540*cdf0e10cSrcweir // put into the implementation hashmap 1541*cdf0e10cSrcweir m_ImplementationMap.insert( xEle ); 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir // put into the implementation name hashmap 1544*cdf0e10cSrcweir Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) ); 1545*cdf0e10cSrcweir if( xInfo.is() ) 1546*cdf0e10cSrcweir { 1547*cdf0e10cSrcweir OUString aImplName = xInfo->getImplementationName(); 1548*cdf0e10cSrcweir if( aImplName.getLength() ) 1549*cdf0e10cSrcweir m_ImplementationNameMap[ aImplName ] = xEle; 1550*cdf0e10cSrcweir 1551*cdf0e10cSrcweir //put into the service map 1552*cdf0e10cSrcweir Sequence< OUString > aServiceNames = xInfo->getSupportedServiceNames(); 1553*cdf0e10cSrcweir const OUString * pArray = aServiceNames.getConstArray(); 1554*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ ) 1555*cdf0e10cSrcweir { 1556*cdf0e10cSrcweir m_ServiceMap.insert( HashMultimap_OWString_Interface::value_type( 1557*cdf0e10cSrcweir pArray[i], *(Reference<XInterface > *)Element.getValue() ) ); 1558*cdf0e10cSrcweir } 1559*cdf0e10cSrcweir } 1560*cdf0e10cSrcweir } 1561*cdf0e10cSrcweir // add the disposing listener to the factory 1562*cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) ); 1563*cdf0e10cSrcweir if( xComp.is() ) 1564*cdf0e10cSrcweir xComp->addEventListener( getFactoryListener() ); 1565*cdf0e10cSrcweir } 1566*cdf0e10cSrcweir 1567*cdf0e10cSrcweir // helper function 1568*cdf0e10cSrcweir sal_Bool OServiceManager::haveFactoryWithThisImplementation(const OUString& aImplName) 1569*cdf0e10cSrcweir { 1570*cdf0e10cSrcweir return ( m_ImplementationNameMap.find(aImplName) != m_ImplementationNameMap.end()); 1571*cdf0e10cSrcweir } 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir // XSet 1574*cdf0e10cSrcweir void OServiceManager::remove( const Any & Element ) 1575*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, 1576*cdf0e10cSrcweir ::com::sun::star::container::NoSuchElementException, 1577*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 1578*cdf0e10cSrcweir { 1579*cdf0e10cSrcweir if (is_disposed()) 1580*cdf0e10cSrcweir return; 1581*cdf0e10cSrcweir 1582*cdf0e10cSrcweir Reference<XInterface > xEle; 1583*cdf0e10cSrcweir if (Element.getValueTypeClass() == TypeClass_INTERFACE) 1584*cdf0e10cSrcweir { 1585*cdf0e10cSrcweir xEle.set( Element, UNO_QUERY_THROW ); 1586*cdf0e10cSrcweir } 1587*cdf0e10cSrcweir else if (Element.getValueTypeClass() == TypeClass_STRING) 1588*cdf0e10cSrcweir { 1589*cdf0e10cSrcweir OUString const & implName = 1590*cdf0e10cSrcweir *reinterpret_cast< OUString const * >(Element.getValue()); 1591*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1592*cdf0e10cSrcweir HashMap_OWString_Interface::const_iterator const iFind( 1593*cdf0e10cSrcweir m_ImplementationNameMap.find( implName ) ); 1594*cdf0e10cSrcweir if (iFind == m_ImplementationNameMap.end()) 1595*cdf0e10cSrcweir { 1596*cdf0e10cSrcweir throw NoSuchElementException( 1597*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element is not in: ") ) 1598*cdf0e10cSrcweir + implName, static_cast< OWeakObject * >(this) ); 1599*cdf0e10cSrcweir } 1600*cdf0e10cSrcweir xEle = iFind->second; 1601*cdf0e10cSrcweir } 1602*cdf0e10cSrcweir else 1603*cdf0e10cSrcweir { 1604*cdf0e10cSrcweir throw IllegalArgumentException( 1605*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( 1606*cdf0e10cSrcweir "neither interface nor string given!") ), 1607*cdf0e10cSrcweir Reference< XInterface >(), 0 ); 1608*cdf0e10cSrcweir } 1609*cdf0e10cSrcweir 1610*cdf0e10cSrcweir // remove the disposing listener from the factory 1611*cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) ); 1612*cdf0e10cSrcweir if( xComp.is() ) 1613*cdf0e10cSrcweir xComp->removeEventListener( getFactoryListener() ); 1614*cdf0e10cSrcweir 1615*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1616*cdf0e10cSrcweir HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle ); 1617*cdf0e10cSrcweir if( aIt == m_ImplementationMap.end() ) 1618*cdf0e10cSrcweir { 1619*cdf0e10cSrcweir throw NoSuchElementException( 1620*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element is not in!") ), 1621*cdf0e10cSrcweir static_cast< OWeakObject * >(this) ); 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir //First remove all factories which have been loaded by ORegistryServiceManager. 1624*cdf0e10cSrcweir m_SetLoadedFactories.erase( *aIt); 1625*cdf0e10cSrcweir //Remove from the implementation map. It contains all factories of m_SetLoadedFactories 1626*cdf0e10cSrcweir //which have been added directly through XSet, that is not via ORegistryServiceManager 1627*cdf0e10cSrcweir m_ImplementationMap.erase( aIt ); 1628*cdf0e10cSrcweir 1629*cdf0e10cSrcweir // remove from the implementation name hashmap 1630*cdf0e10cSrcweir Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) ); 1631*cdf0e10cSrcweir if( xInfo.is() ) 1632*cdf0e10cSrcweir { 1633*cdf0e10cSrcweir OUString aImplName = xInfo->getImplementationName(); 1634*cdf0e10cSrcweir if( aImplName.getLength() ) 1635*cdf0e10cSrcweir m_ImplementationNameMap.erase( aImplName ); 1636*cdf0e10cSrcweir } 1637*cdf0e10cSrcweir 1638*cdf0e10cSrcweir //remove from the service map 1639*cdf0e10cSrcweir Reference<XServiceInfo > xSF( Reference<XServiceInfo >::query( xEle ) ); 1640*cdf0e10cSrcweir if( xSF.is() ) 1641*cdf0e10cSrcweir { 1642*cdf0e10cSrcweir Sequence< OUString > aServiceNames = xSF->getSupportedServiceNames(); 1643*cdf0e10cSrcweir const OUString * pArray = aServiceNames.getConstArray(); 1644*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ ) 1645*cdf0e10cSrcweir { 1646*cdf0e10cSrcweir pair<HashMultimap_OWString_Interface::iterator, HashMultimap_OWString_Interface::iterator> p = 1647*cdf0e10cSrcweir m_ServiceMap.equal_range( pArray[i] ); 1648*cdf0e10cSrcweir 1649*cdf0e10cSrcweir while( p.first != p.second ) 1650*cdf0e10cSrcweir { 1651*cdf0e10cSrcweir if( xEle == (*p.first).second ) 1652*cdf0e10cSrcweir { 1653*cdf0e10cSrcweir m_ServiceMap.erase( p.first ); 1654*cdf0e10cSrcweir break; 1655*cdf0e10cSrcweir } 1656*cdf0e10cSrcweir ++p.first; 1657*cdf0e10cSrcweir } 1658*cdf0e10cSrcweir } 1659*cdf0e10cSrcweir } 1660*cdf0e10cSrcweir } 1661*cdf0e10cSrcweir 1662*cdf0e10cSrcweir /***************************************************************************** 1663*cdf0e10cSrcweir class ORegistryServiceManager 1664*cdf0e10cSrcweir *****************************************************************************/ 1665*cdf0e10cSrcweir class ORegistryServiceManager : public OServiceManager 1666*cdf0e10cSrcweir { 1667*cdf0e10cSrcweir public: 1668*cdf0e10cSrcweir ORegistryServiceManager( Reference< XComponentContext > const & xContext ); 1669*cdf0e10cSrcweir virtual ~ORegistryServiceManager(); 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir // XInitialization 1672*cdf0e10cSrcweir void SAL_CALL initialize(const Sequence< Any >& Arguments) 1673*cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 1674*cdf0e10cSrcweir 1675*cdf0e10cSrcweir // XServiceInfo 1676*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException) 1677*cdf0e10cSrcweir { return stoc_bootstrap::regsmgr_getImplementationName(); } 1678*cdf0e10cSrcweir 1679*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 1680*cdf0e10cSrcweir 1681*cdf0e10cSrcweir // XMultiServiceFactory 1682*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException); 1683*cdf0e10cSrcweir 1684*cdf0e10cSrcweir // XContentEnumerationAccess 1685*cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); 1686*cdf0e10cSrcweir Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException); 1687*cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration( 1688*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ) 1689*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 1690*cdf0e10cSrcweir 1691*cdf0e10cSrcweir // XComponent 1692*cdf0e10cSrcweir void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); 1693*cdf0e10cSrcweir 1694*cdf0e10cSrcweir // OServiceManager 1695*cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() 1696*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 1697*cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName) 1698*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 1699*cdf0e10cSrcweir 1700*cdf0e10cSrcweir protected: 1701*cdf0e10cSrcweir //OServiceManager 1702*cdf0e10cSrcweir Sequence< Reference< XInterface > > queryServiceFactories( 1703*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ); 1704*cdf0e10cSrcweir private: 1705*cdf0e10cSrcweir Reference<XRegistryKey > getRootKey(); 1706*cdf0e10cSrcweir Reference<XInterface > loadWithImplementationName( 1707*cdf0e10cSrcweir const OUString & rImplName, Reference< XComponentContext > const & xContext ); 1708*cdf0e10cSrcweir Sequence<OUString> getFromServiceName(const OUString& serviceName); 1709*cdf0e10cSrcweir Reference<XInterface > loadWithServiceName( 1710*cdf0e10cSrcweir const OUString & rImplName, Reference< XComponentContext > const & xContext ); 1711*cdf0e10cSrcweir void fillAllNamesFromRegistry( HashSet_OWString & ); 1712*cdf0e10cSrcweir 1713*cdf0e10cSrcweir sal_Bool m_searchedRegistry; 1714*cdf0e10cSrcweir Reference<XSimpleRegistry > m_xRegistry; // readonly property Registry 1715*cdf0e10cSrcweir Reference<XRegistryKey > m_xRootKey; 1716*cdf0e10cSrcweir 1717*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1718*cdf0e10cSrcweir bool m_init; 1719*cdf0e10cSrcweir #endif 1720*cdf0e10cSrcweir }; 1721*cdf0e10cSrcweir 1722*cdf0e10cSrcweir /** 1723*cdf0e10cSrcweir * Create a ServiceManager 1724*cdf0e10cSrcweir */ 1725*cdf0e10cSrcweir ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > const & xContext ) 1726*cdf0e10cSrcweir : OServiceManager( xContext ) 1727*cdf0e10cSrcweir , m_searchedRegistry(sal_False) 1728*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1729*cdf0e10cSrcweir , m_init( false ) 1730*cdf0e10cSrcweir #endif 1731*cdf0e10cSrcweir { 1732*cdf0e10cSrcweir } 1733*cdf0e10cSrcweir 1734*cdf0e10cSrcweir /** 1735*cdf0e10cSrcweir * Destroy the ServiceManager 1736*cdf0e10cSrcweir */ 1737*cdf0e10cSrcweir ORegistryServiceManager::~ORegistryServiceManager() 1738*cdf0e10cSrcweir { 1739*cdf0e10cSrcweir } 1740*cdf0e10cSrcweir 1741*cdf0e10cSrcweir // XComponent 1742*cdf0e10cSrcweir void ORegistryServiceManager::dispose() 1743*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1744*cdf0e10cSrcweir { 1745*cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose) 1746*cdf0e10cSrcweir return; 1747*cdf0e10cSrcweir OServiceManager::dispose(); 1748*cdf0e10cSrcweir // dispose 1749*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1750*cdf0e10cSrcweir // erase all members 1751*cdf0e10cSrcweir m_xRegistry = Reference<XSimpleRegistry >(); 1752*cdf0e10cSrcweir m_xRootKey = Reference<XRegistryKey >(); 1753*cdf0e10cSrcweir } 1754*cdf0e10cSrcweir 1755*cdf0e10cSrcweir /** 1756*cdf0e10cSrcweir * Return the root key of the registry. The Default registry service is ordered 1757*cdf0e10cSrcweir * if no registry is set. 1758*cdf0e10cSrcweir */ 1759*cdf0e10cSrcweir //Reference<XServiceProvider > create_DefaultRegistry_ServiceProvider(); 1760*cdf0e10cSrcweir 1761*cdf0e10cSrcweir Reference<XRegistryKey > ORegistryServiceManager::getRootKey() 1762*cdf0e10cSrcweir { 1763*cdf0e10cSrcweir if( !m_xRootKey.is() ) 1764*cdf0e10cSrcweir { 1765*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1766*cdf0e10cSrcweir // DefaultRegistry suchen !!!! 1767*cdf0e10cSrcweir if( !m_xRegistry.is() && !m_searchedRegistry ) 1768*cdf0e10cSrcweir { 1769*cdf0e10cSrcweir // merken, es wird nur einmal gesucht 1770*cdf0e10cSrcweir m_searchedRegistry = sal_True; 1771*cdf0e10cSrcweir 1772*cdf0e10cSrcweir m_xRegistry.set( 1773*cdf0e10cSrcweir createInstanceWithContext( 1774*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.DefaultRegistry") ), 1775*cdf0e10cSrcweir m_xContext ), 1776*cdf0e10cSrcweir UNO_QUERY ); 1777*cdf0e10cSrcweir } 1778*cdf0e10cSrcweir if( m_xRegistry.is() && !m_xRootKey.is() ) 1779*cdf0e10cSrcweir m_xRootKey = m_xRegistry->getRootKey(); 1780*cdf0e10cSrcweir } 1781*cdf0e10cSrcweir 1782*cdf0e10cSrcweir return m_xRootKey; 1783*cdf0e10cSrcweir } 1784*cdf0e10cSrcweir 1785*cdf0e10cSrcweir /** 1786*cdf0e10cSrcweir * Create a service provider from the registry with an implementation name 1787*cdf0e10cSrcweir */ 1788*cdf0e10cSrcweir Reference<XInterface > ORegistryServiceManager::loadWithImplementationName( 1789*cdf0e10cSrcweir const OUString& name, Reference< XComponentContext > const & xContext ) 1790*cdf0e10cSrcweir { 1791*cdf0e10cSrcweir Reference<XInterface > ret; 1792*cdf0e10cSrcweir 1793*cdf0e10cSrcweir Reference<XRegistryKey > xRootKey = getRootKey(); 1794*cdf0e10cSrcweir if( !xRootKey.is() ) 1795*cdf0e10cSrcweir return ret; 1796*cdf0e10cSrcweir 1797*cdf0e10cSrcweir try 1798*cdf0e10cSrcweir { 1799*cdf0e10cSrcweir OUString implementationName = OUString( RTL_CONSTASCII_USTRINGPARAM("/IMPLEMENTATIONS/") ) + name; 1800*cdf0e10cSrcweir Reference<XRegistryKey > xImpKey = m_xRootKey->openKey(implementationName); 1801*cdf0e10cSrcweir 1802*cdf0e10cSrcweir if( xImpKey.is() ) 1803*cdf0e10cSrcweir { 1804*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMgr; 1805*cdf0e10cSrcweir if (xContext.is()) 1806*cdf0e10cSrcweir xMgr.set( xContext->getServiceManager(), UNO_QUERY_THROW ); 1807*cdf0e10cSrcweir else 1808*cdf0e10cSrcweir xMgr.set( this ); 1809*cdf0e10cSrcweir ret = createSingleRegistryFactory( xMgr, name, xImpKey ); 1810*cdf0e10cSrcweir insert( makeAny( ret ) ); 1811*cdf0e10cSrcweir // Remember this factory as loaded in contrast to inserted ( XSet::insert) 1812*cdf0e10cSrcweir // factories. Those loaded factories in this set are candidates for being 1813*cdf0e10cSrcweir // released on an unloading notification. 1814*cdf0e10cSrcweir m_SetLoadedFactories.insert( ret); 1815*cdf0e10cSrcweir } 1816*cdf0e10cSrcweir } 1817*cdf0e10cSrcweir catch (InvalidRegistryException &) 1818*cdf0e10cSrcweir { 1819*cdf0e10cSrcweir } 1820*cdf0e10cSrcweir 1821*cdf0e10cSrcweir return ret; 1822*cdf0e10cSrcweir } 1823*cdf0e10cSrcweir 1824*cdf0e10cSrcweir /** 1825*cdf0e10cSrcweir * Return all implementation out of the registry. 1826*cdf0e10cSrcweir */ 1827*cdf0e10cSrcweir Sequence<OUString> ORegistryServiceManager::getFromServiceName( 1828*cdf0e10cSrcweir const OUString& serviceName ) 1829*cdf0e10cSrcweir { 1830*cdf0e10cSrcweir OUStringBuffer buf; 1831*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "/SERVICES/" ) ); 1832*cdf0e10cSrcweir buf.append( serviceName ); 1833*cdf0e10cSrcweir return retrieveAsciiValueList( m_xRegistry, buf.makeStringAndClear() ); 1834*cdf0e10cSrcweir } 1835*cdf0e10cSrcweir 1836*cdf0e10cSrcweir /** 1837*cdf0e10cSrcweir * Create a service provider from the registry 1838*cdf0e10cSrcweir */ 1839*cdf0e10cSrcweir Reference<XInterface > ORegistryServiceManager::loadWithServiceName( 1840*cdf0e10cSrcweir const OUString& serviceName, Reference< XComponentContext > const & xContext ) 1841*cdf0e10cSrcweir { 1842*cdf0e10cSrcweir Sequence<OUString> implEntries = getFromServiceName( serviceName ); 1843*cdf0e10cSrcweir for (sal_Int32 i = 0; i < implEntries.getLength(); i++) 1844*cdf0e10cSrcweir { 1845*cdf0e10cSrcweir Reference< XInterface > x( 1846*cdf0e10cSrcweir loadWithImplementationName( implEntries.getConstArray()[i], xContext ) ); 1847*cdf0e10cSrcweir if (x.is()) 1848*cdf0e10cSrcweir return x; 1849*cdf0e10cSrcweir } 1850*cdf0e10cSrcweir 1851*cdf0e10cSrcweir return Reference<XInterface >(); 1852*cdf0e10cSrcweir } 1853*cdf0e10cSrcweir 1854*cdf0e10cSrcweir /** 1855*cdf0e10cSrcweir * Return a sequence of all service names from the registry. 1856*cdf0e10cSrcweir */ 1857*cdf0e10cSrcweir void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet ) 1858*cdf0e10cSrcweir { 1859*cdf0e10cSrcweir Reference<XRegistryKey > xRootKey = getRootKey(); 1860*cdf0e10cSrcweir if( !xRootKey.is() ) 1861*cdf0e10cSrcweir return; 1862*cdf0e10cSrcweir 1863*cdf0e10cSrcweir try 1864*cdf0e10cSrcweir { 1865*cdf0e10cSrcweir Reference<XRegistryKey > xServicesKey = xRootKey->openKey( 1866*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("SERVICES") ) ); 1867*cdf0e10cSrcweir // root + /Services + / 1868*cdf0e10cSrcweir if( xServicesKey.is() ) 1869*cdf0e10cSrcweir { 1870*cdf0e10cSrcweir sal_Int32 nPrefix = xServicesKey->getKeyName().getLength() +1; 1871*cdf0e10cSrcweir Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys(); 1872*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aKeys.getLength(); i++ ) 1873*cdf0e10cSrcweir rSet.insert( aKeys.getConstArray()[i]->getKeyName().copy( nPrefix ) ); 1874*cdf0e10cSrcweir } 1875*cdf0e10cSrcweir } 1876*cdf0e10cSrcweir catch (InvalidRegistryException &) 1877*cdf0e10cSrcweir { 1878*cdf0e10cSrcweir } 1879*cdf0e10cSrcweir } 1880*cdf0e10cSrcweir 1881*cdf0e10cSrcweir // XInitialization 1882*cdf0e10cSrcweir void ORegistryServiceManager::initialize(const Sequence< Any >& Arguments) 1883*cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1884*cdf0e10cSrcweir { 1885*cdf0e10cSrcweir check_undisposed(); 1886*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1887*cdf0e10cSrcweir if (Arguments.getLength() > 0) 1888*cdf0e10cSrcweir { 1889*cdf0e10cSrcweir m_xRootKey.clear(); 1890*cdf0e10cSrcweir Arguments[ 0 ] >>= m_xRegistry; 1891*cdf0e10cSrcweir } 1892*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1893*cdf0e10cSrcweir // to find all bootstrapping processes to be fixed... 1894*cdf0e10cSrcweir OSL_ENSURE( !m_init, "### second init of service manager instance!" ); 1895*cdf0e10cSrcweir m_init = true; 1896*cdf0e10cSrcweir #endif 1897*cdf0e10cSrcweir } 1898*cdf0e10cSrcweir 1899*cdf0e10cSrcweir // XMultiServiceFactory, XContentEnumeration 1900*cdf0e10cSrcweir Sequence< OUString > ORegistryServiceManager::getAvailableServiceNames() 1901*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1902*cdf0e10cSrcweir { 1903*cdf0e10cSrcweir check_undisposed(); 1904*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1905*cdf0e10cSrcweir // all names 1906*cdf0e10cSrcweir HashSet_OWString aNameSet; 1907*cdf0e10cSrcweir 1908*cdf0e10cSrcweir // all names from the registry 1909*cdf0e10cSrcweir fillAllNamesFromRegistry( aNameSet ); 1910*cdf0e10cSrcweir 1911*cdf0e10cSrcweir return OServiceManager::getUniqueAvailableServiceNames( aNameSet ); 1912*cdf0e10cSrcweir } 1913*cdf0e10cSrcweir 1914*cdf0e10cSrcweir // XServiceInfo 1915*cdf0e10cSrcweir Sequence< OUString > ORegistryServiceManager::getSupportedServiceNames() 1916*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1917*cdf0e10cSrcweir { 1918*cdf0e10cSrcweir check_undisposed(); 1919*cdf0e10cSrcweir return stoc_bootstrap::regsmgr_getSupportedServiceNames(); 1920*cdf0e10cSrcweir } 1921*cdf0e10cSrcweir 1922*cdf0e10cSrcweir 1923*cdf0e10cSrcweir // OServiceManager 1924*cdf0e10cSrcweir Sequence< Reference< XInterface > > ORegistryServiceManager::queryServiceFactories( 1925*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ) 1926*cdf0e10cSrcweir { 1927*cdf0e10cSrcweir Sequence< Reference< XInterface > > ret( 1928*cdf0e10cSrcweir OServiceManager::queryServiceFactories( aServiceName, xContext ) ); 1929*cdf0e10cSrcweir if (ret.getLength()) 1930*cdf0e10cSrcweir { 1931*cdf0e10cSrcweir return ret; 1932*cdf0e10cSrcweir } 1933*cdf0e10cSrcweir else 1934*cdf0e10cSrcweir { 1935*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1936*cdf0e10cSrcweir Reference< XInterface > x( loadWithServiceName( aServiceName, xContext ) ); 1937*cdf0e10cSrcweir if (! x.is()) 1938*cdf0e10cSrcweir x = loadWithImplementationName( aServiceName, xContext ); 1939*cdf0e10cSrcweir return Sequence< Reference< XInterface > >( &x, 1 ); 1940*cdf0e10cSrcweir } 1941*cdf0e10cSrcweir } 1942*cdf0e10cSrcweir 1943*cdf0e10cSrcweir // XContentEnumerationAccess 1944*cdf0e10cSrcweir Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration( 1945*cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext ) 1946*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1947*cdf0e10cSrcweir { 1948*cdf0e10cSrcweir check_undisposed(); 1949*cdf0e10cSrcweir MutexGuard aGuard( ((ORegistryServiceManager *)this)->m_mutex ); 1950*cdf0e10cSrcweir // get all implementation names registered under this service name from the registry 1951*cdf0e10cSrcweir Sequence<OUString> aImpls = ((ORegistryServiceManager *)this)->getFromServiceName( aServiceName ); 1952*cdf0e10cSrcweir // load and insert all factories specified by the registry 1953*cdf0e10cSrcweir sal_Int32 i; 1954*cdf0e10cSrcweir OUString aImplName; 1955*cdf0e10cSrcweir for( i = 0; i < aImpls.getLength(); i++ ) 1956*cdf0e10cSrcweir { 1957*cdf0e10cSrcweir aImplName = aImpls.getConstArray()[i]; 1958*cdf0e10cSrcweir if ( !haveFactoryWithThisImplementation(aImplName) ) 1959*cdf0e10cSrcweir { 1960*cdf0e10cSrcweir loadWithImplementationName( aImplName, xContext ); 1961*cdf0e10cSrcweir } 1962*cdf0e10cSrcweir } 1963*cdf0e10cSrcweir // call the superclass to enumerate all contents 1964*cdf0e10cSrcweir return OServiceManager::createContentEnumeration( aServiceName, xContext ); 1965*cdf0e10cSrcweir } 1966*cdf0e10cSrcweir Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration( 1967*cdf0e10cSrcweir const OUString& aServiceName ) 1968*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1969*cdf0e10cSrcweir { 1970*cdf0e10cSrcweir return createContentEnumeration( aServiceName, m_xContext ); 1971*cdf0e10cSrcweir } 1972*cdf0e10cSrcweir 1973*cdf0e10cSrcweir // OServiceManager 1974*cdf0e10cSrcweir Reference<XPropertySetInfo > ORegistryServiceManager::getPropertySetInfo() 1975*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 1976*cdf0e10cSrcweir { 1977*cdf0e10cSrcweir check_undisposed(); 1978*cdf0e10cSrcweir if (! m_xPropertyInfo.is()) 1979*cdf0e10cSrcweir { 1980*cdf0e10cSrcweir Sequence< beans::Property > seq( 2 ); 1981*cdf0e10cSrcweir seq[ 0 ] = beans::Property( 1982*cdf0e10cSrcweir OUSTR("DefaultContext"), -1, ::getCppuType( &m_xContext ), 0 ); 1983*cdf0e10cSrcweir seq[ 1 ] = beans::Property( 1984*cdf0e10cSrcweir OUSTR("Registry"), -1, ::getCppuType( &m_xRegistry ), 1985*cdf0e10cSrcweir beans::PropertyAttribute::READONLY ); 1986*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) ); 1987*cdf0e10cSrcweir 1988*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 1989*cdf0e10cSrcweir if (! m_xPropertyInfo.is()) 1990*cdf0e10cSrcweir { 1991*cdf0e10cSrcweir m_xPropertyInfo = xInfo; 1992*cdf0e10cSrcweir } 1993*cdf0e10cSrcweir } 1994*cdf0e10cSrcweir return m_xPropertyInfo; 1995*cdf0e10cSrcweir } 1996*cdf0e10cSrcweir 1997*cdf0e10cSrcweir Any ORegistryServiceManager::getPropertyValue(const OUString& PropertyName) 1998*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 1999*cdf0e10cSrcweir { 2000*cdf0e10cSrcweir check_undisposed(); 2001*cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Registry") )) 2002*cdf0e10cSrcweir { 2003*cdf0e10cSrcweir MutexGuard aGuard( m_mutex ); 2004*cdf0e10cSrcweir if( m_xRegistry.is() ) 2005*cdf0e10cSrcweir return makeAny( m_xRegistry ); 2006*cdf0e10cSrcweir else 2007*cdf0e10cSrcweir return Any(); 2008*cdf0e10cSrcweir } 2009*cdf0e10cSrcweir return OServiceManager::getPropertyValue( PropertyName ); 2010*cdf0e10cSrcweir } 2011*cdf0e10cSrcweir 2012*cdf0e10cSrcweir /* This is the listener function used by the service manager in order 2013*cdf0e10cSrcweir to implement the unloading mechanism, id is the this pointer of the 2014*cdf0e10cSrcweir service manager instances. On notification, that is the function is being called 2015*cdf0e10cSrcweir by rtl_unloadUnusedModules, the cached factroies are being removed from the 2016*cdf0e10cSrcweir service manager ( except manually inserted factories). 2017*cdf0e10cSrcweir */ 2018*cdf0e10cSrcweir extern "C" void SAL_CALL smgrUnloadingListener(void* id) 2019*cdf0e10cSrcweir { 2020*cdf0e10cSrcweir stoc_smgr::OServiceManager* pMgr= reinterpret_cast<stoc_smgr::OServiceManager*>( id); 2021*cdf0e10cSrcweir pMgr->onUnloadingNotify(); 2022*cdf0e10cSrcweir } 2023*cdf0e10cSrcweir 2024*cdf0e10cSrcweir } // namespace 2025*cdf0e10cSrcweir 2026*cdf0e10cSrcweir namespace stoc_bootstrap 2027*cdf0e10cSrcweir { 2028*cdf0e10cSrcweir /** 2029*cdf0e10cSrcweir * Create the ServiceManager 2030*cdf0e10cSrcweir */ 2031*cdf0e10cSrcweir Reference<XInterface > SAL_CALL OServiceManager_CreateInstance( 2032*cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) 2033*cdf0e10cSrcweir { 2034*cdf0e10cSrcweir return Reference<XInterface >( 2035*cdf0e10cSrcweir SAL_STATIC_CAST( 2036*cdf0e10cSrcweir XInterface *, SAL_STATIC_CAST( 2037*cdf0e10cSrcweir OWeakObject *, new stoc_smgr::OServiceManager( xContext ) ) ) ); 2038*cdf0e10cSrcweir } 2039*cdf0e10cSrcweir 2040*cdf0e10cSrcweir /** 2041*cdf0e10cSrcweir * Create the ServiceManager 2042*cdf0e10cSrcweir */ 2043*cdf0e10cSrcweir Reference<XInterface > SAL_CALL ORegistryServiceManager_CreateInstance( 2044*cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) 2045*cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 2046*cdf0e10cSrcweir { 2047*cdf0e10cSrcweir return Reference<XInterface >( 2048*cdf0e10cSrcweir SAL_STATIC_CAST( 2049*cdf0e10cSrcweir XInterface *, SAL_STATIC_CAST( 2050*cdf0e10cSrcweir OWeakObject *, new stoc_smgr::ORegistryServiceManager( xContext ) ) ) ); 2051*cdf0e10cSrcweir } 2052*cdf0e10cSrcweir 2053*cdf0e10cSrcweir Reference<XInterface > SAL_CALL OServiceManagerWrapper_CreateInstance( 2054*cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) 2055*cdf0e10cSrcweir throw (Exception) 2056*cdf0e10cSrcweir { 2057*cdf0e10cSrcweir return (OWeakObject *)new stoc_smgr::OServiceManagerWrapper( xContext ); 2058*cdf0e10cSrcweir } 2059*cdf0e10cSrcweir } 2060