Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / ucb / source / core / provprox.cxx
blob63fd79fc586fa71ce5460ff013ee83e85d25aee0
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 <osl/diagnose.h>
21 #include <osl/thread.h>
22 #include <rtl/strbuf.hxx>
23 #include "provprox.hxx"
24 #include <com/sun/star/lang/XInitialization.hpp>
26 using namespace com::sun::star::lang;
27 using namespace com::sun::star::ucb;
28 using namespace com::sun::star::uno;
34 // UcbContentProviderProxyFactory Implementation.
39 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
40 const Reference< XMultiServiceFactory >& rxSMgr )
41 : m_xSMgr( rxSMgr )
46 // virtual
47 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
51 // XServiceInfo methods.
55 XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
56 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
57 OUString( PROVIDER_FACTORY_SERVICE_NAME ) );
61 // Service factory implementation.
65 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
69 // XContentProviderFactory methods.
73 // virtual
74 Reference< XContentProvider > SAL_CALL
75 UcbContentProviderProxyFactory::createContentProvider(
76 const OUString& Service )
77 throw( RuntimeException, std::exception )
79 return Reference< XContentProvider >(
80 new UcbContentProviderProxy( m_xSMgr, Service ) );
86 // UcbContentProviderProxy Implementation.
91 UcbContentProviderProxy::UcbContentProviderProxy(
92 const Reference< XMultiServiceFactory >& rxSMgr,
93 const OUString& Service )
94 : m_aService( Service ),
95 m_bReplace( false ),
96 m_bRegister( false ),
97 m_xSMgr( rxSMgr )
102 // virtual
103 UcbContentProviderProxy::~UcbContentProviderProxy()
108 // XInterface methods.
109 void SAL_CALL UcbContentProviderProxy::acquire()
110 throw()
112 OWeakObject::acquire();
115 void SAL_CALL UcbContentProviderProxy::release()
116 throw()
118 OWeakObject::release();
121 // virtual
122 Any SAL_CALL
123 UcbContentProviderProxy::queryInterface( const Type & rType )
124 throw ( RuntimeException, std::exception )
126 Any aRet = cppu::queryInterface( rType,
127 static_cast< XTypeProvider * >( this ),
128 static_cast< XServiceInfo * >( this ),
129 static_cast< XContentProvider * >( this ),
130 static_cast< XParameterizedContentProvider * >( this ),
131 static_cast< XContentProviderSupplier * >( this ) );
133 if ( !aRet.hasValue() )
134 aRet = OWeakObject::queryInterface( rType );
136 if ( !aRet.hasValue() )
138 // Get original provider an forward the call...
139 osl::Guard< osl::Mutex > aGuard( m_aMutex );
140 Reference< XContentProvider > xProvider = getContentProvider();
141 if ( xProvider.is() )
142 aRet = xProvider->queryInterface( rType );
145 return aRet;
150 // XTypeProvider methods.
154 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
158 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \
159 throw( RuntimeException, std::exception )
161 // Get original provider an forward the call...
162 osl::Guard< osl::Mutex > aGuard( m_aMutex );
163 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
164 if ( xProvider.is() )
166 return xProvider->getTypes();
168 else
170 static cppu::OTypeCollection collection(
171 CPPU_TYPE_REF( XTypeProvider ),
172 CPPU_TYPE_REF( XServiceInfo ),
173 CPPU_TYPE_REF( XContentProvider ),
174 CPPU_TYPE_REF( XParameterizedContentProvider ),
175 CPPU_TYPE_REF( XContentProviderSupplier ) );
176 return collection.getTypes();
182 // XServiceInfo methods.
186 XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
187 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
188 OUString( PROVIDER_PROXY_SERVICE_NAME ) );
192 // XContentProvider methods.
196 // virtual
197 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
198 const Reference< XContentIdentifier >& Identifier )
199 throw( IllegalIdentifierException,
200 RuntimeException, std::exception )
202 // Get original provider an forward the call...
204 osl::Guard< osl::Mutex > aGuard( m_aMutex );
206 Reference< XContentProvider > xProvider = getContentProvider();
207 if ( xProvider.is() )
208 return xProvider->queryContent( Identifier );
210 return Reference< XContent >();
214 // virtual
215 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
216 const Reference< XContentIdentifier >& Id1,
217 const Reference< XContentIdentifier >& Id2 )
218 throw( RuntimeException, std::exception )
220 // Get original provider an forward the call...
222 osl::Guard< osl::Mutex > aGuard( m_aMutex );
223 Reference< XContentProvider > xProvider = getContentProvider();
224 if ( xProvider.is() )
225 return xProvider->compareContentIds( Id1, Id2 );
227 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
229 // @@@ What else?
230 return 0;
235 // XParameterizedContentProvider methods.
239 // virtual
240 Reference< XContentProvider > SAL_CALL
241 UcbContentProviderProxy::registerInstance( const OUString& Template,
242 const OUString& Arguments,
243 sal_Bool ReplaceExisting )
244 throw( IllegalArgumentException,
245 RuntimeException, std::exception )
247 // Just remember that this method was called ( and the params ).
249 osl::Guard< osl::Mutex > aGuard( m_aMutex );
251 if ( !m_bRegister )
253 // m_xTargetProvider = 0;
254 m_aTemplate = Template;
255 m_aArguments = Arguments;
256 m_bReplace = ReplaceExisting;
258 m_bRegister = true;
260 return this;
264 // virtual
265 Reference< XContentProvider > SAL_CALL
266 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
267 const OUString& Arguments )
268 throw( IllegalArgumentException,
269 RuntimeException, std::exception )
271 osl::Guard< osl::Mutex > aGuard( m_aMutex );
273 // registerInstance called at proxy and at original?
274 if ( m_bRegister && m_xTargetProvider.is() )
276 m_bRegister = false;
277 m_xTargetProvider = 0;
279 Reference< XParameterizedContentProvider >
280 xParamProvider( m_xProvider, UNO_QUERY );
281 if ( xParamProvider.is() )
285 xParamProvider->deregisterInstance( Template, Arguments );
287 catch ( IllegalIdentifierException const & )
289 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
290 "Caught IllegalIdentifierException!" );
295 return this;
300 // XContentProviderSupplier methods.
304 // virtual
305 Reference< XContentProvider > SAL_CALL
306 UcbContentProviderProxy::getContentProvider()
307 throw( RuntimeException, std::exception )
309 osl::Guard< osl::Mutex > aGuard( m_aMutex );
310 if ( !m_xProvider.is() )
314 m_xProvider
315 = Reference< XContentProvider >(
316 m_xSMgr->createInstance( m_aService ), UNO_QUERY );
317 if ( m_aArguments == "NoConfig" )
319 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
320 if(xInit.is()) {
321 Sequence<Any> aArgs(1);
322 aArgs[0] <<= m_aArguments;
323 xInit->initialize(aArgs);
327 catch ( RuntimeException const & )
329 throw;
331 catch ( Exception const & e)
333 SAL_INFO( "ucb.core", "Exception when getting content provider: " << e.Message );
336 // registerInstance called at proxy, but not yet at original?
337 if ( m_xProvider.is() && m_bRegister )
339 Reference< XParameterizedContentProvider >
340 xParamProvider( m_xProvider, UNO_QUERY );
341 if ( xParamProvider.is() )
345 m_xTargetProvider
346 = xParamProvider->registerInstance( m_aTemplate,
347 m_aArguments,
348 m_bReplace );
350 catch ( IllegalIdentifierException const & )
352 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
353 "Caught IllegalIdentifierException!" );
356 OSL_ENSURE( m_xTargetProvider.is(),
357 "UcbContentProviderProxy::getContentProvider - "
358 "No provider!" );
361 if ( !m_xTargetProvider.is() )
362 m_xTargetProvider = m_xProvider;
365 OSL_ENSURE( m_xProvider.is(),
366 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
367 return m_xTargetProvider;
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */