LCOV - code coverage report
Current view: top level - libreoffice/remotebridges/source/unourl_resolver - unourl_resolver.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 52 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
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             : //  #define TRACE(x) OSL_TRACE(x)
      21             : #define TRACE(x)
      22             : 
      23             : #include <osl/diagnose.h>
      24             : #include <osl/mutex.hxx>
      25             : #include <cppuhelper/factory.hxx>
      26             : #include <cppuhelper/implbase2.hxx>
      27             : #include <cppuhelper/implementationentry.hxx>
      28             : #include "cppuhelper/unourl.hxx"
      29             : #include "rtl/malformeduriexception.hxx"
      30             : 
      31             : #include <com/sun/star/lang/XServiceInfo.hpp>
      32             : #include <com/sun/star/lang/XComponent.hpp>
      33             : #include <com/sun/star/registry/XRegistryKey.hpp>
      34             : #include <com/sun/star/connection/XConnector.hpp>
      35             : #include <com/sun/star/bridge/BridgeFactory.hpp>
      36             : #include <com/sun/star/bridge/XBridgeFactory.hpp>
      37             : #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
      38             : 
      39             : using namespace cppu;
      40             : using namespace osl;
      41             : using namespace com::sun::star::uno;
      42             : using namespace com::sun::star::lang;
      43             : using namespace com::sun::star::connection;
      44             : using namespace com::sun::star::bridge;
      45             : using namespace com::sun::star::registry;
      46             : 
      47             : using ::rtl::OUString;
      48             : 
      49             : #define SERVICENAME     "com.sun.star.bridge.UnoUrlResolver"
      50             : #define IMPLNAME        "com.sun.star.comp.bridge.UnoUrlResolver"
      51             : 
      52             : namespace unourl_resolver
      53             : {
      54             :     rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
      55             : //--------------------------------------------------------------------------------------------------
      56           0 : Sequence< OUString > resolver_getSupportedServiceNames()
      57             : {
      58           0 :     Sequence< OUString > seqNames(1);
      59           0 :     seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
      60           0 :     return seqNames;
      61             : }
      62             : 
      63           0 : OUString resolver_getImplementationName()
      64             : {
      65           0 :     return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
      66             : }
      67             : 
      68             : //==================================================================================================
      69             : class ResolverImpl : public WeakImplHelper2< XServiceInfo, XUnoUrlResolver >
      70             : {
      71             :     Reference< XMultiComponentFactory > _xSMgr;
      72             :     Reference< XComponentContext > _xCtx;
      73             : 
      74             : public:
      75             :     ResolverImpl( const Reference< XComponentContext > & xSMgr );
      76             :     virtual ~ResolverImpl();
      77             : 
      78             :     // XServiceInfo
      79             :     virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
      80             :     virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException);
      81             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
      82             : 
      83             :     // XUnoUrlResolver
      84             :     virtual Reference< XInterface > SAL_CALL resolve( const OUString & rUnoUrl )
      85             :         throw (NoConnectException, ConnectionSetupException, RuntimeException);
      86             : };
      87             : 
      88             : //##################################################################################################
      89             : 
      90             : //__________________________________________________________________________________________________
      91           0 : ResolverImpl::ResolverImpl( const Reference< XComponentContext > & xCtx )
      92           0 :     : _xSMgr( xCtx->getServiceManager() )
      93           0 :     , _xCtx( xCtx )
      94             : {
      95           0 :     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
      96           0 : }
      97             : //__________________________________________________________________________________________________
      98           0 : ResolverImpl::~ResolverImpl()
      99             : {
     100           0 :     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
     101           0 : }
     102             : 
     103             : // XServiceInfo
     104             : //__________________________________________________________________________________________________
     105           0 : OUString ResolverImpl::getImplementationName()
     106             :     throw(::com::sun::star::uno::RuntimeException)
     107             : {
     108           0 :     return resolver_getImplementationName();
     109             : }
     110             : //__________________________________________________________________________________________________
     111           0 : sal_Bool ResolverImpl::supportsService( const OUString & rServiceName )
     112             :     throw(::com::sun::star::uno::RuntimeException)
     113             : {
     114           0 :     const Sequence< OUString > & rSNL = getSupportedServiceNames();
     115           0 :     const OUString * pArray = rSNL.getConstArray();
     116           0 :     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
     117             :     {
     118           0 :         if (pArray[nPos] == rServiceName)
     119           0 :             return sal_True;
     120             :     }
     121           0 :     return sal_False;
     122             : }
     123             : //__________________________________________________________________________________________________
     124           0 : Sequence< OUString > ResolverImpl::getSupportedServiceNames()
     125             :     throw(::com::sun::star::uno::RuntimeException)
     126             : {
     127           0 :     return resolver_getSupportedServiceNames();
     128             : }
     129             : 
     130             : // XUnoUrlResolver
     131             : //__________________________________________________________________________________________________
     132           0 : Reference< XInterface > ResolverImpl::resolve( const OUString & rUnoUrl )
     133             :     throw (NoConnectException, ConnectionSetupException, RuntimeException)
     134             : {
     135           0 :     OUString aProtocolDescr;
     136           0 :     OUString aConnectDescr;
     137           0 :     OUString aInstanceName;
     138             :     try
     139             :     {
     140           0 :         cppu::UnoUrl aUrl(rUnoUrl);
     141           0 :         aProtocolDescr = aUrl.getProtocol().getDescriptor();
     142           0 :         aConnectDescr = aUrl.getConnection().getDescriptor();
     143           0 :         aInstanceName = aUrl.getObjectName();
     144             :     }
     145           0 :     catch (const rtl::MalformedUriException & rEx)
     146             :     {
     147           0 :         throw ConnectionSetupException(rEx.getMessage(), 0);
     148             :     }
     149             : 
     150             :     Reference< XConnector > xConnector(
     151           0 :         _xSMgr->createInstanceWithContext(
     152             :             OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ),
     153           0 :             _xCtx ),
     154           0 :         UNO_QUERY );
     155             : 
     156           0 :     if (! xConnector.is())
     157           0 :         throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no connector!" ) ), Reference< XInterface >() );
     158             : 
     159           0 :     Reference< XConnection > xConnection( xConnector->connect( aConnectDescr ) );
     160             : 
     161             :     // As soon as singletons are ready, switch to singleton !
     162           0 :     Reference< XBridgeFactory2 > xBridgeFactory( BridgeFactory::create(_xCtx) );
     163             : 
     164             :     // bridge
     165           0 :     Reference< XBridge > xBridge( xBridgeFactory->createBridge(
     166             :         OUString(), aProtocolDescr,
     167           0 :         xConnection, Reference< XInstanceProvider >() ) );
     168             : 
     169           0 :     Reference< XInterface > xRet( xBridge->getInstance( aInstanceName ) );
     170             : 
     171           0 :     return xRet;
     172             : }
     173             : 
     174             : //==================================================================================================
     175           0 : static Reference< XInterface > SAL_CALL ResolverImpl_create( const Reference< XComponentContext > & xCtx )
     176             : {
     177           0 :     return Reference< XInterface >( *new ResolverImpl( xCtx ) );
     178             : }
     179             : 
     180             : 
     181             : }
     182             : 
     183             : using namespace unourl_resolver;
     184             : 
     185             : static struct ImplementationEntry g_entries[] =
     186             : {
     187             :     {
     188             :         ResolverImpl_create, resolver_getImplementationName,
     189             :         resolver_getSupportedServiceNames, createSingleComponentFactory,
     190             :         &g_moduleCount.modCnt , 0
     191             :     },
     192             :     { 0, 0, 0, 0, 0, 0 }
     193             : };
     194             : 
     195             : extern "C"
     196             : {
     197           0 : SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL uuresolver_component_canUnload( TimeValue *pTime )
     198             : {
     199           0 :     return g_moduleCount.canUnload( &g_moduleCount , pTime );
     200             : }
     201             : 
     202             : //==================================================================================================
     203           0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL uuresolver_component_getFactory(
     204             :     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
     205             : {
     206           0 :     return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
     207             : }
     208             : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10