LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbaglobalbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 63 77.8 %
Date: 2012-08-25 Functions: 7 9 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 72 179 40.2 %

           Branch data     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                 :            : #include "vbahelper/vbaglobalbase.hxx"
      20                 :            : #include <sal/macros.h>
      21                 :            : 
      22                 :            : #include <cppuhelper/component_context.hxx>
      23                 :            : #include <cppuhelper/exc_hlp.hxx>
      24                 :            : #include <comphelper/processfactory.hxx>
      25                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      26                 :            : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
      27                 :            : 
      28                 :            : using namespace com::sun::star;
      29                 :            : using namespace ooo::vba;
      30                 :            : 
      31                 :            : // special key to return the Application
      32                 :            : const char sAppService[] = "ooo.vba.Application";
      33                 :            : 
      34                 :          8 : VbaGlobalsBase::VbaGlobalsBase(
      35                 :            : const uno::Reference< ov::XHelperInterface >& xParent,
      36                 :            : const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName )
      37                 :            :     : Globals_BASE( xParent, xContext )
      38                 :            :     , msDocCtxName( sDocCtxName )
      39         [ +  - ]:          8 :     , msApplication( RTL_CONSTASCII_USTRINGPARAM("Application") )
      40                 :            : {
      41                 :            :     // overwrite context with custom one ( that contains the application )
      42                 :            :     // wrap the service manager as we don't want the disposing context to tear down the 'normal' ServiceManager ( or at least thats what the code appears like it wants to do )
      43                 :          8 :     uno::Reference< uno::XInterface > aSrvMgr;
      44 [ +  - ][ +  - ]:          8 :     if ( xContext.is() && xContext->getServiceManager().is() )
         [ +  - ][ +  - ]
           [ +  -  #  # ]
                 [ +  - ]
      45                 :            :     {
      46 [ +  - ][ +  - ]:          8 :         aSrvMgr = xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      47                 :            :     }
      48                 :            : 
      49                 :            :     ::cppu::ContextEntry_Init aHandlerContextInfo[] =
      50                 :            :     {
      51                 :            :         ::cppu::ContextEntry_Init( msApplication, uno::Any() ),
      52                 :            :         ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ),
      53                 :            :         ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), uno::makeAny( aSrvMgr ) )
      54 [ +  - ][ +  - ]:         32 :     };
           [ #  #  #  # ]
      55                 :            :     // don't pass a delegate, this seems to introduce yet another cyclic dependency ( and
      56                 :            :     // some strange behavior
      57                 :            :     mxContext = ::cppu::createComponentContext(
      58                 :            :                         aHandlerContextInfo,
      59 [ +  - ][ +  - ]:          8 :                         ( sizeof ( aHandlerContextInfo ) / sizeof ( aHandlerContextInfo[0] ) ), NULL );
                 [ +  - ]
      60         [ +  - ]:          8 :     if ( aSrvMgr.is() )
      61                 :            :     {
      62                 :            :         try
      63                 :            :         {
      64                 :            :             uno::Reference< beans::XPropertySet >(
      65 [ +  - ][ +  - ]:         16 :                 aSrvMgr, uno::UNO_QUERY_THROW )->
      66 [ +  - ][ +  - ]:          8 :                 setPropertyValue( "DefaultContext", uno::makeAny( mxContext ) );
      67                 :            :         }
      68                 :          0 :         catch ( uno::RuntimeException & )
      69                 :            :         {
      70                 :          0 :             throw;
      71                 :            :         }
      72      [ #  #  # ]:          0 :         catch ( uno::Exception & )
      73                 :            :         {
      74         [ #  # ]:          0 :             uno::Any e(cppu::getCaughtException());
      75                 :            :             throw lang::WrappedTargetRuntimeException(
      76                 :            :                 ("VbaGlobalsBase ctor, setting OServiceManagerWrapper"
      77                 :            :                  " DefaultContext failed"),
      78         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >(), e);
      79                 :            :         }
      80 [ +  + ][ #  # ]:         32 :     }
      81                 :          8 : }
      82                 :            : 
      83                 :          8 : VbaGlobalsBase::~VbaGlobalsBase()
      84                 :            : {
      85                 :            :     try
      86                 :            :     {
      87         [ +  - ]:          8 :         uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY );
      88         [ +  - ]:          8 :         if ( xNameContainer.is() )
      89                 :            :         {
      90                 :            :             // release document reference ( we don't wan't the component context trying to dispose that )
      91 [ +  - ][ +  - ]:          8 :             xNameContainer->removeByName( msDocCtxName );
      92                 :            :             // release application reference, as it is holding onto the context
      93 [ +  - ][ +  - ]:          8 :             xNameContainer->removeByName( msApplication );
      94         [ #  # ]:          8 :         }
      95                 :            :     }
      96         [ #  # ]:          0 :     catch ( const uno::Exception& )
      97                 :            :     {
      98                 :            :     }
      99         [ -  + ]:          8 : }
     100                 :            : 
     101                 :            : void
     102                 :          8 : VbaGlobalsBase::init(  const uno::Sequence< beans::PropertyValue >& aInitArgs )
     103                 :            : {
     104                 :          8 :     sal_Int32 nLen = aInitArgs.getLength();
     105         [ +  + ]:         24 :     for ( sal_Int32 nIndex = 0; nIndex < nLen; ++nIndex )
     106                 :            :     {
     107         [ +  - ]:         16 :         uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
     108         [ +  + ]:         16 :         if ( aInitArgs[ nIndex ].Name.equals( msApplication ) )
     109                 :            :         {
     110 [ +  - ][ +  - ]:          8 :             xNameContainer->replaceByName( msApplication, aInitArgs[ nIndex ].Value );
     111         [ +  - ]:          8 :             uno::Reference< XHelperInterface > xParent( aInitArgs[ nIndex ].Value, uno::UNO_QUERY );
     112         [ +  - ]:          8 :             mxParent = xParent;
     113                 :            :         }
     114                 :            :         else
     115 [ +  - ][ +  - ]:          8 :             xNameContainer->replaceByName( aInitArgs[ nIndex ].Name, aInitArgs[ nIndex ].Value );
     116                 :         16 :     }
     117                 :          8 : }
     118                 :            : 
     119                 :            : uno::Reference< uno::XInterface > SAL_CALL
     120                 :          0 : VbaGlobalsBase::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (uno::Exception, uno::RuntimeException)
     121                 :            : {
     122                 :          0 :     uno::Reference< uno::XInterface > xReturn;
     123         [ #  # ]:          0 :     if ( aServiceSpecifier == sAppService )
     124                 :            :     {
     125                 :            :         // try to extract the Application from the context
     126         [ #  # ]:          0 :         uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY );
     127 [ #  # ][ #  # ]:          0 :         xNameContainer->getByName( msApplication ) >>= xReturn;
                 [ #  # ]
     128                 :            :     }
     129 [ #  # ][ #  # ]:          0 :     else if ( hasServiceName( aServiceSpecifier ) )
     130 [ #  # ][ #  # ]:          0 :         xReturn = mxContext->getServiceManager()->createInstanceWithContext( aServiceSpecifier, mxContext );
         [ #  # ][ #  # ]
                 [ #  # ]
     131                 :          0 :     return xReturn;
     132                 :            : }
     133                 :            : 
     134                 :            : uno::Reference< uno::XInterface > SAL_CALL
     135                 :         64 : VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& aServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) throw (uno::Exception, uno::RuntimeException)
     136                 :            : {
     137                 :            : 
     138                 :         64 :     uno::Reference< uno::XInterface > xReturn;
     139         [ +  + ]:         64 :     if ( aServiceSpecifier == sAppService )
     140                 :            :     {
     141                 :            :         // try to extract the Application from the context
     142         [ +  - ]:          4 :         uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY );
     143 [ +  - ][ +  - ]:          4 :         xNameContainer->getByName( msApplication ) >>= xReturn;
                 [ +  - ]
     144                 :            :     }
     145 [ +  - ][ +  + ]:         60 :     else if ( hasServiceName( aServiceSpecifier ) )
     146 [ +  - ][ +  - ]:         21 :         xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( aServiceSpecifier, Arguments, mxContext );
         [ +  - ][ +  - ]
                 [ +  - ]
     147                 :         64 :     return xReturn;
     148                 :            : }
     149                 :            : 
     150                 :            : uno::Sequence< ::rtl::OUString > SAL_CALL
     151                 :          6 : VbaGlobalsBase::getAvailableServiceNames(  ) throw (uno::RuntimeException)
     152                 :            : {
     153                 :            :     static const rtl::OUString names[] = {
     154                 :            :     // common
     155                 :            :         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.msforms.UserForm" ) ),
     156 [ +  - ][ +  - ]:         18 :       };
         [ +  - ][ #  #  
             #  #  #  # ]
                 [ +  + ]
     157 [ +  - ][ +  - ]:          6 :     static uno::Sequence< rtl::OUString > serviceNames( names, sizeof( names )/ sizeof( names[0] ) );
         [ +  - ][ #  # ]
     158                 :          6 :     return serviceNames;
     159                 :            : }
     160                 :            : 
     161                 :            : bool
     162                 :         60 : VbaGlobalsBase::hasServiceName( const rtl::OUString& serviceName )
     163                 :            : {
     164         [ +  - ]:         60 :     uno::Sequence< rtl::OUString > sServiceNames( getAvailableServiceNames() );
     165                 :         60 :     sal_Int32 nLen = sServiceNames.getLength();
     166         [ +  + ]:        229 :     for ( sal_Int32 index = 0; index < nLen; ++index )
     167                 :            :     {
     168 [ +  - ][ +  + ]:        190 :         if ( sServiceNames[ index ].equals( serviceName ) )
     169                 :         21 :             return true;
     170                 :            :     }
     171         [ +  - ]:         60 :     return false;
     172                 :            : }
     173                 :            : 
     174                 :            : 
     175                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10