LCOV - code coverage report
Current view: top level - framework/source/uifactory - uielementfactorymanager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 241 0.0 %
Date: 2014-04-14 Functions: 0 29 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <uifactory/configurationaccessfactorymanager.hxx>
      23             : #include <helper/mischelper.hxx>
      24             : 
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      28             : #include <com/sun/star/container/XContainer.hpp>
      29             : #include <com/sun/star/container/XContainerListener.hpp>
      30             : #include <com/sun/star/lang/XServiceInfo.hpp>
      31             : #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
      32             : #include <com/sun/star/frame/ModuleManager.hpp>
      33             : #include <com/sun/star/frame/XFrame.hpp>
      34             : #include <com/sun/star/frame/XModuleManager2.hpp>
      35             : #include <com/sun/star/ui/XUIElementFactoryManager.hpp>
      36             : 
      37             : #include <rtl/ustrbuf.hxx>
      38             : #include <cppuhelper/basemutex.hxx>
      39             : #include <cppuhelper/compbase2.hxx>
      40             : #include <cppuhelper/supportsservice.hxx>
      41             : #include <vcl/svapp.hxx>
      42             : 
      43             : using namespace com::sun::star::uno;
      44             : using namespace com::sun::star::lang;
      45             : using namespace com::sun::star::beans;
      46             : using namespace com::sun::star::frame;
      47             : using namespace com::sun::star::configuration;
      48             : using namespace com::sun::star::container;
      49             : using namespace ::com::sun::star::ui;
      50             : using namespace ::com::sun::star::frame;
      51             : using namespace framework;
      52             : 
      53             : namespace framework
      54             : {
      55             : 
      56             : // global function needed by both implementations
      57           0 : static OUString getHashKeyFromStrings( const OUString& aType, const OUString& aName, const OUString& aModuleName )
      58             : {
      59           0 :     OUStringBuffer aKey( aType );
      60           0 :     aKey.appendAscii( "^" );
      61           0 :     aKey.append( aName );
      62           0 :     aKey.appendAscii( "^" );
      63           0 :     aKey.append( aModuleName );
      64           0 :     return aKey.makeStringAndClear();
      65             : }
      66             : 
      67           0 : ConfigurationAccess_FactoryManager::ConfigurationAccess_FactoryManager( const Reference< XComponentContext >& rxContext, const OUString& _sRoot ) :
      68             :     m_aPropType( "Type" ),
      69             :     m_aPropName( "Name" ),
      70             :     m_aPropModule( "Module" ),
      71             :     m_aPropFactory( "FactoryImplementation" ),
      72             :     m_sRoot(_sRoot),
      73           0 :     m_bConfigAccessInitialized( false )
      74             : {
      75           0 :     m_xConfigProvider = theDefaultProvider::get( rxContext );
      76           0 : }
      77             : 
      78           0 : ConfigurationAccess_FactoryManager::~ConfigurationAccess_FactoryManager()
      79             : {
      80             :     // SAFE
      81           0 :     osl::MutexGuard g(m_aMutex);
      82             : 
      83           0 :     Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
      84           0 :     if ( xContainer.is() )
      85           0 :         xContainer->removeContainerListener(m_xConfigListener);
      86           0 : }
      87             : 
      88           0 : OUString ConfigurationAccess_FactoryManager::getFactorySpecifierFromTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule ) const
      89             : {
      90             :     // SAFE
      91           0 :     osl::MutexGuard g(m_aMutex);
      92             : 
      93             :     FactoryManagerMap::const_iterator pIter =
      94           0 :         m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rModule ));
      95           0 :     if ( pIter != m_aFactoryManagerMap.end() )
      96           0 :         return pIter->second;
      97             :     else
      98             :     {
      99           0 :         pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, OUString() ));
     100           0 :         if ( pIter != m_aFactoryManagerMap.end() )
     101           0 :             return pIter->second;
     102             :         else
     103             :         {
     104             :             // Support factories which uses a defined prefix before the ui name.
     105           0 :             sal_Int32 nIndex = rName.indexOf( '_' );
     106           0 :             if ( nIndex > 0 )
     107             :             {
     108           0 :                 OUString aName = rName.copy( 0, nIndex+1 );
     109           0 :                 pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, aName, OUString() ));
     110           0 :                 if ( pIter != m_aFactoryManagerMap.end() )
     111           0 :                     return pIter->second;
     112             :             }
     113             : 
     114           0 :             pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, OUString(), OUString() ));
     115           0 :             if ( pIter != m_aFactoryManagerMap.end() )
     116           0 :                 return pIter->second;
     117             :         }
     118             :     }
     119             : 
     120           0 :     return OUString();
     121             : }
     122             : 
     123           0 : void ConfigurationAccess_FactoryManager::addFactorySpecifierToTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule, const OUString& rServiceSpecifier )
     124             : {
     125             :     // SAFE
     126           0 :     osl::MutexGuard g(m_aMutex);
     127             : 
     128           0 :     OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
     129             : 
     130           0 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
     131             : 
     132           0 :     if ( pIter != m_aFactoryManagerMap.end() )
     133           0 :         throw ElementExistException();
     134             :     else
     135           0 :         m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, rServiceSpecifier ));
     136           0 : }
     137             : 
     138           0 : void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule )
     139             : {
     140             :     // SAFE
     141           0 :     osl::MutexGuard g(m_aMutex);
     142             : 
     143           0 :     OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
     144             : 
     145           0 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
     146             : 
     147           0 :     if ( pIter == m_aFactoryManagerMap.end() )
     148           0 :         throw NoSuchElementException();
     149             :     else
     150           0 :         m_aFactoryManagerMap.erase( aHashKey );
     151           0 : }
     152             : 
     153           0 : Sequence< Sequence< PropertyValue > > ConfigurationAccess_FactoryManager::getFactoriesDescription() const
     154             : {
     155             :     // SAFE
     156           0 :     osl::MutexGuard g(m_aMutex);
     157             : 
     158           0 :     Sequence< Sequence< PropertyValue > > aSeqSeq;
     159             : 
     160           0 :     sal_Int32 nIndex( 0 );
     161           0 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.begin();
     162           0 :     while ( pIter != m_aFactoryManagerMap.end() )
     163             :     {
     164           0 :         OUString aFactory = pIter->first;
     165           0 :         if ( !aFactory.isEmpty() )
     166             :         {
     167           0 :             sal_Int32                 nToken = 0;
     168           0 :             Sequence< PropertyValue > aSeq( 1 );
     169             : 
     170           0 :             aSeqSeq.realloc( aSeqSeq.getLength() + 1 );
     171           0 :             aSeq[0].Name  = m_aPropType;
     172           0 :             aSeq[0].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     173           0 :             if ( nToken > 0 )
     174             :             {
     175           0 :                 aSeq.realloc( 2 );
     176           0 :                 aSeq[1].Name  = m_aPropName;
     177           0 :                 aSeq[1].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     178           0 :                 if ( nToken > 0 )
     179             :                 {
     180           0 :                     aSeq.realloc( 3 );
     181           0 :                     aSeq[2].Name  = m_aPropModule;
     182           0 :                     aSeq[2].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     183             :                 }
     184             :             }
     185             : 
     186           0 :             aSeqSeq[nIndex++] = aSeq;
     187             :         }
     188             : 
     189           0 :         ++pIter;
     190           0 :     }
     191             : 
     192           0 :     return aSeqSeq;
     193             : }
     194             : 
     195             : // container.XContainerListener
     196           0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception)
     197             : {
     198           0 :     OUString   aType;
     199           0 :     OUString   aName;
     200           0 :     OUString   aModule;
     201           0 :     OUString   aService;
     202             : 
     203             :     // SAFE
     204           0 :     osl::MutexGuard g(m_aMutex);
     205             : 
     206           0 :     if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
     207             :     {
     208             :         // Create hash key from type, name and module as they are together a primary key to
     209             :         // the UNO service that implements a user interface factory.
     210           0 :         OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
     211           0 :         m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
     212           0 :     }
     213           0 : }
     214             : 
     215           0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception)
     216             : {
     217           0 :     OUString   aType;
     218           0 :     OUString   aName;
     219           0 :     OUString   aModule;
     220           0 :     OUString   aService;
     221             : 
     222             :     // SAFE
     223           0 :     osl::MutexGuard g(m_aMutex);
     224             : 
     225           0 :     if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
     226             :     {
     227             :         // Create hash key from command and model as they are together a primary key to
     228             :         // the UNO service that implements the popup menu controller.
     229           0 :         OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
     230           0 :         m_aFactoryManagerMap.erase( aHashKey );
     231           0 :     }
     232           0 : }
     233             : 
     234           0 : void SAL_CALL ConfigurationAccess_FactoryManager::elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception)
     235             : {
     236           0 :     OUString   aType;
     237           0 :     OUString   aName;
     238           0 :     OUString   aModule;
     239           0 :     OUString   aService;
     240             : 
     241             :     // SAFE
     242           0 :     osl::MutexGuard g(m_aMutex);
     243             : 
     244           0 :     if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService ))
     245             :     {
     246             :         // Create hash key from command and model as they are together a primary key to
     247             :         // the UNO service that implements the popup menu controller.
     248           0 :         OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule ));
     249           0 :         m_aFactoryManagerMap.erase( aHashKey );
     250           0 :         m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
     251           0 :     }
     252           0 : }
     253             : 
     254             : // lang.XEventListener
     255           0 : void SAL_CALL ConfigurationAccess_FactoryManager::disposing( const EventObject& ) throw(RuntimeException, std::exception)
     256             : {
     257             :     // SAFE
     258             :     // remove our reference to the config access
     259           0 :     osl::MutexGuard g(m_aMutex);
     260           0 :     m_xConfigAccess.clear();
     261           0 : }
     262             : 
     263           0 : void ConfigurationAccess_FactoryManager::readConfigurationData()
     264             : {
     265             :     // SAFE
     266           0 :     osl::MutexGuard g(m_aMutex);
     267             : 
     268           0 :     if ( !m_bConfigAccessInitialized )
     269             :     {
     270           0 :         Sequence< Any > aArgs( 1 );
     271           0 :         PropertyValue   aPropValue;
     272             : 
     273           0 :         aPropValue.Name  = "nodepath";
     274           0 :         aPropValue.Value <<= m_sRoot;
     275           0 :         aArgs[0] <<= aPropValue;
     276             : 
     277             :         try
     278             :         {
     279           0 :             m_xConfigAccess.set( m_xConfigProvider->createInstanceWithArguments(
     280           0 :                         "com.sun.star.configuration.ConfigurationAccess", aArgs ), UNO_QUERY );
     281             :         }
     282           0 :         catch ( const WrappedTargetException& )
     283             :         {
     284             :         }
     285             : 
     286           0 :         m_bConfigAccessInitialized = true;
     287             :     }
     288             : 
     289           0 :     if ( m_xConfigAccess.is() )
     290             :     {
     291           0 :         Sequence< OUString >   aUIElementFactories = m_xConfigAccess->getElementNames();
     292             : 
     293           0 :         OUString             aType;
     294           0 :         OUString             aName;
     295           0 :         OUString             aModule;
     296           0 :         OUString             aService;
     297           0 :         OUString             aHashKey;
     298           0 :         Reference< XPropertySet > xPropertySet;
     299           0 :         for ( sal_Int32 i = 0; i < aUIElementFactories.getLength(); i++ )
     300             :         {
     301           0 :             if ( impl_getElementProps( m_xConfigAccess->getByName( aUIElementFactories[i] ), aType, aName, aModule, aService ))
     302             :             {
     303             :                 // Create hash key from type, name and module as they are together a primary key to
     304             :                 // the UNO service that implements the user interface element factory.
     305           0 :                 aHashKey = getHashKeyFromStrings( aType, aName, aModule );
     306           0 :                 m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
     307             :             }
     308             :         }
     309             : 
     310           0 :         Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
     311           0 :         if ( xContainer.is() )
     312             :         {
     313           0 :             m_xConfigListener = new WeakContainerListener(this);
     314           0 :             xContainer->addContainerListener(m_xConfigListener);
     315           0 :         }
     316           0 :     }
     317           0 : }
     318             : 
     319           0 : bool ConfigurationAccess_FactoryManager::impl_getElementProps( const Any& aElement, OUString& rType, OUString& rName, OUString& rModule, OUString& rServiceSpecifier ) const
     320             : {
     321           0 :     Reference< XPropertySet > xPropertySet;
     322           0 :     aElement >>= xPropertySet;
     323             : 
     324           0 :     if ( xPropertySet.is() )
     325             :     {
     326             :         try
     327             :         {
     328           0 :             xPropertySet->getPropertyValue( m_aPropType ) >>= rType;
     329           0 :             xPropertySet->getPropertyValue( m_aPropName ) >>= rName;
     330           0 :             xPropertySet->getPropertyValue( m_aPropModule ) >>= rModule;
     331           0 :             xPropertySet->getPropertyValue( m_aPropFactory ) >>= rServiceSpecifier;
     332             :         }
     333           0 :         catch ( const com::sun::star::beans::UnknownPropertyException& )
     334             :         {
     335           0 :             return false;
     336             :         }
     337           0 :         catch ( const com::sun::star::lang::WrappedTargetException& )
     338             :         {
     339           0 :             return false;
     340             :         }
     341             :     }
     342             : 
     343           0 :     return true;
     344             : }
     345             : 
     346             : } // framework
     347             : 
     348             : namespace {
     349             : 
     350             : typedef ::cppu::WeakComponentImplHelper2<
     351             :     css::lang::XServiceInfo,
     352             :     css::ui::XUIElementFactoryManager> UIElementFactoryManager_BASE;
     353             : 
     354             : class UIElementFactoryManager : private cppu::BaseMutex,
     355             :                                 public UIElementFactoryManager_BASE
     356             : {
     357             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     358             : public:
     359             :     UIElementFactoryManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
     360             :     virtual ~UIElementFactoryManager();
     361             : 
     362           0 :     virtual OUString SAL_CALL getImplementationName()
     363             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     364             :     {
     365           0 :         return OUString("com.sun.star.comp.framework.UIElementFactoryManager");
     366             :     }
     367             : 
     368           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
     369             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     370             :     {
     371           0 :         return cppu::supportsService(this, ServiceName);
     372             :     }
     373             : 
     374           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
     375             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     376             :     {
     377           0 :         css::uno::Sequence< OUString > aSeq(1);
     378           0 :         aSeq[0] = OUString("com.sun.star.ui.UIElementFactoryManager");
     379           0 :         return aSeq;
     380             :     }
     381             : 
     382             :     // XUIElementFactory
     383             :     virtual css::uno::Reference< css::ui::XUIElement > SAL_CALL createUIElement( const OUString& ResourceURL, const css::uno::Sequence< css::beans::PropertyValue >& Args ) throw (css::container::NoSuchElementException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     384             : 
     385             :     // XUIElementFactoryRegistration
     386             :     virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getRegisteredFactories(  ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     387             :     virtual css::uno::Reference< css::ui::XUIElementFactory > SAL_CALL getFactory( const OUString& ResourceURL, const OUString& ModuleIdentifier ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     388             :     virtual void SAL_CALL registerFactory( const OUString& aType, const OUString& aName, const OUString& aModuleIdentifier, const OUString& aFactoryImplementationName ) throw (css::container::ElementExistException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     389             :     virtual void SAL_CALL deregisterFactory( const OUString& aType, const OUString& aName, const OUString& aModuleIdentifier ) throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     390             : 
     391             : private:
     392             :     bool                                                  m_bConfigRead;
     393             :     css::uno::Reference< css::uno::XComponentContext >        m_xContext;
     394             :     ConfigurationAccess_FactoryManager*                       m_pConfigAccess;
     395             : };
     396             : 
     397           0 : UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentContext >& rxContext ) :
     398             :     UIElementFactoryManager_BASE(m_aMutex),
     399             :     m_bConfigRead( false ),
     400           0 :     m_xContext(rxContext)
     401             : {
     402             :     m_pConfigAccess = new ConfigurationAccess_FactoryManager(rxContext,
     403           0 :             "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories");
     404           0 :     m_pConfigAccess->acquire();
     405           0 : }
     406             : 
     407           0 : UIElementFactoryManager::~UIElementFactoryManager()
     408             : {
     409           0 :     disposing();
     410           0 : }
     411             : 
     412           0 : void SAL_CALL UIElementFactoryManager::disposing()
     413             : {
     414           0 :     osl::MutexGuard g(rBHelper.rMutex);
     415           0 :     if (m_pConfigAccess)
     416             :     {
     417             :         // reduce reference count
     418           0 :         m_pConfigAccess->release();
     419           0 :         m_pConfigAccess = 0;
     420           0 :     }
     421           0 : }
     422             : 
     423             : // XUIElementFactory
     424           0 : Reference< XUIElement > SAL_CALL UIElementFactoryManager::createUIElement(
     425             :     const OUString& ResourceURL,
     426             :     const Sequence< PropertyValue >& Args )
     427             : throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception )
     428             : {
     429           0 :     Reference< XFrame > xFrame;
     430             :     { // SAFE
     431           0 :     osl::MutexGuard g(rBHelper.rMutex);
     432             : 
     433           0 :     if ( !m_bConfigRead )
     434             :     {
     435           0 :         m_bConfigRead = true;
     436           0 :         m_pConfigAccess->readConfigurationData();
     437             :     }
     438             : 
     439             :     // Retrieve the frame instance from the arguments to determine the module identifier. This must be provided
     440             :     // to the search function. An empty module identifier is provided if the frame is missing or the module id cannot
     441             :     // retrieve from it.
     442           0 :     for ( int i = 0; i < Args.getLength(); i++ )
     443             :     {
     444           0 :         if ( Args[i].Name == "Frame")
     445           0 :             Args[i].Value >>= xFrame;
     446           0 :     }
     447             :     } // SAFE
     448             : 
     449           0 :     Reference< XModuleManager2 > xManager = ModuleManager::create( m_xContext );
     450             : 
     451             :     // Determine the module identifier
     452             :     try
     453             :     {
     454           0 :         OUString aModuleId;
     455           0 :         if ( xFrame.is() && xManager.is() )
     456           0 :             aModuleId = xManager->identify( xFrame );
     457             : 
     458           0 :         Reference< XUIElementFactory > xUIElementFactory = getFactory( ResourceURL, aModuleId );
     459           0 :         if ( xUIElementFactory.is() )
     460           0 :             return xUIElementFactory->createUIElement( ResourceURL, Args );
     461             :     }
     462           0 :     catch ( const UnknownModuleException& )
     463             :     {
     464             :     }
     465             : 
     466           0 :     throw NoSuchElementException();
     467             : }
     468             : 
     469             : // XUIElementFactoryRegistration
     470           0 : Sequence< Sequence< PropertyValue > > SAL_CALL UIElementFactoryManager::getRegisteredFactories()
     471             : throw ( RuntimeException, std::exception )
     472             : {
     473             :     // SAFE
     474           0 :     osl::MutexGuard g(rBHelper.rMutex);
     475             : 
     476           0 :     if ( !m_bConfigRead )
     477             :     {
     478           0 :         m_bConfigRead = true;
     479           0 :         m_pConfigAccess->readConfigurationData();
     480             :     }
     481             : 
     482           0 :     return m_pConfigAccess->getFactoriesDescription();
     483             : }
     484             : 
     485           0 : Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( const OUString& aResourceURL, const OUString& aModuleId )
     486             : throw ( RuntimeException, std::exception )
     487             : {
     488           0 :     OUString aServiceSpecifier;
     489             :     { // SAFE
     490           0 :     osl::MutexGuard g(rBHelper.rMutex);
     491             : 
     492           0 :     if ( !m_bConfigRead )
     493             :     {
     494           0 :         m_bConfigRead = true;
     495           0 :         m_pConfigAccess->readConfigurationData();
     496             :     }
     497             : 
     498           0 :     OUString aType;
     499           0 :     OUString aName;
     500             : 
     501           0 :     RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
     502             : 
     503           0 :     aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     504             :     } // SAFE
     505             : 
     506           0 :     if ( !aServiceSpecifier.isEmpty() ) try
     507             :     {
     508           0 :         return Reference< XUIElementFactory >(m_xContext->getServiceManager()->
     509           0 :                 createInstanceWithContext(aServiceSpecifier, m_xContext), UNO_QUERY);
     510             :     }
     511           0 :     catch ( const css::loader::CannotActivateFactoryException& )
     512             :     {
     513             :         SAL_WARN("fwk.uielement", aServiceSpecifier <<
     514             :                 " not available. This should happen only on mobile platforms.");
     515             :     }
     516           0 :     return Reference< XUIElementFactory >();
     517             : }
     518             : 
     519           0 : void SAL_CALL UIElementFactoryManager::registerFactory( const OUString& aType, const OUString& aName, const OUString& aModuleId, const OUString& aFactoryImplementationName )
     520             : throw ( ElementExistException, RuntimeException, std::exception )
     521             : {
     522             :     // SAFE
     523           0 :     osl::MutexGuard g(rBHelper.rMutex);
     524             : 
     525           0 :     if ( !m_bConfigRead )
     526             :     {
     527           0 :         m_bConfigRead = true;
     528           0 :         m_pConfigAccess->readConfigurationData();
     529             :     }
     530             : 
     531           0 :     m_pConfigAccess->addFactorySpecifierToTypeNameModule( aType, aName, aModuleId, aFactoryImplementationName );
     532             :     // SAFE
     533           0 : }
     534             : 
     535           0 : void SAL_CALL UIElementFactoryManager::deregisterFactory( const OUString& aType, const OUString& aName, const OUString& aModuleId )
     536             : throw ( NoSuchElementException, RuntimeException, std::exception )
     537             : {
     538             :     // SAFE
     539           0 :     osl::MutexGuard g(rBHelper.rMutex);
     540             : 
     541           0 :     if ( !m_bConfigRead )
     542             :     {
     543           0 :         m_bConfigRead = true;
     544           0 :         m_pConfigAccess->readConfigurationData();
     545             :     }
     546             : 
     547           0 :     m_pConfigAccess->removeFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     548             :     // SAFE
     549           0 : }
     550             : 
     551           0 : struct Instance {
     552           0 :     explicit Instance(
     553             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     554             :         instance(static_cast<cppu::OWeakObject *>(
     555           0 :                     new UIElementFactoryManager(context)))
     556             :     {
     557           0 :     }
     558             : 
     559             :     css::uno::Reference<css::uno::XInterface> instance;
     560             : };
     561             : 
     562             : struct Singleton:
     563             :     public rtl::StaticWithArg<
     564             :         Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
     565             : {};
     566             : 
     567             : }
     568             : 
     569             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     570           0 : com_sun_star_comp_framework_UIElementFactoryManager_get_implementation(
     571             :     css::uno::XComponentContext *context,
     572             :     css::uno::Sequence<css::uno::Any> const &)
     573             : {
     574             :     return cppu::acquire(static_cast<cppu::OWeakObject *>(
     575           0 :             Singleton::get(context).instance.get()));
     576             : }
     577             : 
     578             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10