LCOV - code coverage report
Current view: top level - stoc/source/servicemanager - servicemanager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 574 0.0 %
Date: 2014-04-14 Functions: 0 108 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/mutex.hxx>
      21             : #include <osl/diagnose.h>
      22             : #include <rtl/ref.hxx>
      23             : #include <rtl/ustrbuf.hxx>
      24             : 
      25             : #include <boost/unordered_map.hpp>
      26             : #include <boost/unordered_set.hpp>
      27             : #include <uno/mapping.hxx>
      28             : #include <uno/dispatcher.h>
      29             : #include <cppuhelper/queryinterface.hxx>
      30             : #include <cppuhelper/weakref.hxx>
      31             : #include <cppuhelper/component.hxx>
      32             : #include <cppuhelper/implbase1.hxx>
      33             : #include <cppuhelper/implementationentry.hxx>
      34             : #include <cppuhelper/component_context.hxx>
      35             : #include <cppuhelper/bootstrap.hxx>
      36             : #include <cppuhelper/compbase6.hxx>
      37             : #include <cppuhelper/compbase7.hxx>
      38             : #include <cppuhelper/supportsservice.hxx>
      39             : 
      40             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      42             : #include <com/sun/star/lang/XServiceInfo.hpp>
      43             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      44             : #include <com/sun/star/lang/XInitialization.hpp>
      45             : #include <com/sun/star/lang/XEventListener.hpp>
      46             : #include <com/sun/star/lang/DisposedException.hpp>
      47             : #include <com/sun/star/beans/XPropertySet.hpp>
      48             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      49             : #include <com/sun/star/registry/XRegistryKey.hpp>
      50             : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      51             : #include <com/sun/star/container/XSet.hpp>
      52             : #include <com/sun/star/container/XElementAccess.hpp>
      53             : #include <com/sun/star/container/XEnumeration.hpp>
      54             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      55             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      56             : #include <com/sun/star/uno/XUnloadingPreference.hpp>
      57             : 
      58             : using namespace com::sun::star;
      59             : using namespace com::sun::star::uno;
      60             : using namespace com::sun::star::beans;
      61             : using namespace com::sun::star::registry;
      62             : using namespace com::sun::star::lang;
      63             : using namespace com::sun::star::container;
      64             : using namespace cppu;
      65             : using namespace osl;
      66             : using namespace std;
      67             : 
      68             : namespace {
      69             : 
      70           0 : static Sequence< OUString > retrieveAsciiValueList(
      71             :     const Reference< XSimpleRegistry > &xReg, const OUString &keyName )
      72             : {
      73           0 :     Reference< XEnumerationAccess > xAccess( xReg, UNO_QUERY );
      74           0 :     Sequence< OUString > seq;
      75           0 :     if( xAccess.is() )
      76             :     {
      77           0 :         Reference< XEnumeration > xEnum = xAccess->createEnumeration();
      78           0 :         while( xEnum.is() && xEnum->hasMoreElements() )
      79             :         {
      80           0 :             Reference< XSimpleRegistry > xTempReg;
      81           0 :             xEnum->nextElement() >>= xTempReg;
      82           0 :             if( xTempReg.is() )
      83             :             {
      84           0 :                 Sequence< OUString > seq2 = retrieveAsciiValueList( xTempReg, keyName );
      85             : 
      86           0 :                 if( seq2.getLength() )
      87             :                 {
      88           0 :                     sal_Int32 n1Len = seq.getLength();
      89           0 :                     sal_Int32 n2Len = seq2.getLength();
      90             : 
      91           0 :                     seq.realloc( n1Len + n2Len );
      92           0 :                     const OUString *pSource = seq2.getConstArray();
      93           0 :                     OUString *pTarget = seq.getArray();
      94           0 :                     for( int i = 0 ; i < n2Len ; i ++ )
      95             :                     {
      96           0 :                         pTarget[i+n1Len] = pSource[i];
      97             :                     }
      98           0 :                 }
      99             :             }
     100           0 :         }
     101             :     }
     102           0 :     else if( xReg.is () )
     103             :     {
     104             :         try
     105             :         {
     106           0 :             Reference< XRegistryKey > rRootKey = xReg->getRootKey();
     107           0 :             if( rRootKey.is() )
     108             :             {
     109           0 :                 Reference<XRegistryKey > xKey = rRootKey->openKey(keyName);
     110           0 :                 if( xKey.is() )
     111             :                 {
     112           0 :                     seq = xKey->getAsciiListValue();
     113           0 :                 }
     114           0 :             }
     115             :         }
     116           0 :         catch( InvalidRegistryException & )
     117             :         {
     118             :         }
     119           0 :         catch (InvalidValueException &)
     120             :         {
     121             :         }
     122             :     }
     123           0 :     return seq;
     124             : }
     125             : 
     126             : /*****************************************************************************
     127             :     Enumeration by ServiceName
     128             : *****************************************************************************/
     129             : struct hashRef_Impl
     130             : {
     131           0 :     size_t operator()(const Reference<XInterface > & rName) const
     132             :     {
     133             :         // query to XInterface. The cast to XInterface* must be the same for the same object
     134           0 :         Reference<XInterface > x( Reference<XInterface >::query( rName ) );
     135           0 :         return (size_t)x.get();
     136             :     }
     137             : };
     138             : 
     139             : struct equaltoRef_Impl
     140             : {
     141           0 :     bool operator()(const Reference<XInterface > & rName1, const Reference<XInterface > & rName2 ) const
     142           0 :         { return rName1 == rName2; }
     143             : };
     144             : 
     145             : typedef boost::unordered_set
     146             : <
     147             :     Reference<XInterface >,
     148             :     hashRef_Impl,
     149             :     equaltoRef_Impl
     150             : > HashSet_Ref;
     151             : 
     152             : 
     153             : class ServiceEnumeration_Impl : public WeakImplHelper1< XEnumeration >
     154             : {
     155             : public:
     156           0 :     ServiceEnumeration_Impl( const Sequence< Reference<XInterface > > & rFactories )
     157             :         : aFactories( rFactories )
     158           0 :         , nIt( 0 )
     159           0 :         {}
     160           0 :     virtual ~ServiceEnumeration_Impl() {}
     161             : 
     162             :     // XEnumeration
     163             :     sal_Bool SAL_CALL hasMoreElements()
     164             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     165             :     Any SAL_CALL nextElement()
     166             :         throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     167             : private:
     168             :     Mutex                               aMutex;
     169             :     Sequence< Reference<XInterface > >  aFactories;
     170             :     sal_Int32                           nIt;
     171             : };
     172             : 
     173             : // XEnumeration
     174           0 : sal_Bool ServiceEnumeration_Impl::hasMoreElements() throw(::com::sun::star::uno::RuntimeException, std::exception)
     175             : {
     176           0 :     MutexGuard aGuard( aMutex );
     177           0 :     return nIt != aFactories.getLength();
     178             : }
     179             : 
     180             : // XEnumeration
     181           0 : Any ServiceEnumeration_Impl::nextElement()
     182             :     throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     183             : {
     184           0 :     MutexGuard aGuard( aMutex );
     185           0 :     if( nIt == aFactories.getLength() )
     186           0 :         throw NoSuchElementException();
     187             : 
     188           0 :     return Any( &aFactories.getConstArray()[nIt++], ::getCppuType( (const Reference<XInterface > *)0 ) );
     189             : }
     190             : 
     191             : 
     192           0 : class PropertySetInfo_Impl : public WeakImplHelper1< beans::XPropertySetInfo >
     193             : {
     194             :     Sequence< beans::Property > m_properties;
     195             : 
     196             : public:
     197           0 :     inline PropertySetInfo_Impl( Sequence< beans::Property > const & properties ) SAL_THROW(())
     198           0 :         : m_properties( properties )
     199           0 :         {}
     200             : 
     201             :     // XPropertySetInfo impl
     202             :     virtual Sequence< beans::Property > SAL_CALL getProperties()
     203             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     204             :     virtual beans::Property SAL_CALL getPropertyByName( OUString const & name )
     205             :         throw (beans::UnknownPropertyException, RuntimeException, std::exception) SAL_OVERRIDE;
     206             :     virtual sal_Bool SAL_CALL hasPropertyByName( OUString const & name )
     207             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     208             : };
     209             : 
     210           0 : Sequence< beans::Property > PropertySetInfo_Impl::getProperties()
     211             :     throw (RuntimeException, std::exception)
     212             : {
     213           0 :     return m_properties;
     214             : }
     215             : 
     216           0 : beans::Property PropertySetInfo_Impl::getPropertyByName( OUString const & name )
     217             :     throw (beans::UnknownPropertyException, RuntimeException, std::exception)
     218             : {
     219           0 :     beans::Property const * p = m_properties.getConstArray();
     220           0 :     for ( sal_Int32 nPos = m_properties.getLength(); nPos--; )
     221             :     {
     222           0 :         if (p[ nPos ].Name.equals( name ))
     223           0 :             return p[ nPos ];
     224             :     }
     225             :     throw beans::UnknownPropertyException(
     226           0 :         "unknown property: " + name, Reference< XInterface >() );
     227             : }
     228             : 
     229           0 : sal_Bool PropertySetInfo_Impl::hasPropertyByName( OUString const & name )
     230             :     throw (RuntimeException, std::exception)
     231             : {
     232           0 :     beans::Property const * p = m_properties.getConstArray();
     233           0 :     for ( sal_Int32 nPos = m_properties.getLength(); nPos--; )
     234             :     {
     235           0 :         if (p[ nPos ].Name.equals( name ))
     236           0 :             return sal_True;
     237             :     }
     238           0 :     return sal_False;
     239             : }
     240             : 
     241             : 
     242             : /*****************************************************************************
     243             :     Enumeration by implementation
     244             : *****************************************************************************/
     245             : class ImplementationEnumeration_Impl : public WeakImplHelper1< XEnumeration >
     246             : {
     247             : public:
     248           0 :     ImplementationEnumeration_Impl( const HashSet_Ref & rImplementationMap )
     249             :         : aImplementationMap( rImplementationMap )
     250           0 :         , aIt( aImplementationMap.begin() )
     251           0 :         {}
     252             :     virtual ~ImplementationEnumeration_Impl();
     253             : 
     254             :     // XEnumeration
     255             :     virtual sal_Bool SAL_CALL hasMoreElements()
     256             :          throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     257             :     virtual Any SAL_CALL nextElement()
     258             :         throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     259             : 
     260             : private:
     261             :     Mutex                           aMutex;
     262             :     HashSet_Ref                     aImplementationMap;
     263             :     HashSet_Ref::iterator           aIt;
     264             :     Reference<XInterface >          xNext;
     265             : };
     266             : 
     267           0 : ImplementationEnumeration_Impl::~ImplementationEnumeration_Impl() {}
     268             : 
     269             : // XEnumeration
     270           0 : sal_Bool ImplementationEnumeration_Impl::hasMoreElements()
     271             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     272             : {
     273           0 :     MutexGuard aGuard( aMutex );
     274           0 :     return aIt != aImplementationMap.end();
     275             : }
     276             : 
     277             : // XEnumeration
     278           0 : Any ImplementationEnumeration_Impl::nextElement()
     279             :     throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     280             : {
     281           0 :     MutexGuard aGuard( aMutex );
     282           0 :     if( aIt == aImplementationMap.end() )
     283           0 :         throw NoSuchElementException();
     284             : 
     285           0 :     Any ret( &(*aIt), ::getCppuType( (const Reference<XInterface > *)0 ) );
     286           0 :     ++aIt;
     287           0 :     return ret;
     288             : }
     289             : 
     290             : /*****************************************************************************
     291             :     Hash tables
     292             : *****************************************************************************/
     293             : struct equalOWString_Impl
     294             : {
     295           0 :   sal_Bool operator()(const OUString & s1, const OUString & s2) const
     296           0 :         { return s1 == s2; }
     297             : };
     298             : 
     299             : struct hashOWString_Impl
     300             : {
     301           0 :     size_t operator()(const OUString & rName) const
     302           0 :         { return rName.hashCode(); }
     303             : };
     304             : 
     305             : typedef boost::unordered_set
     306             : <
     307             :     OUString,
     308             :     hashOWString_Impl,
     309             :     equalOWString_Impl
     310             : > HashSet_OWString;
     311             : 
     312             : typedef boost::unordered_multimap
     313             : <
     314             :     OUString,
     315             :     Reference<XInterface >,
     316             :     hashOWString_Impl,
     317             :     equalOWString_Impl
     318             : > HashMultimap_OWString_Interface;
     319             : 
     320             : typedef boost::unordered_map
     321             : <
     322             :     OUString,
     323             :     Reference<XInterface >,
     324             :     hashOWString_Impl,
     325             :     equalOWString_Impl
     326             : > HashMap_OWString_Interface;
     327             : 
     328             : /*****************************************************************************
     329             :     class OServiceManager_Listener
     330             : *****************************************************************************/
     331           0 : class OServiceManager_Listener : public WeakImplHelper1< XEventListener >
     332             : {
     333             : private:
     334             :     WeakReference<XSet > xSMgr;
     335             : 
     336             : public:
     337           0 :     OServiceManager_Listener( const Reference<XSet > & rSMgr )
     338           0 :         : xSMgr( rSMgr )
     339           0 :         {}
     340             : 
     341             :     // XEventListener
     342             :     virtual void SAL_CALL disposing(const EventObject & rEvt ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     343             : };
     344             : 
     345           0 : void OServiceManager_Listener::disposing(const EventObject & rEvt )
     346             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     347             : {
     348           0 :     Reference<XSet > x( xSMgr );
     349           0 :     if( x.is() )
     350             :     {
     351             :         try
     352             :         {
     353           0 :             x->remove( Any( &rEvt.Source, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
     354             :         }
     355           0 :         catch( const IllegalArgumentException & )
     356             :         {
     357             :             OSL_FAIL( "IllegalArgumentException caught" );
     358             :         }
     359           0 :         catch( const NoSuchElementException & )
     360             :         {
     361             :             OSL_FAIL( "NoSuchElementException caught" );
     362             :         }
     363           0 :     }
     364           0 : }
     365             : 
     366             : 
     367             : /*****************************************************************************
     368             :     class OServiceManager
     369             : *****************************************************************************/
     370           0 : struct OServiceManagerMutex
     371             : {
     372             :     Mutex m_mutex;
     373             : };
     374             : 
     375             : typedef WeakComponentImplHelper7<
     376             :     lang::XMultiServiceFactory, lang::XMultiComponentFactory, lang::XServiceInfo,
     377             :     lang::XInitialization,
     378             :     container::XSet, container::XContentEnumerationAccess,
     379             :     beans::XPropertySet > t_OServiceManager_impl;
     380             : 
     381             : class OServiceManager
     382             :     : public OServiceManagerMutex
     383             :     , public t_OServiceManager_impl
     384             : {
     385             : public:
     386             :     OServiceManager( Reference< XComponentContext > const & xContext );
     387             :     virtual ~OServiceManager();
     388             : 
     389             :     // XInitialization
     390             :     void SAL_CALL initialize( Sequence< Any > const & args )
     391             :         throw (Exception, std::exception) SAL_OVERRIDE;
     392             : 
     393             :     // XServiceInfo
     394             :     virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     395             :     virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     396             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     397             : 
     398             :     // XMultiComponentFactory
     399             :     virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
     400             :         OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext )
     401             :         throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE;
     402             :     virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
     403             :         OUString const & rServiceSpecifier,
     404             :         Sequence< Any > const & rArguments,
     405             :         Reference< XComponentContext > const & xContext )
     406             :         throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE;
     407             : //      virtual Sequence< OUString > SAL_CALL getAvailableServiceNames()
     408             : //          throw (RuntimeException);
     409             : 
     410             :     // XMultiServiceFactory
     411             :     virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     412             :     virtual Reference<XInterface > SAL_CALL createInstance(const OUString &) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     413             :     virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString &, const Sequence<Any >& Arguments) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     414             : 
     415             :     // The same as the getAvailableServiceNames, but only uique names
     416             :     Sequence< OUString > getUniqueAvailableServiceNames(
     417             :         HashSet_OWString & aNameSet );
     418             : 
     419             :     // XElementAccess
     420             :     virtual Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     421             :     virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     422             : 
     423             :     // XEnumerationAccess
     424             :     virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     425             : 
     426             :     // XSet
     427             :     virtual sal_Bool SAL_CALL has( const Any & Element ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     428             :     virtual void SAL_CALL insert( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     429             :     virtual void SAL_CALL remove( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     430             : 
     431             :     // XContentEnumerationAccess
     432             :     //Sequence< OUString >          getAvailableServiceNames() throw( (Exception) );
     433             :     virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     434             : 
     435             :     // XComponent
     436             :     virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     437             : 
     438             :     // XPropertySet
     439             :     Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo()
     440             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     441             :     void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue)
     442             :         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, std::exception) SAL_OVERRIDE;
     443             :     Any SAL_CALL getPropertyValue(const OUString& PropertyName)
     444             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     445             :     void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
     446             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     447             :     void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
     448             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     449             :     void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
     450             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     451             :     void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
     452             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     453             : 
     454             : protected:
     455             :     inline bool is_disposed() const SAL_THROW( (lang::DisposedException) );
     456             :     inline void check_undisposed() const SAL_THROW( (lang::DisposedException) );
     457             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     458             : 
     459             :     sal_Bool haveFactoryWithThisImplementation(const OUString& aImplName);
     460             : 
     461             :     virtual Sequence< Reference< XInterface > > queryServiceFactories(
     462             :         const OUString& aServiceName, Reference< XComponentContext > const & xContext );
     463             : 
     464             :     Reference< XComponentContext >  m_xContext;
     465             : 
     466             :     Reference< beans::XPropertySetInfo > m_xPropertyInfo;
     467             : 
     468             :     // factories which have been loaded and not inserted( by XSet::insert)
     469             :     // are remembered by this set.
     470             :     HashSet_Ref m_SetLoadedFactories;
     471             : private:
     472             : 
     473             :     Reference<XEventListener >      getFactoryListener();
     474             : 
     475             : 
     476             :     HashMultimap_OWString_Interface m_ServiceMap;
     477             :     HashSet_Ref                     m_ImplementationMap;
     478             :     HashMap_OWString_Interface      m_ImplementationNameMap;
     479             :     Reference<XEventListener >      xFactoryListener;
     480             :     bool                            m_bInDisposing;
     481             : };
     482             : 
     483             : 
     484             : 
     485           0 : inline bool OServiceManager::is_disposed() const
     486             :     SAL_THROW( (lang::DisposedException) )
     487             : {
     488             :     // ought to be guarded by m_mutex:
     489           0 :     return (m_bInDisposing || rBHelper.bDisposed);
     490             : }
     491             : 
     492             : 
     493           0 : inline void OServiceManager::check_undisposed() const
     494             :     SAL_THROW( (lang::DisposedException) )
     495             : {
     496           0 :     if (is_disposed())
     497             :     {
     498             :         throw lang::DisposedException(
     499             :             "service manager instance has already been disposed!",
     500           0 :             (OWeakObject *)this );
     501             :     }
     502           0 : }
     503             : 
     504             : 
     505             : 
     506             : 
     507             : 
     508             : typedef WeakComponentImplHelper6<
     509             :     lang::XMultiServiceFactory, lang::XMultiComponentFactory, lang::XServiceInfo,
     510             :     container::XSet, container::XContentEnumerationAccess,
     511             :     beans::XPropertySet > t_OServiceManagerWrapper_impl;
     512             : 
     513             : class OServiceManagerWrapper : public OServiceManagerMutex, public t_OServiceManagerWrapper_impl
     514             : {
     515             :     Reference< XComponentContext > m_xContext;
     516             :     Reference< XMultiComponentFactory > m_root;
     517           0 :     inline Reference< XMultiComponentFactory > getRoot() SAL_THROW( (RuntimeException) )
     518             :     {
     519           0 :         if (! m_root.is())
     520             :         {
     521             :             throw lang::DisposedException(
     522             :                 "service manager instance has already been disposed!",
     523           0 :                 Reference< XInterface >() );
     524             :         }
     525           0 :         return m_root;
     526             :     }
     527             : 
     528             : protected:
     529             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     530             : 
     531             : public:
     532             :     OServiceManagerWrapper(
     533             :         Reference< XComponentContext > const & xContext )
     534             :         SAL_THROW( (RuntimeException) );
     535             :     virtual ~OServiceManagerWrapper() SAL_THROW(());
     536             : 
     537             :     // XServiceInfo
     538           0 :     virtual OUString SAL_CALL getImplementationName() throw (RuntimeException, std::exception) SAL_OVERRIDE
     539           0 :         { return Reference< XServiceInfo >(getRoot(), UNO_QUERY_THROW)->getImplementationName(); }
     540           0 :     virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (RuntimeException, std::exception) SAL_OVERRIDE
     541           0 :         { return Reference< XServiceInfo >(getRoot(), UNO_QUERY_THROW)->supportsService( ServiceName ); }
     542           0 :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException, std::exception) SAL_OVERRIDE
     543           0 :         { return Reference< XServiceInfo >(getRoot(), UNO_QUERY_THROW)->getSupportedServiceNames(); }
     544             : 
     545             :     // XMultiComponentFactory
     546           0 :     virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
     547             :         OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext )
     548             :         throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE
     549           0 :         { return getRoot()->createInstanceWithContext( rServiceSpecifier, xContext ); }
     550           0 :     virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
     551             :         OUString const & rServiceSpecifier,
     552             :         Sequence< Any > const & rArguments,
     553             :         Reference< XComponentContext > const & xContext )
     554             :         throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE
     555           0 :         { return getRoot()->createInstanceWithArgumentsAndContext( rServiceSpecifier, rArguments, xContext ); }
     556             : //      virtual Sequence< OUString > SAL_CALL getAvailableServiceNames()
     557             : //          throw (RuntimeException);
     558             : 
     559             :     // XMultiServiceFactory
     560           0 :     virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException, std::exception) SAL_OVERRIDE
     561           0 :         { return getRoot()->getAvailableServiceNames(); }
     562           0 :     virtual Reference<XInterface > SAL_CALL createInstance(const OUString & name) throw (Exception, std::exception) SAL_OVERRIDE
     563           0 :         { return getRoot()->createInstanceWithContext( name, m_xContext ); }
     564           0 :     virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString & name, const Sequence<Any >& Arguments) throw (Exception, std::exception) SAL_OVERRIDE
     565           0 :         { return getRoot()->createInstanceWithArgumentsAndContext( name, Arguments, m_xContext ); }
     566             : 
     567             :     // XElementAccess
     568           0 :     virtual Type SAL_CALL getElementType() throw (RuntimeException, std::exception) SAL_OVERRIDE
     569           0 :         { return Reference< XElementAccess >(getRoot(), UNO_QUERY_THROW)->getElementType(); }
     570           0 :     virtual sal_Bool SAL_CALL hasElements() throw (RuntimeException, std::exception) SAL_OVERRIDE
     571           0 :         { return Reference< XElementAccess >(getRoot(), UNO_QUERY_THROW)->hasElements(); }
     572             : 
     573             :     // XEnumerationAccess
     574           0 :     virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw (RuntimeException, std::exception) SAL_OVERRIDE
     575           0 :         { return Reference< XEnumerationAccess >(getRoot(), UNO_QUERY_THROW)->createEnumeration(); }
     576             : 
     577             :     // XSet
     578           0 :     virtual sal_Bool SAL_CALL has( const Any & Element ) throw (RuntimeException, std::exception) SAL_OVERRIDE
     579           0 :         { return Reference< XSet >(getRoot(), UNO_QUERY_THROW)->has( Element ); }
     580           0 :     virtual void SAL_CALL insert( const Any & Element ) throw (lang::IllegalArgumentException, container::ElementExistException, RuntimeException, std::exception) SAL_OVERRIDE
     581           0 :         { Reference< XSet >(getRoot(), UNO_QUERY_THROW)->insert( Element ); }
     582           0 :     virtual void SAL_CALL remove( const Any & Element ) throw (lang::IllegalArgumentException, container::NoSuchElementException, RuntimeException, std::exception) SAL_OVERRIDE
     583           0 :         { Reference< XSet >(getRoot(), UNO_QUERY_THROW)->remove( Element ); }
     584             : 
     585             :     // XContentEnumerationAccess
     586             :     //Sequence< OUString >          getAvailableServiceNames() throw( (Exception) );
     587           0 :     virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw (RuntimeException, std::exception) SAL_OVERRIDE
     588           0 :         { return Reference< XContentEnumerationAccess >(getRoot(), UNO_QUERY_THROW)->createContentEnumeration( aServiceName ); }
     589             : 
     590             :     // XPropertySet
     591           0 :     Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException, std::exception) SAL_OVERRIDE
     592           0 :         { return Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->getPropertySetInfo(); }
     593             : 
     594             :     void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue)
     595             :         throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
     596             :     Any SAL_CALL getPropertyValue(const OUString& PropertyName)
     597             :         throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
     598             : 
     599           0 :     void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
     600             :         throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE
     601           0 :         { Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->addPropertyChangeListener( PropertyName, aListener ); }
     602           0 :     void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
     603             :         throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE
     604           0 :         { Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->removePropertyChangeListener( PropertyName, aListener ); }
     605           0 :     void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
     606             :         throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE
     607           0 :         { Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->addVetoableChangeListener( PropertyName, aListener ); }
     608           0 :     void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
     609             :         throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE
     610           0 :         { Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->removeVetoableChangeListener( PropertyName, aListener ); }
     611             : };
     612             : 
     613           0 : void SAL_CALL OServiceManagerWrapper::setPropertyValue(
     614             :     const OUString& PropertyName, const Any& aValue )
     615             :     throw (beans::UnknownPropertyException, beans::PropertyVetoException,
     616             :            lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException, std::exception)
     617             : {
     618           0 :     if ( PropertyName == "DefaultContext" )
     619             :     {
     620           0 :         Reference< XComponentContext > xContext;
     621           0 :         if (aValue >>= xContext)
     622             :         {
     623           0 :             MutexGuard aGuard( m_mutex );
     624           0 :             m_xContext = xContext;
     625             :         }
     626             :         else
     627             :         {
     628             :             throw IllegalArgumentException(
     629             :                 OUString("no XComponentContext given!"),
     630           0 :                 (OWeakObject *)this, 1 );
     631           0 :         }
     632             :     }
     633             :     else
     634             :     {
     635           0 :         Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->setPropertyValue( PropertyName, aValue );
     636             :     }
     637           0 : }
     638             : 
     639           0 : Any SAL_CALL OServiceManagerWrapper::getPropertyValue(
     640             :     const OUString& PropertyName )
     641             :     throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException, std::exception)
     642             : {
     643           0 :     if ( PropertyName == "DefaultContext" )
     644             :     {
     645           0 :         MutexGuard aGuard( m_mutex );
     646           0 :         if( m_xContext.is() )
     647           0 :             return makeAny( m_xContext );
     648             :         else
     649           0 :             return Any();
     650             :     }
     651             :     else
     652             :     {
     653           0 :         return Reference< XPropertySet >(getRoot(), UNO_QUERY_THROW)->getPropertyValue( PropertyName );
     654             :     }
     655             : }
     656             : 
     657           0 : void OServiceManagerWrapper::disposing()
     658             : {
     659           0 :     m_xContext.clear();
     660             : 
     661             : // no m_root->dispose(), because every context disposes its service manager...
     662           0 :     m_root.clear();
     663           0 : }
     664             : 
     665           0 : OServiceManagerWrapper::~OServiceManagerWrapper() SAL_THROW(()) {}
     666             : 
     667           0 : OServiceManagerWrapper::OServiceManagerWrapper(
     668             :     Reference< XComponentContext > const & xContext )
     669             :     SAL_THROW( (RuntimeException) )
     670             :     : t_OServiceManagerWrapper_impl( m_mutex )
     671             :     , m_xContext( xContext )
     672           0 :     , m_root( xContext->getServiceManager() )
     673             : {
     674           0 :     if (! m_root.is())
     675             :     {
     676             :         throw RuntimeException(
     677             :             OUString("no service manager to wrap"),
     678           0 :             Reference< XInterface >() );
     679             :     }
     680           0 : }
     681             : 
     682             : 
     683             : 
     684             : 
     685             : 
     686             : /**
     687             :  * Create a ServiceManager
     688             :  */
     689           0 : OServiceManager::OServiceManager( Reference< XComponentContext > const & xContext )
     690             :     : t_OServiceManager_impl( m_mutex )
     691             :     , m_xContext( xContext )
     692           0 :     , m_bInDisposing( false )
     693           0 : {}
     694             : 
     695             : /**
     696             :  * Destroy the ServiceManager
     697             :  */
     698           0 : OServiceManager::~OServiceManager() {}
     699             : 
     700             : // XComponent
     701           0 : void OServiceManager::dispose()
     702             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     703             : {
     704           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     705           0 :         return;
     706           0 :     t_OServiceManager_impl::dispose();
     707             : }
     708             : 
     709           0 : void OServiceManager::disposing()
     710             : {
     711             :     // dispose all factories
     712           0 :     HashSet_Ref aImpls;
     713             :     {
     714           0 :         MutexGuard aGuard( m_mutex );
     715           0 :         m_bInDisposing = true;
     716           0 :         aImpls = m_ImplementationMap;
     717             :     }
     718           0 :     HashSet_Ref::iterator aIt = aImpls.begin();
     719           0 :     while( aIt != aImpls.end() )
     720             :     {
     721             :         try
     722             :         {
     723           0 :             Reference<XComponent > xComp( Reference<XComponent >::query( *aIt++ ) );
     724           0 :             if( xComp.is() )
     725           0 :                 xComp->dispose();
     726             :         }
     727           0 :         catch (const RuntimeException & exc)
     728             :         {
     729             : #if OSL_DEBUG_LEVEL > 1
     730             :             OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
     731             :             OSL_TRACE( "### RuntimeException occurred upon disposing factory: %s", str.getStr() );
     732             : #else
     733             :             (void) exc; // unused
     734             : #endif
     735             :         }
     736             :     }
     737             : 
     738             :     // dispose
     739           0 :     HashSet_Ref aImplMap;
     740             :     {
     741           0 :         MutexGuard aGuard( m_mutex );
     742             :         // erase all members
     743           0 :         m_ServiceMap = HashMultimap_OWString_Interface();
     744           0 :         aImplMap = m_ImplementationMap;
     745           0 :         m_ImplementationMap = HashSet_Ref();
     746           0 :         m_ImplementationNameMap = HashMap_OWString_Interface();
     747           0 :         m_SetLoadedFactories= HashSet_Ref();
     748             :     }
     749             : 
     750           0 :     m_xContext.clear();
     751             : 
     752             :     // not only the Event should hold the object
     753           0 :     OSL_ASSERT( m_refCount != 1 );
     754           0 : }
     755             : 
     756             : // XPropertySet
     757           0 : Reference<XPropertySetInfo > OServiceManager::getPropertySetInfo()
     758             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     759             : {
     760           0 :     check_undisposed();
     761           0 :     if (! m_xPropertyInfo.is())
     762             :     {
     763           0 :         Sequence< beans::Property > seq( 1 );
     764           0 :         seq[ 0 ] = beans::Property(
     765           0 :             "DefaultContext", -1, ::getCppuType( &m_xContext ), 0 );
     766           0 :         Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) );
     767             : 
     768           0 :         MutexGuard aGuard( m_mutex );
     769           0 :         if (! m_xPropertyInfo.is())
     770             :         {
     771           0 :             m_xPropertyInfo = xInfo;
     772           0 :         }
     773             :     }
     774           0 :     return m_xPropertyInfo;
     775             : }
     776             : 
     777           0 : void OServiceManager::setPropertyValue(
     778             :     const OUString& PropertyName, const Any& aValue )
     779             :     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, std::exception)
     780             : {
     781           0 :     check_undisposed();
     782           0 :     if ( PropertyName == "DefaultContext" )
     783             :     {
     784           0 :         Reference< XComponentContext > xContext;
     785           0 :         if (aValue >>= xContext)
     786             :         {
     787           0 :             MutexGuard aGuard( m_mutex );
     788           0 :             m_xContext = xContext;
     789             :         }
     790             :         else
     791             :         {
     792             :             throw IllegalArgumentException(
     793             :                 OUString("no XComponentContext given!"),
     794           0 :                 (OWeakObject *)this, 1 );
     795           0 :         }
     796             :     }
     797             :     else
     798             :     {
     799             :         throw UnknownPropertyException(
     800           0 :             OUString("unknown property ") + PropertyName,
     801           0 :             (OWeakObject *)this );
     802             :     }
     803           0 : }
     804             : 
     805           0 : Any OServiceManager::getPropertyValue(const OUString& PropertyName)
     806             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     807             : {
     808           0 :     check_undisposed();
     809           0 :     if ( PropertyName == "DefaultContext" )
     810             :     {
     811           0 :         MutexGuard aGuard( m_mutex );
     812           0 :         if( m_xContext.is() )
     813           0 :             return makeAny( m_xContext );
     814             :         else
     815           0 :             return Any();
     816             :     }
     817             :     else
     818             :     {
     819           0 :         UnknownPropertyException except;
     820           0 :         except.Message =  "ServiceManager : unknown property " + PropertyName;
     821           0 :         throw except;
     822             :     }
     823             : }
     824             : 
     825           0 : void OServiceManager::addPropertyChangeListener(
     826             :     const OUString&, const Reference<XPropertyChangeListener >&)
     827             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     828             : {
     829           0 :     check_undisposed();
     830           0 :     throw UnknownPropertyException();
     831             : }
     832             : 
     833           0 : void OServiceManager::removePropertyChangeListener(
     834             :     const OUString&, const Reference<XPropertyChangeListener >&)
     835             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     836             : {
     837           0 :     check_undisposed();
     838           0 :     throw UnknownPropertyException();
     839             : }
     840             : 
     841           0 : void OServiceManager::addVetoableChangeListener(
     842             :     const OUString&, const Reference<XVetoableChangeListener >&)
     843             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     844             : {
     845           0 :     check_undisposed();
     846           0 :     throw UnknownPropertyException();
     847             : }
     848             : 
     849           0 : void OServiceManager::removeVetoableChangeListener(
     850             :     const OUString&, const Reference<XVetoableChangeListener >&)
     851             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     852             : {
     853           0 :     check_undisposed();
     854           0 :     throw UnknownPropertyException();
     855             : }
     856             : 
     857             : // OServiceManager
     858           0 : Reference<XEventListener > OServiceManager::getFactoryListener()
     859             : {
     860           0 :     check_undisposed();
     861           0 :     MutexGuard aGuard( m_mutex );
     862           0 :     if( !xFactoryListener.is() )
     863           0 :         xFactoryListener = new OServiceManager_Listener( this );
     864           0 :     return xFactoryListener;
     865             : }
     866             : 
     867             : // XMultiServiceFactory, XContentEnumeration
     868           0 : Sequence< OUString > OServiceManager::getUniqueAvailableServiceNames(
     869             :     HashSet_OWString & aNameSet )
     870             : {
     871           0 :     check_undisposed();
     872           0 :     MutexGuard aGuard( m_mutex );
     873           0 :     HashMultimap_OWString_Interface::iterator aSIt = m_ServiceMap.begin();
     874           0 :     while( aSIt != m_ServiceMap.end() )
     875           0 :         aNameSet.insert( (*aSIt++).first );
     876             : 
     877             :     /* do not return the implementation names
     878             :     HashMap_OWString_Interface      m_ImplementationNameMap;
     879             :     HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.begin();
     880             :     while( aIt != m_ImplementationNameMap.end() )
     881             :         aNameSet.insert( (*aIt++).first );
     882             :     */
     883             : 
     884           0 :     Sequence< OUString > aNames( aNameSet.size() );
     885           0 :     OUString * pArray = aNames.getArray();
     886           0 :     sal_Int32 i = 0;
     887           0 :     HashSet_OWString::iterator next = aNameSet.begin();
     888           0 :     while( next != aNameSet.end() )
     889           0 :         pArray[i++] = (*next++);
     890             : 
     891           0 :     return aNames;
     892             : }
     893             : 
     894             : // XMultiComponentFactory
     895           0 : Reference< XInterface > OServiceManager::createInstanceWithContext(
     896             :     OUString const & rServiceSpecifier,
     897             :     Reference< XComponentContext > const & xContext )
     898             :     throw (Exception, RuntimeException, std::exception)
     899             : {
     900           0 :     check_undisposed();
     901             : #if OSL_DEBUG_LEVEL > 0
     902             :     Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY );
     903             :     OSL_ASSERT( xProps.is() );
     904             :     if (xProps.is())
     905             :     {
     906             :         Reference< XComponentContext > xDefContext;
     907             :         xProps->getPropertyValue(
     908             :             OUString("DefaultContext") ) >>= xDefContext;
     909             :         OSL_ENSURE(
     910             :             xContext == xDefContext,
     911             :             "### default context of service manager singleton differs from context holding it!" );
     912             :     }
     913             : #endif
     914             : 
     915             :     Sequence< Reference< XInterface > > factories(
     916           0 :         queryServiceFactories( rServiceSpecifier, xContext ) );
     917           0 :     Reference< XInterface > const * p = factories.getConstArray();
     918           0 :     for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
     919             :     {
     920             :         try
     921             :         {
     922           0 :             Reference< XInterface > const & xFactory = p[ nPos ];
     923           0 :             if (xFactory.is())
     924             :             {
     925           0 :                 Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
     926           0 :                 if (xFac.is())
     927             :                 {
     928           0 :                     return xFac->createInstanceWithContext( xContext );
     929             :                 }
     930             :                 else
     931             :                 {
     932           0 :                     Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
     933           0 :                     if (xFac2.is())
     934             :                     {
     935             : #if OSL_DEBUG_LEVEL > 1
     936             :                         OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) );
     937             :                         OSL_TRACE( "### ignoring given context raising service %s !!!", aStr.getStr() );
     938             : #endif
     939           0 :                         return xFac2->createInstance();
     940           0 :                     }
     941           0 :                 }
     942             :             }
     943             :         }
     944           0 :         catch (const lang::DisposedException & exc)
     945             :         {
     946             : #if OSL_DEBUG_LEVEL > 1
     947             :             OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
     948             :             OSL_TRACE( "### DisposedException occurred: %s", str.getStr() );
     949             : #else
     950             :             (void) exc; // unused
     951             : #endif
     952             :         }
     953             :     }
     954             : 
     955           0 :     return Reference< XInterface >();
     956             : }
     957             : // XMultiComponentFactory
     958           0 : Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext(
     959             :     OUString const & rServiceSpecifier,
     960             :     Sequence< Any > const & rArguments,
     961             :     Reference< XComponentContext > const & xContext )
     962             :     throw (Exception, RuntimeException, std::exception)
     963             : {
     964           0 :     check_undisposed();
     965             : #if OSL_DEBUG_LEVEL > 0
     966             :     Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY );
     967             :     OSL_ASSERT( xProps.is() );
     968             :     if (xProps.is())
     969             :     {
     970             :         Reference< XComponentContext > xDefContext;
     971             :         xProps->getPropertyValue(
     972             :             OUString("DefaultContext") ) >>= xDefContext;
     973             :         OSL_ENSURE(
     974             :             xContext == xDefContext,
     975             :             "### default context of service manager singleton differs from context holding it!" );
     976             :     }
     977             : #endif
     978             : 
     979             :     Sequence< Reference< XInterface > > factories(
     980           0 :         queryServiceFactories( rServiceSpecifier, xContext ) );
     981           0 :     Reference< XInterface > const * p = factories.getConstArray();
     982           0 :     for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
     983             :     {
     984             :         try
     985             :         {
     986           0 :             Reference< XInterface > const & xFactory = p[ nPos ];
     987           0 :             if (xFactory.is())
     988             :             {
     989           0 :                 Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
     990           0 :                 if (xFac.is())
     991             :                 {
     992           0 :                     return xFac->createInstanceWithArgumentsAndContext( rArguments, xContext );
     993             :                 }
     994             :                 else
     995             :                 {
     996           0 :                     Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
     997           0 :                     if (xFac2.is())
     998             :                     {
     999             : #if OSL_DEBUG_LEVEL > 1
    1000             :                         OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) );
    1001             :                         OSL_TRACE( "### ignoring given context raising service %s !!!", aStr.getStr() );
    1002             : #endif
    1003           0 :                         return xFac2->createInstanceWithArguments( rArguments );
    1004           0 :                     }
    1005           0 :                 }
    1006             :             }
    1007             :         }
    1008           0 :         catch (const lang::DisposedException & exc)
    1009             :         {
    1010             : #if OSL_DEBUG_LEVEL > 1
    1011             :             OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
    1012             :             OSL_TRACE( "### DisposedException occurred: %s", str.getStr() );
    1013             : #else
    1014             :             (void) exc; // unused
    1015             : #endif
    1016             :         }
    1017             :     }
    1018             : 
    1019           0 :     return Reference< XInterface >();
    1020             : }
    1021             : 
    1022             : // XMultiServiceFactory, XMultiComponentFactory, XContentEnumeration
    1023           0 : Sequence< OUString > OServiceManager::getAvailableServiceNames()
    1024             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1025             : {
    1026           0 :     check_undisposed();
    1027             :     // all names
    1028           0 :     HashSet_OWString aNameSet;
    1029           0 :     return getUniqueAvailableServiceNames( aNameSet );
    1030             : }
    1031             : 
    1032             : // XMultibleServiceFactory
    1033           0 : Reference<XInterface > OServiceManager::createInstance(
    1034             :     const OUString& rServiceSpecifier )
    1035             :     throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
    1036             : {
    1037             :     return createInstanceWithContext(
    1038           0 :         rServiceSpecifier, m_xContext );
    1039             : }
    1040             : 
    1041             : // XMultibleServiceFactory
    1042           0 : Reference<XInterface > OServiceManager::createInstanceWithArguments(
    1043             :     const OUString& rServiceSpecifier,
    1044             :     const Sequence<Any >& rArguments )
    1045             :     throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
    1046             : {
    1047             :     return createInstanceWithArgumentsAndContext(
    1048           0 :         rServiceSpecifier, rArguments, m_xContext );
    1049             : }
    1050             : 
    1051             : // XInitialization
    1052           0 : void OServiceManager::initialize( Sequence< Any > const & )
    1053             :     throw (Exception, std::exception)
    1054             : {
    1055           0 :     check_undisposed();
    1056             :     OSL_FAIL( "not impl!" );
    1057           0 : }
    1058             : 
    1059             : // XServiceInfo
    1060           0 : OUString OServiceManager::getImplementationName()
    1061             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1062             : {
    1063           0 :     return OUString("com.sun.star.comp.stoc.OServiceManager");
    1064             : }
    1065             : 
    1066             : // XServiceInfo
    1067           0 : sal_Bool OServiceManager::supportsService(const OUString& ServiceName)
    1068             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1069             : {
    1070           0 :     return cppu::supportsService(this, ServiceName);
    1071             : }
    1072             : 
    1073             : // XServiceInfo
    1074           0 : Sequence< OUString > OServiceManager::getSupportedServiceNames()
    1075             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1076             : {
    1077           0 :     Sequence< OUString > seqNames(2);
    1078           0 :     seqNames[0] = "com.sun.star.lang.MultiServiceFactory";
    1079           0 :     seqNames[1] = "com.sun.star.lang.ServiceManager";
    1080           0 :     return seqNames;
    1081             : }
    1082             : 
    1083             : 
    1084           0 : Sequence< Reference< XInterface > > OServiceManager::queryServiceFactories(
    1085             :     const OUString& aServiceName, Reference< XComponentContext > const & )
    1086             : {
    1087           0 :     Sequence< Reference< XInterface > > ret;
    1088             : 
    1089           0 :     MutexGuard aGuard( m_mutex );
    1090             :     ::std::pair<
    1091             :           HashMultimap_OWString_Interface::iterator,
    1092             :           HashMultimap_OWString_Interface::iterator> p(
    1093           0 :               m_ServiceMap.equal_range( aServiceName ) );
    1094             : 
    1095           0 :     if (p.first == p.second) // no factories
    1096             :     {
    1097             :         // no service found, look for an implementation
    1098           0 :         HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.find( aServiceName );
    1099           0 :         if( aIt != m_ImplementationNameMap.end() )
    1100             :         {
    1101           0 :             Reference< XInterface > const & x = aIt->second;
    1102             :             // an implementation found
    1103           0 :             ret = Sequence< Reference< XInterface > >( &x, 1 );
    1104             :         }
    1105             :     }
    1106             :     else
    1107             :     {
    1108           0 :         ::std::vector< Reference< XInterface > > vec;
    1109           0 :         vec.reserve( 4 );
    1110           0 :         while (p.first != p.second)
    1111             :         {
    1112           0 :             vec.push_back( p.first->second );
    1113           0 :             ++p.first;
    1114             :         }
    1115           0 :         ret = Sequence< Reference< XInterface > >(
    1116           0 :             vec.empty() ? 0 : &vec[ 0 ], vec.size() );
    1117             :     }
    1118             : 
    1119           0 :     return ret;
    1120             : }
    1121             : 
    1122             : // XContentEnumerationAccess
    1123           0 : Reference<XEnumeration > OServiceManager::createContentEnumeration(
    1124             :     const OUString& aServiceName )
    1125             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1126             : {
    1127           0 :     check_undisposed();
    1128             :     Sequence< Reference< XInterface > > factories(
    1129           0 :         OServiceManager::queryServiceFactories( aServiceName, m_xContext ) );
    1130           0 :     if (factories.getLength())
    1131           0 :         return new ServiceEnumeration_Impl( factories );
    1132             :     else
    1133           0 :         return Reference< XEnumeration >();
    1134             : }
    1135             : 
    1136             : // XEnumeration
    1137           0 : Reference<XEnumeration > OServiceManager::createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception)
    1138             : {
    1139           0 :     check_undisposed();
    1140           0 :     MutexGuard aGuard( m_mutex );
    1141           0 :     return new ImplementationEnumeration_Impl( m_ImplementationMap );
    1142             : }
    1143             : 
    1144             : // XElementAccess
    1145           0 : Type OServiceManager::getElementType()
    1146             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1147             : {
    1148           0 :     check_undisposed();
    1149           0 :     return ::getCppuType( (const Reference< XInterface > *)0 );
    1150             : }
    1151             : 
    1152             : // XElementAccess
    1153           0 : sal_Bool OServiceManager::hasElements()
    1154             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1155             : {
    1156           0 :     check_undisposed();
    1157           0 :     MutexGuard aGuard( m_mutex );
    1158           0 :     return !m_ImplementationMap.empty();
    1159             : }
    1160             : 
    1161             : // XSet
    1162           0 : sal_Bool OServiceManager::has( const Any & Element )
    1163             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1164             : {
    1165           0 :     check_undisposed();
    1166           0 :     if( Element.getValueTypeClass() == TypeClass_INTERFACE )
    1167             :     {
    1168           0 :         Reference<XInterface > xEle( Element, UNO_QUERY_THROW );
    1169           0 :         MutexGuard aGuard( m_mutex );
    1170           0 :         return m_ImplementationMap.find( xEle ) !=
    1171           0 :             m_ImplementationMap.end();
    1172             :     }
    1173           0 :     else if (Element.getValueTypeClass() == TypeClass_STRING)
    1174             :     {
    1175             :         OUString const & implName =
    1176           0 :             *reinterpret_cast< OUString const * >(Element.getValue());
    1177           0 :         MutexGuard aGuard( m_mutex );
    1178           0 :         return m_ImplementationNameMap.find( implName ) !=
    1179           0 :             m_ImplementationNameMap.end();
    1180             :     }
    1181           0 :     return sal_False;
    1182             : }
    1183             : 
    1184             : // XSet
    1185           0 : void OServiceManager::insert( const Any & Element )
    1186             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception)
    1187             : {
    1188           0 :     check_undisposed();
    1189           0 :     if( Element.getValueTypeClass() != TypeClass_INTERFACE )
    1190             :     {
    1191             :         throw IllegalArgumentException(
    1192             :             OUString("no interface given!"),
    1193           0 :             Reference< XInterface >(), 0 );
    1194             :     }
    1195           0 :     Reference<XInterface > xEle( Element, UNO_QUERY_THROW );
    1196             : 
    1197             :     {
    1198           0 :     MutexGuard aGuard( m_mutex );
    1199           0 :     HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );
    1200           0 :     if( aIt != m_ImplementationMap.end() )
    1201             :     {
    1202             :         throw ElementExistException(
    1203             :             OUString("element already exists!"),
    1204           0 :             Reference< XInterface >() );
    1205             :     }
    1206             : 
    1207             :     // put into the implementation hashmap
    1208           0 :     m_ImplementationMap.insert( xEle );
    1209             : 
    1210             :     // put into the implementation name hashmap
    1211           0 :     Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) );
    1212           0 :     if( xInfo.is() )
    1213             :     {
    1214           0 :         OUString aImplName = xInfo->getImplementationName();
    1215           0 :         if( !aImplName.isEmpty() )
    1216           0 :             m_ImplementationNameMap[ aImplName ] = xEle;
    1217             : 
    1218             :         //put into the service map
    1219           0 :         Sequence< OUString > aServiceNames = xInfo->getSupportedServiceNames();
    1220           0 :         const OUString * pArray = aServiceNames.getConstArray();
    1221           0 :         for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
    1222             :         {
    1223             :             m_ServiceMap.insert( HashMultimap_OWString_Interface::value_type(
    1224           0 :                 pArray[i], *(Reference<XInterface > *)Element.getValue() ) );
    1225           0 :         }
    1226           0 :     }
    1227             :     }
    1228             :     // add the disposing listener to the factory
    1229           0 :     Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) );
    1230           0 :     if( xComp.is() )
    1231           0 :         xComp->addEventListener( getFactoryListener() );
    1232           0 : }
    1233             : 
    1234             : // helper function
    1235           0 : sal_Bool OServiceManager::haveFactoryWithThisImplementation(const OUString& aImplName)
    1236             : {
    1237           0 :     return ( m_ImplementationNameMap.find(aImplName) != m_ImplementationNameMap.end());
    1238             : }
    1239             : 
    1240             : // XSet
    1241           0 : void OServiceManager::remove( const Any & Element )
    1242             :      throw(::com::sun::star::lang::IllegalArgumentException,
    1243             :            ::com::sun::star::container::NoSuchElementException,
    1244             :            ::com::sun::star::uno::RuntimeException, std::exception)
    1245             : {
    1246           0 :     if (is_disposed())
    1247           0 :         return;
    1248             : 
    1249           0 :     Reference<XInterface > xEle;
    1250           0 :     if (Element.getValueTypeClass() == TypeClass_INTERFACE)
    1251             :     {
    1252           0 :         xEle.set( Element, UNO_QUERY_THROW );
    1253             :     }
    1254           0 :     else if (Element.getValueTypeClass() == TypeClass_STRING)
    1255             :     {
    1256             :         OUString const & implName =
    1257           0 :             *reinterpret_cast< OUString const * >(Element.getValue());
    1258           0 :         MutexGuard aGuard( m_mutex );
    1259             :         HashMap_OWString_Interface::const_iterator const iFind(
    1260           0 :             m_ImplementationNameMap.find( implName ) );
    1261           0 :         if (iFind == m_ImplementationNameMap.end())
    1262             :         {
    1263             :             throw NoSuchElementException(
    1264             :                 OUString("element is not in: ")
    1265           0 :                 + implName, static_cast< OWeakObject * >(this) );
    1266             :         }
    1267           0 :         xEle = iFind->second;
    1268             :     }
    1269             :     else
    1270             :     {
    1271             :         throw IllegalArgumentException(
    1272             :             OUString(
    1273             :                           "neither interface nor string given!"),
    1274           0 :             Reference< XInterface >(), 0 );
    1275             :     }
    1276             : 
    1277             :     // remove the disposing listener from the factory
    1278           0 :     Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) );
    1279           0 :     if( xComp.is() )
    1280           0 :         xComp->removeEventListener( getFactoryListener() );
    1281             : 
    1282           0 :     MutexGuard aGuard( m_mutex );
    1283           0 :     HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );
    1284           0 :     if( aIt == m_ImplementationMap.end() )
    1285             :     {
    1286             :         throw NoSuchElementException(
    1287             :             OUString("element is not in!"),
    1288           0 :             static_cast< OWeakObject * >(this) );
    1289             :     }
    1290             :     //First remove all factories which have been loaded by ORegistryServiceManager.
    1291           0 :     m_SetLoadedFactories.erase( *aIt);
    1292             :     //Remove from the implementation map. It contains all factories of m_SetLoadedFactories
    1293             :     //which have been added directly through XSet, that is not via ORegistryServiceManager
    1294           0 :     m_ImplementationMap.erase( aIt );
    1295             : 
    1296             :     // remove from the implementation name hashmap
    1297           0 :     Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) );
    1298           0 :     if( xInfo.is() )
    1299             :     {
    1300           0 :         OUString aImplName = xInfo->getImplementationName();
    1301           0 :         if( !aImplName.isEmpty() )
    1302           0 :             m_ImplementationNameMap.erase( aImplName );
    1303             :     }
    1304             : 
    1305             :     //remove from the service map
    1306           0 :     Reference<XServiceInfo > xSF( Reference<XServiceInfo >::query( xEle ) );
    1307           0 :     if( xSF.is() )
    1308             :     {
    1309           0 :         Sequence< OUString > aServiceNames = xSF->getSupportedServiceNames();
    1310           0 :         const OUString * pArray = aServiceNames.getConstArray();
    1311           0 :         for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
    1312             :         {
    1313             :             pair<HashMultimap_OWString_Interface::iterator, HashMultimap_OWString_Interface::iterator> p =
    1314           0 :                 m_ServiceMap.equal_range( pArray[i] );
    1315             : 
    1316           0 :             while( p.first != p.second )
    1317             :             {
    1318           0 :                 if( xEle == (*p.first).second )
    1319             :                 {
    1320           0 :                     m_ServiceMap.erase( p.first );
    1321           0 :                     break;
    1322             :                 }
    1323           0 :                 ++p.first;
    1324             :             }
    1325           0 :         }
    1326           0 :     }
    1327             : }
    1328             : 
    1329             : /*****************************************************************************
    1330             :     class ORegistryServiceManager
    1331             : *****************************************************************************/
    1332             : class ORegistryServiceManager : public OServiceManager
    1333             : {
    1334             : public:
    1335             :     ORegistryServiceManager( Reference< XComponentContext > const & xContext );
    1336             :     virtual ~ORegistryServiceManager();
    1337             : 
    1338             :     // XInitialization
    1339             :     void SAL_CALL initialize(const Sequence< Any >& Arguments)
    1340             :         throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1341             : 
    1342             :     // XServiceInfo
    1343           0 :     OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
    1344           0 :         { return OUString("com.sun.star.comp.stoc.ORegistryServiceManager"); }
    1345             : 
    1346             :     Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1347             : 
    1348             :     // XMultiServiceFactory
    1349             :     Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1350             : 
    1351             :     // XContentEnumerationAccess
    1352             :     //Sequence< OUString >          getAvailableServiceNames() throw( (Exception) );
    1353             :     Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1354             : 
    1355             :     // XComponent
    1356             :     void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1357             : 
    1358             :     // OServiceManager
    1359             :     Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo()
    1360             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1361             :     Any SAL_CALL getPropertyValue(const OUString& PropertyName)
    1362             :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    1363             : 
    1364             : protected:
    1365             :     //OServiceManager
    1366             :     Sequence< Reference< XInterface > > queryServiceFactories(
    1367             :         const OUString& aServiceName, Reference< XComponentContext > const & xContext ) SAL_OVERRIDE;
    1368             : private:
    1369             :     Reference<XRegistryKey >        getRootKey();
    1370             :     Reference<XInterface > loadWithImplementationName(
    1371             :         const OUString & rImplName, Reference< XComponentContext > const & xContext );
    1372             :     Sequence<OUString>          getFromServiceName(const OUString& serviceName);
    1373             :     Reference<XInterface > loadWithServiceName(
    1374             :         const OUString & rImplName, Reference< XComponentContext > const & xContext );
    1375             :     void                        fillAllNamesFromRegistry( HashSet_OWString & );
    1376             : 
    1377             :     sal_Bool                    m_searchedRegistry;
    1378             :     Reference<XSimpleRegistry > m_xRegistry;    // readonly property Registry
    1379             :     Reference<XRegistryKey >    m_xRootKey;
    1380             : 
    1381             : #if OSL_DEBUG_LEVEL > 0
    1382             :     bool m_init;
    1383             : #endif
    1384             : };
    1385             : 
    1386             : /**
    1387             :  * Create a ServiceManager
    1388             :  */
    1389           0 : ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > const & xContext )
    1390             :     : OServiceManager( xContext )
    1391           0 :     , m_searchedRegistry(sal_False)
    1392             : #if OSL_DEBUG_LEVEL > 0
    1393             :     , m_init( false )
    1394             : #endif
    1395             : {
    1396           0 : }
    1397             : 
    1398             : /**
    1399             :  * Destroy the ServiceManager
    1400             :  */
    1401           0 : ORegistryServiceManager::~ORegistryServiceManager()
    1402             : {
    1403           0 : }
    1404             : 
    1405             : // XComponent
    1406           0 : void ORegistryServiceManager::dispose()
    1407             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1408             : {
    1409           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
    1410           0 :         return;
    1411           0 :     OServiceManager::dispose();
    1412             :     // dispose
    1413           0 :     MutexGuard aGuard( m_mutex );
    1414             :     // erase all members
    1415           0 :     m_xRegistry.clear();
    1416           0 :     m_xRootKey.clear();
    1417             : }
    1418             : 
    1419             : /**
    1420             :  * Return the root key of the registry. The Default registry service is ordered
    1421             :  * if no registry is set.
    1422             :  */
    1423             : //Reference<XServiceProvider > create_DefaultRegistry_ServiceProvider();
    1424             : 
    1425           0 : Reference<XRegistryKey > ORegistryServiceManager::getRootKey()
    1426             : {
    1427           0 :     if( !m_xRootKey.is() )
    1428             :     {
    1429           0 :         MutexGuard aGuard( m_mutex );
    1430             :         //  DefaultRegistry suchen !!!!
    1431           0 :         if( !m_xRegistry.is() && !m_searchedRegistry )
    1432             :         {
    1433             :             // merken, es wird nur einmal gesucht
    1434           0 :             m_searchedRegistry = sal_True;
    1435             : 
    1436             :             m_xRegistry.set(
    1437             :                 createInstanceWithContext(
    1438             :                     OUString("com.sun.star.registry.DefaultRegistry"),
    1439           0 :                     m_xContext ),
    1440           0 :                 UNO_QUERY );
    1441             :         }
    1442           0 :         if( m_xRegistry.is() && !m_xRootKey.is() )
    1443           0 :             m_xRootKey = m_xRegistry->getRootKey();
    1444             :     }
    1445             : 
    1446           0 :     return m_xRootKey;
    1447             : }
    1448             : 
    1449             : /**
    1450             :  * Create a service provider from the registry with an implementation name
    1451             :  */
    1452           0 : Reference<XInterface > ORegistryServiceManager::loadWithImplementationName(
    1453             :     const OUString& name, Reference< XComponentContext > const & xContext )
    1454             : {
    1455           0 :     Reference<XInterface > ret;
    1456             : 
    1457           0 :     Reference<XRegistryKey > xRootKey = getRootKey();
    1458           0 :     if( !xRootKey.is() )
    1459           0 :         return ret;
    1460             : 
    1461             :     try
    1462             :     {
    1463           0 :         OUString implementationName = "/IMPLEMENTATIONS/" + name;
    1464           0 :         Reference<XRegistryKey > xImpKey = m_xRootKey->openKey(implementationName);
    1465             : 
    1466           0 :         if( xImpKey.is() )
    1467             :         {
    1468           0 :             Reference< lang::XMultiServiceFactory > xMgr;
    1469           0 :             if (xContext.is())
    1470           0 :                 xMgr.set( xContext->getServiceManager(), UNO_QUERY_THROW );
    1471             :             else
    1472           0 :                 xMgr.set( this );
    1473           0 :             ret = createSingleRegistryFactory( xMgr, name, xImpKey );
    1474           0 :             insert( makeAny( ret ) );
    1475             :             // Remember this factory as loaded in contrast to inserted ( XSet::insert)
    1476             :             // factories. Those loaded factories in this set are candidates for being
    1477             :             // released on an unloading notification.
    1478           0 :             m_SetLoadedFactories.insert( ret);
    1479           0 :         }
    1480             :     }
    1481           0 :     catch (InvalidRegistryException &)
    1482             :     {
    1483             :     }
    1484             : 
    1485           0 :     return ret;
    1486             : }
    1487             : 
    1488             : /**
    1489             :  * Return all implementation out of the registry.
    1490             :  */
    1491           0 : Sequence<OUString> ORegistryServiceManager::getFromServiceName(
    1492             :     const OUString& serviceName )
    1493             : {
    1494           0 :     OUStringBuffer buf;
    1495           0 :     buf.append( "/SERVICES/" );
    1496           0 :     buf.append( serviceName );
    1497           0 :     return retrieveAsciiValueList( m_xRegistry, buf.makeStringAndClear() );
    1498             : }
    1499             : 
    1500             : /**
    1501             :  * Create a service provider from the registry
    1502             :  */
    1503           0 : Reference<XInterface > ORegistryServiceManager::loadWithServiceName(
    1504             :     const OUString& serviceName, Reference< XComponentContext > const & xContext )
    1505             : {
    1506           0 :     Sequence<OUString> implEntries = getFromServiceName( serviceName );
    1507           0 :     for (sal_Int32 i = 0; i < implEntries.getLength(); i++)
    1508             :     {
    1509             :         Reference< XInterface > x(
    1510           0 :             loadWithImplementationName( implEntries.getConstArray()[i], xContext ) );
    1511           0 :         if (x.is())
    1512           0 :             return x;
    1513           0 :     }
    1514             : 
    1515           0 :     return Reference<XInterface >();
    1516             : }
    1517             : 
    1518             : /**
    1519             :  * Return a sequence of all service names from the registry.
    1520             :  */
    1521           0 : void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet )
    1522             : {
    1523           0 :     Reference<XRegistryKey > xRootKey = getRootKey();
    1524           0 :     if( !xRootKey.is() )
    1525           0 :         return;
    1526             : 
    1527             :     try
    1528             :     {
    1529           0 :         Reference<XRegistryKey > xServicesKey = xRootKey->openKey(
    1530           0 :             OUString("SERVICES") );
    1531             :         // root + /Services + /
    1532           0 :         if( xServicesKey.is() )
    1533             :         {
    1534           0 :             sal_Int32 nPrefix = xServicesKey->getKeyName().getLength() +1;
    1535           0 :             Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys();
    1536           0 :             for( sal_Int32 i = 0; i < aKeys.getLength(); i++ )
    1537           0 :                 rSet.insert( aKeys.getConstArray()[i]->getKeyName().copy( nPrefix ) );
    1538           0 :         }
    1539             :     }
    1540           0 :     catch (InvalidRegistryException &)
    1541             :     {
    1542           0 :     }
    1543             : }
    1544             : 
    1545             : // XInitialization
    1546           0 : void ORegistryServiceManager::initialize(const Sequence< Any >& Arguments)
    1547             :     throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
    1548             : {
    1549           0 :     check_undisposed();
    1550           0 :     MutexGuard aGuard( m_mutex );
    1551           0 :     if (Arguments.getLength() > 0)
    1552             :     {
    1553           0 :         m_xRootKey.clear();
    1554           0 :         Arguments[ 0 ] >>= m_xRegistry;
    1555           0 :     }
    1556             : #if OSL_DEBUG_LEVEL > 0
    1557             :     // to find all bootstrapping processes to be fixed...
    1558             :     OSL_ENSURE( !m_init, "### second init of service manager instance!" );
    1559             :     m_init = true;
    1560             : #endif
    1561           0 : }
    1562             : 
    1563             : // XMultiServiceFactory, XContentEnumeration
    1564           0 : Sequence< OUString > ORegistryServiceManager::getAvailableServiceNames()
    1565             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1566             : {
    1567           0 :     check_undisposed();
    1568           0 :     MutexGuard aGuard( m_mutex );
    1569             :     // all names
    1570           0 :     HashSet_OWString aNameSet;
    1571             : 
    1572             :     // all names from the registry
    1573           0 :     fillAllNamesFromRegistry( aNameSet );
    1574             : 
    1575           0 :     return OServiceManager::getUniqueAvailableServiceNames( aNameSet );
    1576             : }
    1577             : 
    1578             : // XServiceInfo
    1579           0 : Sequence< OUString > ORegistryServiceManager::getSupportedServiceNames()
    1580             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1581             : {
    1582           0 :     Sequence< OUString > seqNames(2);
    1583           0 :     seqNames[0] = "com.sun.star.lang.MultiServiceFactory";
    1584           0 :     seqNames[1] = "com.sun.star.lang.RegistryServiceManager";
    1585           0 :     return seqNames;
    1586             : }
    1587             : 
    1588             : 
    1589             : // OServiceManager
    1590           0 : Sequence< Reference< XInterface > > ORegistryServiceManager::queryServiceFactories(
    1591             :     const OUString& aServiceName, Reference< XComponentContext > const & xContext )
    1592             : {
    1593             :     Sequence< Reference< XInterface > > ret(
    1594           0 :         OServiceManager::queryServiceFactories( aServiceName, xContext ) );
    1595           0 :     if (ret.getLength())
    1596             :     {
    1597           0 :         return ret;
    1598             :     }
    1599             :     else
    1600             :     {
    1601           0 :         MutexGuard aGuard( m_mutex );
    1602           0 :         Reference< XInterface > x( loadWithServiceName( aServiceName, xContext ) );
    1603           0 :         if (! x.is())
    1604           0 :             x = loadWithImplementationName( aServiceName, xContext );
    1605           0 :         return Sequence< Reference< XInterface > >( &x, 1 );
    1606           0 :     }
    1607             : }
    1608             : 
    1609             : // XContentEnumerationAccess
    1610           0 : Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration(
    1611             :     const OUString& aServiceName )
    1612             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1613             : {
    1614           0 :     check_undisposed();
    1615           0 :     MutexGuard aGuard( ((ORegistryServiceManager *)this)->m_mutex );
    1616             :     // get all implementation names registered under this service name from the registry
    1617           0 :     Sequence<OUString> aImpls = ((ORegistryServiceManager *)this)->getFromServiceName( aServiceName );
    1618             :     // load and insert all factories specified by the registry
    1619             :     sal_Int32 i;
    1620           0 :     OUString aImplName;
    1621           0 :     for( i = 0; i < aImpls.getLength(); i++ )
    1622             :     {
    1623           0 :         aImplName = aImpls.getConstArray()[i];
    1624           0 :         if ( !haveFactoryWithThisImplementation(aImplName) )
    1625             :         {
    1626           0 :             loadWithImplementationName( aImplName, m_xContext );
    1627             :         }
    1628             :     }
    1629             :     // call the superclass to enumerate all contents
    1630           0 :     return OServiceManager::createContentEnumeration( aServiceName );
    1631             : }
    1632             : 
    1633             : // OServiceManager
    1634           0 : Reference<XPropertySetInfo > ORegistryServiceManager::getPropertySetInfo()
    1635             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
    1636             : {
    1637           0 :     check_undisposed();
    1638           0 :     if (! m_xPropertyInfo.is())
    1639             :     {
    1640           0 :         Sequence< beans::Property > seq( 2 );
    1641           0 :         seq[ 0 ] = beans::Property(
    1642           0 :             "DefaultContext", -1, ::getCppuType( &m_xContext ), 0 );
    1643           0 :         seq[ 1 ] = beans::Property(
    1644           0 :             "Registry", -1, ::getCppuType( &m_xRegistry ),
    1645           0 :             beans::PropertyAttribute::READONLY );
    1646           0 :         Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) );
    1647             : 
    1648           0 :         MutexGuard aGuard( m_mutex );
    1649           0 :         if (! m_xPropertyInfo.is())
    1650             :         {
    1651           0 :             m_xPropertyInfo = xInfo;
    1652           0 :         }
    1653             :     }
    1654           0 :     return m_xPropertyInfo;
    1655             : }
    1656             : 
    1657           0 : Any ORegistryServiceManager::getPropertyValue(const OUString& PropertyName)
    1658             :     throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
    1659             : {
    1660           0 :     check_undisposed();
    1661           0 :     if ( PropertyName == "Registry" )
    1662             :     {
    1663           0 :         MutexGuard aGuard( m_mutex );
    1664           0 :         if( m_xRegistry.is() )
    1665           0 :             return makeAny( m_xRegistry );
    1666             :         else
    1667           0 :             return Any();
    1668             :     }
    1669           0 :     return OServiceManager::getPropertyValue( PropertyName );
    1670             : }
    1671             : 
    1672             : } // namespace
    1673             : 
    1674             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
    1675           0 : com_sun_star_comp_stoc_OServiceManager_get_implementation(
    1676             :     css::uno::XComponentContext *context,
    1677             :     css::uno::Sequence<css::uno::Any> const &)
    1678             : {
    1679           0 :     return cppu::acquire(new OServiceManager(context));
    1680             : }
    1681             : 
    1682             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
    1683           0 : com_sun_star_comp_stoc_ORegistryServiceManager_get_implementation(
    1684             :     css::uno::XComponentContext *context,
    1685             :     css::uno::Sequence<css::uno::Any> const &)
    1686             : {
    1687           0 :     return cppu::acquire(new ORegistryServiceManager(context));
    1688             : }
    1689             : 
    1690             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
    1691           0 : com_sun_star_comp_stoc_OServiceManagerWrapper_get_implementation(
    1692             :     css::uno::XComponentContext *context,
    1693             :     css::uno::Sequence<css::uno::Any> const &)
    1694             : {
    1695           0 :     return cppu::acquire(new OServiceManagerWrapper(context));
    1696             : }
    1697             : 
    1698             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10