nss: upgrade to release 3.73
[LibreOffice.git] / remotebridges / source / unourl_resolver / unourl_resolver.cxx
blob9aa8293fa67b36ff2799ffa057326c3f542e7dc6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/malformeduriexception.hxx>
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/implbase.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <cppuhelper/unourl.hxx>
33 using namespace cppu;
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star::lang;
36 using namespace com::sun::star::connection;
37 using namespace com::sun::star::bridge;
38 using namespace com::sun::star::registry;
40 namespace unourl_resolver
43 namespace {
45 class ResolverImpl : public WeakImplHelper< XServiceInfo, XUnoUrlResolver >
47 Reference< XMultiComponentFactory > _xSMgr;
48 Reference< XComponentContext > _xCtx;
50 public:
51 explicit ResolverImpl( const Reference< XComponentContext > & xSMgr );
53 // XServiceInfo
54 virtual OUString SAL_CALL getImplementationName() override;
55 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) override;
56 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
58 // XUnoUrlResolver
59 virtual Reference< XInterface > SAL_CALL resolve( const OUString & rUnoUrl ) override;
64 ResolverImpl::ResolverImpl( const Reference< XComponentContext > & xCtx )
65 : _xSMgr( xCtx->getServiceManager() )
66 , _xCtx( xCtx )
69 // XServiceInfo
70 OUString ResolverImpl::getImplementationName()
72 return "com.sun.star.comp.bridge.UnoUrlResolver";
75 sal_Bool ResolverImpl::supportsService( const OUString & rServiceName )
77 return cppu::supportsService(this, rServiceName);
80 Sequence< OUString > ResolverImpl::getSupportedServiceNames()
82 return { "com.sun.star.bridge.UnoUrlResolver" };
85 // XUnoUrlResolver
86 Reference< XInterface > ResolverImpl::resolve( const OUString & rUnoUrl )
88 OUString aProtocolDescr;
89 OUString aConnectDescr;
90 OUString aInstanceName;
91 try
93 cppu::UnoUrl aUrl(rUnoUrl);
94 aProtocolDescr = aUrl.getProtocol().getDescriptor();
95 aConnectDescr = aUrl.getConnection().getDescriptor();
96 aInstanceName = aUrl.getObjectName();
98 catch (const rtl::MalformedUriException & rEx)
100 throw ConnectionSetupException(rEx.getMessage(), nullptr);
103 Reference< XConnector > xConnector(
104 _xSMgr->createInstanceWithContext( "com.sun.star.connection.Connector", _xCtx ),
105 UNO_QUERY_THROW );
106 Reference< XConnection > xConnection( xConnector->connect( aConnectDescr ) );
108 // As soon as singletons are ready, switch to singleton !
109 Reference< XBridgeFactory2 > xBridgeFactory( BridgeFactory::create(_xCtx) );
111 // bridge
112 Reference< XBridge > xBridge( xBridgeFactory->createBridge(
113 OUString(), aProtocolDescr,
114 xConnection, Reference< XInstanceProvider >() ) );
116 Reference< XInterface > xRet( xBridge->getInstance( aInstanceName ) );
118 return xRet;
122 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
123 remotebridges_ResolverImpl_get_implementation(
124 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
126 return cppu::acquire(new ResolverImpl(context));
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */