LCOV - code coverage report
Current view: top level - framework/source/uifactory - windowcontentfactorymanager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 21 75 28.0 %
Date: 2014-11-03 Functions: 7 12 58.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 <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/frame/ModuleManager.hpp>
      27             : #include <com/sun/star/frame/XModuleManager2.hpp>
      28             : #include <com/sun/star/frame/XFrame.hpp>
      29             : #include <com/sun/star/lang/XServiceInfo.hpp>
      30             : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      31             : #include <com/sun/star/uno/XComponentContext.hpp>
      32             : 
      33             : #include <cppuhelper/basemutex.hxx>
      34             : #include <cppuhelper/compbase2.hxx>
      35             : #include <cppuhelper/supportsservice.hxx>
      36             : #include <tools/diagnose_ex.h>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace framework;
      40             : 
      41             : namespace {
      42             : 
      43             : typedef ::cppu::WeakComponentImplHelper2<
      44             :     com::sun::star::lang::XServiceInfo,
      45             :     com::sun::star::lang::XSingleComponentFactory > WindowContentFactoryManager_BASE;
      46             : 
      47             : class WindowContentFactoryManager : private cppu::BaseMutex,
      48             :                                     public WindowContentFactoryManager_BASE
      49             : {
      50             : public:
      51             :     WindowContentFactoryManager( const css::uno::Reference< css::uno::XComponentContext>& rxContext );
      52             :     virtual ~WindowContentFactoryManager();
      53             : 
      54           0 :     virtual OUString SAL_CALL getImplementationName()
      55             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      56             :     {
      57           0 :         return OUString("com.sun.star.comp.framework.WindowContentFactoryManager");
      58             :     }
      59             : 
      60           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      61             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      62             :     {
      63           0 :         return cppu::supportsService(this, ServiceName);
      64             :     }
      65             : 
      66           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      67             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      68             :     {
      69           0 :         css::uno::Sequence< OUString > aSeq(1);
      70           0 :         aSeq[0] = OUString("com.sun.star.ui.WindowContentFactoryManager");
      71           0 :         return aSeq;
      72             :     }
      73             : 
      74             :     // XSingleComponentFactory
      75             :     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext( const css::uno::Reference< css::uno::XComponentContext >& Context ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      76             :     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext( const css::uno::Sequence< css::uno::Any >& Arguments, const css::uno::Reference< css::uno::XComponentContext >& Context ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      77             : 
      78             : private:
      79             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
      80             : 
      81             :     css::uno::Reference< css::uno::XComponentContext >     m_xContext;
      82             :     bool                                               m_bConfigRead;
      83             :     ConfigurationAccess_FactoryManager*                    m_pConfigAccess;
      84             : };
      85             : 
      86           2 : WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< uno::XComponentContext >& rxContext ) :
      87             :     WindowContentFactoryManager_BASE(m_aMutex),
      88             :     m_xContext( rxContext ),
      89           2 :     m_bConfigRead( false )
      90             : {
      91             :     m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xContext,
      92           2 :             "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" );
      93           2 :     m_pConfigAccess->acquire();
      94           2 : }
      95             : 
      96           6 : WindowContentFactoryManager::~WindowContentFactoryManager()
      97             : {
      98           2 :     disposing();
      99           4 : }
     100             : 
     101           4 : void SAL_CALL WindowContentFactoryManager::disposing()
     102             : {
     103           4 :     osl::MutexGuard g(rBHelper.rMutex);
     104             : 
     105           4 :     if (m_pConfigAccess)
     106             :     {
     107             :         // reduce reference count
     108           2 :         m_pConfigAccess->release();
     109           2 :         m_pConfigAccess = 0;
     110           4 :     }
     111           4 : }
     112             : 
     113             : // XSingleComponentFactory
     114           0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithContext(
     115             :     const uno::Reference< uno::XComponentContext >& /*xContext*/ )
     116             : throw (uno::Exception, uno::RuntimeException, std::exception)
     117             : {
     118           0 :     uno::Reference< uno::XInterface > xWindow;
     119           0 :     return xWindow;
     120             : }
     121             : 
     122           0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithArgumentsAndContext(
     123             :     const uno::Sequence< uno::Any >& Arguments, const uno::Reference< uno::XComponentContext >& Context )
     124             : throw (uno::Exception, uno::RuntimeException, std::exception)
     125             : {
     126           0 :     uno::Reference< uno::XInterface > xWindow;
     127           0 :     uno::Reference< frame::XFrame >   xFrame;
     128           0 :     OUString                   aResourceURL;
     129             : 
     130           0 :     for (sal_Int32 i=0; i < Arguments.getLength(); i++ )
     131             :     {
     132           0 :         beans::PropertyValue aPropValue;
     133           0 :         if ( Arguments[i] >>= aPropValue )
     134             :         {
     135           0 :             if ( aPropValue.Name == "Frame" )
     136           0 :                 aPropValue.Value >>= xFrame;
     137           0 :             else if ( aPropValue.Name == "ResourceURL" )
     138           0 :                 aPropValue.Value >>= aResourceURL;
     139             :         }
     140           0 :     }
     141             : 
     142             :     // Determine the module identifier
     143           0 :     OUString aType;
     144           0 :     OUString aName;
     145           0 :     OUString aModuleId;
     146             :     uno::Reference< frame::XModuleManager2 > xModuleManager =
     147           0 :         frame::ModuleManager::create( m_xContext );
     148             :     try
     149             :     {
     150           0 :         if ( xFrame.is() && xModuleManager.is() )
     151           0 :             aModuleId = xModuleManager->identify( uno::Reference< uno::XInterface >( xFrame, uno::UNO_QUERY ) );
     152             :     }
     153           0 :     catch ( const frame::UnknownModuleException& )
     154             :     {
     155             :     }
     156             : 
     157           0 :     RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
     158           0 :     if ( !aType.isEmpty() &&
     159           0 :          !aName.isEmpty() &&
     160           0 :          !aModuleId.isEmpty() )
     161             :     {
     162           0 :         OUString                   aImplementationName;
     163           0 :         uno::Reference< uno::XInterface > xHolder( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
     164             : 
     165             :         // Detetmine the implementation name of the window content factory dependent on the
     166             :         // module identifier, user interface element type and name
     167             :         { // SAFE
     168           0 :         osl::MutexGuard g(rBHelper.rMutex);
     169           0 :         if ( !m_bConfigRead )
     170             :         {
     171           0 :             m_bConfigRead = true;
     172           0 :             m_pConfigAccess->readConfigurationData();
     173             :         }
     174           0 :         aImplementationName = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     175             :         } // SAFE
     176             : 
     177           0 :         if ( !aImplementationName.isEmpty() )
     178             :         {
     179           0 :             uno::Reference< lang::XMultiServiceFactory > xServiceManager( Context->getServiceManager(), uno::UNO_QUERY );
     180           0 :             if ( xServiceManager.is() )
     181             :             {
     182             :                 uno::Reference< lang::XSingleComponentFactory > xFactory(
     183           0 :                     xServiceManager->createInstance( aImplementationName ), uno::UNO_QUERY );
     184           0 :                 if ( xFactory.is() )
     185             :                 {
     186             :                     // Be careful: We call external code. Therefore here we have to catch all exceptions
     187             :                     try
     188             :                     {
     189           0 :                         xWindow = xFactory->createInstanceWithArgumentsAndContext( Arguments, Context );
     190             :                     }
     191           0 :                     catch ( uno::Exception& )
     192             :                     {
     193             :                         DBG_UNHANDLED_EXCEPTION();
     194             :                     }
     195           0 :                 }
     196           0 :             }
     197           0 :         }
     198             :     }
     199             : 
     200             :     // UNSAFE
     201           0 :     if ( !xWindow.is())
     202             :     {
     203             :         // Fallback: Use internal factory code to create a toolkit dialog as a content window
     204           0 :         xWindow = createInstanceWithContext(Context);
     205             :     }
     206             : 
     207           0 :     return xWindow;
     208             : }
     209             : 
     210           2 : struct Instance {
     211           2 :     explicit Instance(
     212             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     213             :         instance(static_cast<cppu::OWeakObject *>(
     214           2 :                     new WindowContentFactoryManager(context)))
     215             :     {
     216           2 :     }
     217             : 
     218             :     css::uno::Reference<css::uno::XInterface> instance;
     219             : };
     220             : 
     221             : struct Singleton:
     222             :     public rtl::StaticWithArg<
     223             :         Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
     224             : {};
     225             : 
     226             : }
     227             : 
     228             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     229           2 : com_sun_star_comp_framework_WindowContentFactoryManager_get_implementation(
     230             :     css::uno::XComponentContext *context,
     231             :     css::uno::Sequence<css::uno::Any> const &)
     232             : {
     233             :     return cppu::acquire(static_cast<cppu::OWeakObject *>(
     234           2 :                 Singleton::get(context).instance.get()));
     235             : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10