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

Generated by: LCOV version 1.10