LCOV - code coverage report
Current view: top level - framework/source/uifactory - uielementfactorymanager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 179 242 74.0 %
Date: 2014-11-03 Functions: 25 31 80.6 %
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      116334 : static OUString getHashKeyFromStrings( const OUString& aType, const OUString& aName, const OUString& aModuleName )
      58             : {
      59      116334 :     OUStringBuffer aKey( aType );
      60      116334 :     aKey.appendAscii( "^" );
      61      116334 :     aKey.append( aName );
      62      116334 :     aKey.appendAscii( "^" );
      63      116334 :     aKey.append( aModuleName );
      64      116334 :     return aKey.makeStringAndClear();
      65             : }
      66             : 
      67         168 : 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         168 :     m_bConfigAccessInitialized( false )
      74             : {
      75         168 :     m_xConfigProvider = theDefaultProvider::get( rxContext );
      76         168 : }
      77             : 
      78         492 : ConfigurationAccess_FactoryManager::~ConfigurationAccess_FactoryManager()
      79             : {
      80             :     // SAFE
      81         164 :     osl::MutexGuard g(m_aMutex);
      82             : 
      83         328 :     Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
      84         164 :     if ( xContainer.is() )
      85         324 :         xContainer->removeContainerListener(m_xConfigListener);
      86         328 : }
      87             : 
      88       40656 : OUString ConfigurationAccess_FactoryManager::getFactorySpecifierFromTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule ) const
      89             : {
      90             :     // SAFE
      91       40656 :     osl::MutexGuard g(m_aMutex);
      92             : 
      93             :     FactoryManagerMap::const_iterator pIter =
      94       40656 :         m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rModule ));
      95       40656 :     if ( pIter != m_aFactoryManagerMap.end() )
      96           0 :         return pIter->second;
      97             :     else
      98             :     {
      99       40656 :         pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, OUString() ));
     100       40656 :         if ( pIter != m_aFactoryManagerMap.end() )
     101        6950 :             return pIter->second;
     102             :         else
     103             :         {
     104             :             // Support factories which uses a defined prefix before the ui name.
     105       33706 :             sal_Int32 nIndex = rName.indexOf( '_' );
     106       33706 :             if ( nIndex > 0 )
     107             :             {
     108       11152 :                 OUString aName = rName.copy( 0, nIndex+1 );
     109       11152 :                 pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, aName, OUString() ));
     110       11152 :                 if ( pIter != m_aFactoryManagerMap.end() )
     111       11152 :                     return pIter->second;
     112             :             }
     113             : 
     114       22554 :             pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, OUString(), OUString() ));
     115       22554 :             if ( pIter != m_aFactoryManagerMap.end() )
     116       22554 :                 return pIter->second;
     117             :         }
     118             :     }
     119             : 
     120           0 :     return OUString();
     121             : }
     122             : 
     123           2 : void ConfigurationAccess_FactoryManager::addFactorySpecifierToTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule, const OUString& rServiceSpecifier )
     124             : {
     125             :     // SAFE
     126           2 :     osl::MutexGuard g(m_aMutex);
     127             : 
     128           4 :     OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
     129             : 
     130           2 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
     131             : 
     132           2 :     if ( pIter != m_aFactoryManagerMap.end() )
     133           0 :         throw ElementExistException();
     134             :     else
     135           4 :         m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, rServiceSpecifier ));
     136           2 : }
     137             : 
     138           2 : void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule )
     139             : {
     140             :     // SAFE
     141           2 :     osl::MutexGuard g(m_aMutex);
     142             : 
     143           4 :     OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule );
     144             : 
     145           2 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey );
     146             : 
     147           2 :     if ( pIter == m_aFactoryManagerMap.end() )
     148           0 :         throw NoSuchElementException();
     149             :     else
     150           4 :         m_aFactoryManagerMap.erase( aHashKey );
     151           2 : }
     152             : 
     153           2 : Sequence< Sequence< PropertyValue > > ConfigurationAccess_FactoryManager::getFactoriesDescription() const
     154             : {
     155             :     // SAFE
     156           2 :     osl::MutexGuard g(m_aMutex);
     157             : 
     158           2 :     Sequence< Sequence< PropertyValue > > aSeqSeq;
     159             : 
     160           2 :     sal_Int32 nIndex( 0 );
     161           2 :     FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.begin();
     162          22 :     while ( pIter != m_aFactoryManagerMap.end() )
     163             :     {
     164          18 :         OUString aFactory = pIter->first;
     165          18 :         if ( !aFactory.isEmpty() )
     166             :         {
     167          18 :             sal_Int32                 nToken = 0;
     168          18 :             Sequence< PropertyValue > aSeq( 1 );
     169             : 
     170          18 :             aSeqSeq.realloc( aSeqSeq.getLength() + 1 );
     171          18 :             aSeq[0].Name  = m_aPropType;
     172          18 :             aSeq[0].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     173          18 :             if ( nToken > 0 )
     174             :             {
     175          18 :                 aSeq.realloc( 2 );
     176          18 :                 aSeq[1].Name  = m_aPropName;
     177          18 :                 aSeq[1].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     178          18 :                 if ( nToken > 0 )
     179             :                 {
     180          18 :                     aSeq.realloc( 3 );
     181          18 :                     aSeq[2].Name  = m_aPropModule;
     182          18 :                     aSeq[2].Value = makeAny( aFactory.getToken( 0, '^', nToken ));
     183             :                 }
     184             :             }
     185             : 
     186          18 :             aSeqSeq[nIndex++] = aSeq;
     187             :         }
     188             : 
     189          18 :         ++pIter;
     190          18 :     }
     191             : 
     192           2 :     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         164 : void ConfigurationAccess_FactoryManager::readConfigurationData()
     264             : {
     265             :     // SAFE
     266         164 :     osl::MutexGuard g(m_aMutex);
     267             : 
     268         164 :     if ( !m_bConfigAccessInitialized )
     269             :     {
     270         164 :         Sequence< Any > aArgs( 1 );
     271         328 :         PropertyValue   aPropValue;
     272             : 
     273         164 :         aPropValue.Name  = "nodepath";
     274         164 :         aPropValue.Value <<= m_sRoot;
     275         164 :         aArgs[0] <<= aPropValue;
     276             : 
     277             :         try
     278             :         {
     279         164 :             m_xConfigAccess.set( m_xConfigProvider->createInstanceWithArguments(
     280         164 :                         "com.sun.star.configuration.ConfigurationAccess", aArgs ), UNO_QUERY );
     281             :         }
     282           0 :         catch ( const WrappedTargetException& )
     283             :         {
     284             :         }
     285             : 
     286         328 :         m_bConfigAccessInitialized = true;
     287             :     }
     288             : 
     289         164 :     if ( m_xConfigAccess.is() )
     290             :     {
     291         164 :         Sequence< OUString >   aUIElementFactories = m_xConfigAccess->getElementNames();
     292             : 
     293         328 :         OUString             aType;
     294         328 :         OUString             aName;
     295         328 :         OUString             aModule;
     296         328 :         OUString             aService;
     297         328 :         OUString             aHashKey;
     298         328 :         Reference< XPropertySet > xPropertySet;
     299        1476 :         for ( sal_Int32 i = 0; i < aUIElementFactories.getLength(); i++ )
     300             :         {
     301        1312 :             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        1312 :                 aHashKey = getHashKeyFromStrings( aType, aName, aModule );
     306        1312 :                 m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService ));
     307             :             }
     308             :         }
     309             : 
     310         328 :         Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
     311         164 :         if ( xContainer.is() )
     312             :         {
     313         164 :             m_xConfigListener = new WeakContainerListener(this);
     314         164 :             xContainer->addContainerListener(m_xConfigListener);
     315         164 :         }
     316         164 :     }
     317         164 : }
     318             : 
     319        1312 : bool ConfigurationAccess_FactoryManager::impl_getElementProps( const Any& aElement, OUString& rType, OUString& rName, OUString& rModule, OUString& rServiceSpecifier ) const
     320             : {
     321        1312 :     Reference< XPropertySet > xPropertySet;
     322        1312 :     aElement >>= xPropertySet;
     323             : 
     324        1312 :     if ( xPropertySet.is() )
     325             :     {
     326             :         try
     327             :         {
     328        1312 :             xPropertySet->getPropertyValue( m_aPropType ) >>= rType;
     329        1312 :             xPropertySet->getPropertyValue( m_aPropName ) >>= rName;
     330        1312 :             xPropertySet->getPropertyValue( m_aPropModule ) >>= rModule;
     331        1312 :             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        1312 :     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           2 :     virtual OUString SAL_CALL getImplementationName()
     363             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     364             :     {
     365           2 :         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         166 : UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentContext >& rxContext ) :
     398             :     UIElementFactoryManager_BASE(m_aMutex),
     399             :     m_bConfigRead( false ),
     400         166 :     m_xContext(rxContext)
     401             : {
     402             :     m_pConfigAccess = new ConfigurationAccess_FactoryManager(rxContext,
     403         166 :             "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories");
     404         166 :     m_pConfigAccess->acquire();
     405         166 : }
     406             : 
     407         462 : UIElementFactoryManager::~UIElementFactoryManager()
     408             : {
     409         154 :     disposing();
     410         308 : }
     411             : 
     412         316 : void SAL_CALL UIElementFactoryManager::disposing()
     413             : {
     414         316 :     osl::MutexGuard g(rBHelper.rMutex);
     415         316 :     if (m_pConfigAccess)
     416             :     {
     417             :         // reduce reference count
     418         162 :         m_pConfigAccess->release();
     419         162 :         m_pConfigAccess = 0;
     420         316 :     }
     421         316 : }
     422             : 
     423             : // XUIElementFactory
     424       40660 : 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       40660 :     Reference< XFrame > xFrame;
     430             :     { // SAFE
     431       40660 :     osl::MutexGuard g(rBHelper.rMutex);
     432             : 
     433       40660 :     if ( !m_bConfigRead )
     434             :     {
     435         164 :         m_bConfigRead = true;
     436         164 :         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      156726 :     for ( int i = 0; i < Args.getLength(); i++ )
     443             :     {
     444      116066 :         if ( Args[i].Name == "Frame")
     445       40658 :             Args[i].Value >>= xFrame;
     446       40660 :     }
     447             :     } // SAFE
     448             : 
     449       81320 :     Reference< XModuleManager2 > xManager = ModuleManager::create( m_xContext );
     450             : 
     451             :     // Determine the module identifier
     452             :     try
     453             :     {
     454       40660 :         OUString aModuleId;
     455       40660 :         if ( xFrame.is() && xManager.is() )
     456       35092 :             aModuleId = xManager->identify( Reference<XInterface>( xFrame, UNO_QUERY ) );
     457             : 
     458       41690 :         Reference< XUIElementFactory > xUIElementFactory = getFactory( ResourceURL, aModuleId );
     459       40654 :         if ( xUIElementFactory.is() )
     460       80286 :             return xUIElementFactory->createUIElement( ResourceURL, Args );
     461             :     }
     462           6 :     catch ( const UnknownModuleException& )
     463             :     {
     464             :     }
     465             : 
     466       40660 :     throw NoSuchElementException();
     467             : }
     468             : 
     469             : // XUIElementFactoryRegistration
     470           2 : Sequence< Sequence< PropertyValue > > SAL_CALL UIElementFactoryManager::getRegisteredFactories()
     471             : throw ( RuntimeException, std::exception )
     472             : {
     473             :     // SAFE
     474           2 :     osl::MutexGuard g(rBHelper.rMutex);
     475             : 
     476           2 :     if ( !m_bConfigRead )
     477             :     {
     478           0 :         m_bConfigRead = true;
     479           0 :         m_pConfigAccess->readConfigurationData();
     480             :     }
     481             : 
     482           2 :     return m_pConfigAccess->getFactoriesDescription();
     483             : }
     484             : 
     485       40656 : Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( const OUString& aResourceURL, const OUString& aModuleId )
     486             : throw ( RuntimeException, std::exception )
     487             : {
     488       40656 :     OUString aServiceSpecifier;
     489             :     { // SAFE
     490       40656 :     osl::MutexGuard g(rBHelper.rMutex);
     491             : 
     492       40656 :     if ( !m_bConfigRead )
     493             :     {
     494           0 :         m_bConfigRead = true;
     495           0 :         m_pConfigAccess->readConfigurationData();
     496             :     }
     497             : 
     498       81312 :     OUString aType;
     499       81312 :     OUString aName;
     500             : 
     501       40656 :     RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
     502             : 
     503       81312 :     aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     504             :     } // SAFE
     505             : 
     506       40656 :     if ( !aServiceSpecifier.isEmpty() ) try
     507             :     {
     508       81312 :         return Reference< XUIElementFactory >(m_xContext->getServiceManager()->
     509       40656 :                 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           2 : 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           2 :     osl::MutexGuard g(rBHelper.rMutex);
     524             : 
     525           2 :     if ( !m_bConfigRead )
     526             :     {
     527           0 :         m_bConfigRead = true;
     528           0 :         m_pConfigAccess->readConfigurationData();
     529             :     }
     530             : 
     531           2 :     m_pConfigAccess->addFactorySpecifierToTypeNameModule( aType, aName, aModuleId, aFactoryImplementationName );
     532             :     // SAFE
     533           2 : }
     534             : 
     535           2 : void SAL_CALL UIElementFactoryManager::deregisterFactory( const OUString& aType, const OUString& aName, const OUString& aModuleId )
     536             : throw ( NoSuchElementException, RuntimeException, std::exception )
     537             : {
     538             :     // SAFE
     539           2 :     osl::MutexGuard g(rBHelper.rMutex);
     540             : 
     541           2 :     if ( !m_bConfigRead )
     542             :     {
     543           0 :         m_bConfigRead = true;
     544           0 :         m_pConfigAccess->readConfigurationData();
     545             :     }
     546             : 
     547           2 :     m_pConfigAccess->removeFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     548             :     // SAFE
     549           2 : }
     550             : 
     551         166 : struct Instance {
     552         166 :     explicit Instance(
     553             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     554             :         instance(static_cast<cppu::OWeakObject *>(
     555         166 :                     new UIElementFactoryManager(context)))
     556             :     {
     557         166 :     }
     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         170 : 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         170 :             Singleton::get(context).instance.get()));
     576         951 : }
     577             : 
     578             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10