LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/comphelper/source/misc - componentcontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 34 29.4 %
Date: 2013-07-09 Functions: 2 7 28.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 <comphelper/componentcontext.hxx>
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <com/sun/star/lang/NullPointerException.hpp>
      23             : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : 
      26             : //........................................................................
      27             : namespace comphelper
      28             : {
      29             : //........................................................................
      30             : 
      31             :     using ::com::sun::star::uno::Reference;
      32             :     using ::com::sun::star::uno::XComponentContext;
      33             :     using ::com::sun::star::lang::NullPointerException;
      34             :     using ::com::sun::star::lang::ServiceNotRegisteredException;
      35             :     using ::com::sun::star::uno::Exception;
      36             :     using ::com::sun::star::uno::Any;
      37             :     using ::com::sun::star::uno::XInterface;
      38             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      39             :     using ::com::sun::star::lang::XMultiServiceFactory;
      40             :     using ::com::sun::star::beans::XPropertySet;
      41             :     using ::com::sun::star::uno::UNO_QUERY;
      42             :     using ::com::sun::star::uno::RuntimeException;
      43             :     using ::com::sun::star::uno::Sequence;
      44             : 
      45             :     //====================================================================
      46             :     //= ComponentContext
      47             :     //====================================================================
      48             :     //--------------------------------------------------------------------
      49           1 :     ComponentContext::ComponentContext( const Reference< XComponentContext >& _rxContext )
      50           1 :         :m_xContext( _rxContext )
      51             :     {
      52           1 :         if ( m_xContext.is() )
      53           1 :             m_xORB = m_xContext->getServiceManager();
      54           1 :     }
      55             : 
      56             :     //------------------------------------------------------------------------
      57           0 :     ComponentContext::ComponentContext( const Reference< XMultiServiceFactory >& _rxLegacyFactory )
      58             :     {
      59           0 :         if ( !_rxLegacyFactory.is() )
      60           0 :             throw NullPointerException();
      61             : 
      62           0 :         m_xContext = comphelper::getComponentContext( _rxLegacyFactory );
      63           0 :         m_xORB = m_xContext->getServiceManager();
      64           0 :     }
      65             : 
      66             :     //------------------------------------------------------------------------
      67           0 :     Any ComponentContext::getContextValueByName( const OUString& _rName ) const
      68             :     {
      69           0 :         Any aReturn;
      70             :         try
      71             :         {
      72           0 :             aReturn = m_xContext->getValueByName( _rName );
      73             :         }
      74           0 :         catch( const Exception& )
      75             :         {
      76             :             OSL_FAIL( "ComponentContext::getContextValueByName: caught an exception!" );
      77             :         }
      78           0 :         return aReturn;
      79             :     }
      80             : 
      81             :     //------------------------------------------------------------------------
      82           1 :     Reference< XInterface > ComponentContext::createComponent( const OUString& _rServiceName ) const
      83             :     {
      84             :         Reference< XInterface > xComponent(
      85           1 :             m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
      86           1 :         );
      87           1 :         if ( !xComponent.is() )
      88           0 :             throw ServiceNotRegisteredException( _rServiceName, NULL );
      89           1 :         return xComponent;
      90             :     }
      91             : 
      92             :     //------------------------------------------------------------------------
      93           0 :     Reference< XInterface > ComponentContext::createComponentWithArguments( const OUString& _rServiceName, const Sequence< Any >& _rArguments ) const
      94             :     {
      95             :         Reference< XInterface > xComponent(
      96           0 :             m_xORB->createInstanceWithArgumentsAndContext( _rServiceName, _rArguments, m_xContext )
      97           0 :         );
      98           0 :         if ( !xComponent.is() )
      99           0 :             throw ServiceNotRegisteredException( _rServiceName, NULL );
     100           0 :         return xComponent;
     101             :     }
     102             : 
     103             :     //------------------------------------------------------------------------
     104           0 :     Reference< XInterface > ComponentContext::getSingleton( const OUString& _rInstanceName ) const
     105             :     {
     106           0 :         OUString sKey( "/singletons/" );
     107           0 :         sKey += _rInstanceName;
     108           0 :         return Reference< XInterface >( getContextValueByName( sKey ), UNO_QUERY );
     109             :     }
     110             : 
     111             :     //------------------------------------------------------------------------
     112           0 :     Reference< XMultiServiceFactory > ComponentContext::getLegacyServiceFactory() const
     113             :     {
     114           0 :         return Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY_THROW );
     115             :     }
     116             : 
     117             : //........................................................................
     118             : } // namespace comphelper
     119             : //........................................................................
     120             : 
     121             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10