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

Generated by: LCOV version 1.10