update dev300-m58
[ooovba.git] / ucb / source / core / provprox.cxx
blobb3fc75376cfd780853e82adc5320b113dc499194
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: provprox.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <osl/diagnose.h>
34 #include "provprox.hxx"
35 #include <com/sun/star/lang/XInitialization.hpp>
37 using namespace rtl;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::ucb;
40 using namespace com::sun::star::uno;
42 //=========================================================================
43 //=========================================================================
45 // UcbContentProviderProxyFactory Implementation.
47 //=========================================================================
48 //=========================================================================
50 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
51 const Reference< XMultiServiceFactory >& rxSMgr )
52 : m_xSMgr( rxSMgr )
56 //=========================================================================
57 // virtual
58 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
62 //=========================================================================
64 // XInterface methods.
66 //=========================================================================
68 XINTERFACE_IMPL_3( UcbContentProviderProxyFactory,
69 XTypeProvider,
70 XServiceInfo,
71 XContentProviderFactory );
73 //=========================================================================
75 // XTypeProvider methods.
77 //=========================================================================
79 XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory,
80 XTypeProvider,
81 XServiceInfo,
82 XContentProviderFactory );
84 //=========================================================================
86 // XServiceInfo methods.
88 //=========================================================================
90 XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
91 OUString::createFromAscii(
92 "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
93 OUString::createFromAscii(
94 PROVIDER_FACTORY_SERVICE_NAME ) );
96 //=========================================================================
98 // Service factory implementation.
100 //=========================================================================
102 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
104 //=========================================================================
106 // XContentProviderFactory methods.
108 //=========================================================================
110 // virtual
111 Reference< XContentProvider > SAL_CALL
112 UcbContentProviderProxyFactory::createContentProvider(
113 const OUString& Service )
114 throw( RuntimeException )
116 return Reference< XContentProvider >(
117 new UcbContentProviderProxy( m_xSMgr, Service ) );
120 //=========================================================================
121 //=========================================================================
123 // UcbContentProviderProxy Implementation.
125 //=========================================================================
126 //=========================================================================
128 UcbContentProviderProxy::UcbContentProviderProxy(
129 const Reference< XMultiServiceFactory >& rxSMgr,
130 const OUString& Service )
131 : m_aService( Service ),
132 m_bReplace( sal_False ),
133 m_bRegister( sal_False ),
134 m_xSMgr( rxSMgr )
138 //=========================================================================
139 // virtual
140 UcbContentProviderProxy::~UcbContentProviderProxy()
144 //=========================================================================
146 // XInterface methods.
148 //=========================================================================
150 XINTERFACE_COMMON_IMPL( UcbContentProviderProxy );
152 //============================================================================
153 // virtual
154 Any SAL_CALL
155 UcbContentProviderProxy::queryInterface( const Type & rType )
156 throw ( RuntimeException )
158 Any aRet = cppu::queryInterface( rType,
159 static_cast< XTypeProvider * >( this ),
160 static_cast< XServiceInfo * >( this ),
161 static_cast< XContentProvider * >( this ),
162 static_cast< XParameterizedContentProvider * >( this ),
163 static_cast< XContentProviderSupplier * >( this ) );
165 if ( !aRet.hasValue() )
166 aRet = OWeakObject::queryInterface( rType );
168 if ( !aRet.hasValue() )
170 // Get original provider an forward the call...
171 osl::Guard< osl::Mutex > aGuard( m_aMutex );
172 Reference< XContentProvider > xProvider = getContentProvider();
173 if ( xProvider.is() )
174 aRet = xProvider->queryInterface( rType );
177 return aRet;
180 //=========================================================================
182 // XTypeProvider methods.
184 //=========================================================================
186 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
188 //=========================================================================
190 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \
191 throw( RuntimeException )
193 // Get original provider an forward the call...
194 osl::Guard< osl::Mutex > aGuard( m_aMutex );
195 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
196 if ( xProvider.is() )
198 return xProvider->getTypes();
200 else
202 static cppu::OTypeCollection collection(
203 CPPU_TYPE_REF( XTypeProvider ),
204 CPPU_TYPE_REF( XServiceInfo ),
205 CPPU_TYPE_REF( XContentProvider ),
206 CPPU_TYPE_REF( XParameterizedContentProvider ),
207 CPPU_TYPE_REF( XContentProviderSupplier ) );
208 return collection.getTypes();
212 //=========================================================================
214 // XServiceInfo methods.
216 //=========================================================================
218 XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
219 OUString::createFromAscii(
220 "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
221 OUString::createFromAscii(
222 PROVIDER_PROXY_SERVICE_NAME ) );
224 //=========================================================================
226 // XContentProvider methods.
228 //=========================================================================
230 // virtual
231 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
232 const Reference< XContentIdentifier >& Identifier )
233 throw( IllegalIdentifierException,
234 RuntimeException )
236 // Get original provider an forward the call...
238 osl::Guard< osl::Mutex > aGuard( m_aMutex );
240 Reference< XContentProvider > xProvider = getContentProvider();
241 if ( xProvider.is() )
242 return xProvider->queryContent( Identifier );
244 return Reference< XContent >();
247 //=========================================================================
248 // virtual
249 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
250 const Reference< XContentIdentifier >& Id1,
251 const Reference< XContentIdentifier >& Id2 )
252 throw( RuntimeException )
254 // Get original provider an forward the call...
256 osl::Guard< osl::Mutex > aGuard( m_aMutex );
257 Reference< XContentProvider > xProvider = getContentProvider();
258 if ( xProvider.is() )
259 return xProvider->compareContentIds( Id1, Id2 );
261 // OSL_ENSURE( sal_False,
262 // "UcbContentProviderProxy::compareContentIds - No provider!" );
264 // @@@ What else?
265 return 0;
268 //=========================================================================
270 // XParameterizedContentProvider methods.
272 //=========================================================================
274 // virtual
275 Reference< XContentProvider > SAL_CALL
276 UcbContentProviderProxy::registerInstance( const OUString& Template,
277 const OUString& Arguments,
278 sal_Bool ReplaceExisting )
279 throw( IllegalArgumentException,
280 RuntimeException )
282 // Just remember that this method was called ( and the params ).
284 osl::Guard< osl::Mutex > aGuard( m_aMutex );
286 if ( !m_bRegister )
288 // m_xTargetProvider = 0;
289 m_aTemplate = Template;
290 m_aArguments = Arguments;
291 m_bReplace = ReplaceExisting;
293 m_bRegister = sal_True;
295 return this;
298 //=========================================================================
299 // virtual
300 Reference< XContentProvider > SAL_CALL
301 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
302 const OUString& Arguments )
303 throw( IllegalArgumentException,
304 RuntimeException )
306 osl::Guard< osl::Mutex > aGuard( m_aMutex );
308 // registerInstance called at proxy and at original?
309 if ( m_bRegister && m_xTargetProvider.is() )
311 m_bRegister = sal_False;
312 m_xTargetProvider = 0;
314 Reference< XParameterizedContentProvider >
315 xParamProvider( m_xProvider, UNO_QUERY );
316 if ( xParamProvider.is() )
320 xParamProvider->deregisterInstance( Template, Arguments );
322 catch ( IllegalIdentifierException const & )
324 OSL_ENSURE( sal_False,
325 "UcbContentProviderProxy::deregisterInstance - "
326 "Caught IllegalIdentifierException!" );
331 return this;
334 //=========================================================================
336 // XContentProviderSupplier methods.
338 //=========================================================================
340 // virtual
341 Reference< XContentProvider > SAL_CALL
342 UcbContentProviderProxy::getContentProvider()
343 throw( RuntimeException )
345 osl::Guard< osl::Mutex > aGuard( m_aMutex );
346 if ( !m_xProvider.is() )
350 m_xProvider
351 = Reference< XContentProvider >(
352 m_xSMgr->createInstance( m_aService ), UNO_QUERY );
353 if(m_aArguments.compareToAscii("NoConfig") == 0)
355 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
356 if(xInit.is()) {
357 Sequence<Any> aArgs(1);
358 aArgs[0] <<= m_aArguments;
359 xInit->initialize(aArgs);
363 catch ( RuntimeException const & )
365 throw;
367 catch ( Exception const & )
371 // registerInstance called at proxy, but not yet at original?
372 if ( m_xProvider.is() && m_bRegister )
374 Reference< XParameterizedContentProvider >
375 xParamProvider( m_xProvider, UNO_QUERY );
376 if ( xParamProvider.is() )
380 m_xTargetProvider
381 = xParamProvider->registerInstance( m_aTemplate,
382 m_aArguments,
383 m_bReplace );
385 catch ( IllegalIdentifierException const & )
387 OSL_ENSURE( sal_False,
388 "UcbContentProviderProxy::getContentProvider - "
389 "Caught IllegalIdentifierException!" );
392 OSL_ENSURE( m_xTargetProvider.is(),
393 "UcbContentProviderProxy::getContentProvider - "
394 "No provider!" );
397 if ( !m_xTargetProvider.is() )
398 m_xTargetProvider = m_xProvider;
401 OSL_ENSURE( m_xProvider.is(),
402 "UcbContentProviderProxy::getContentProvider - No provider!" );
403 return m_xTargetProvider;