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

Generated by: LCOV version 1.10