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

Generated by: LCOV version 1.10