1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <osl/diagnose.h>
30 #include <osl/thread.h>
31 #include <rtl/strbuf.hxx>
32 #include "provprox.hxx"
33 #include <com/sun/star/lang/XInitialization.hpp>
35 using namespace com::sun::star::lang
;
36 using namespace com::sun::star::ucb
;
37 using namespace com::sun::star::uno
;
39 using ::rtl::OUString
;
41 //=========================================================================
42 //=========================================================================
44 // UcbContentProviderProxyFactory Implementation.
46 //=========================================================================
47 //=========================================================================
49 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
50 const Reference
< XMultiServiceFactory
>& rxSMgr
)
55 //=========================================================================
57 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
61 //=========================================================================
63 // XInterface methods.
65 //=========================================================================
67 XINTERFACE_IMPL_3( UcbContentProviderProxyFactory
,
70 XContentProviderFactory
);
72 //=========================================================================
74 // XTypeProvider methods.
76 //=========================================================================
78 XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory
,
81 XContentProviderFactory
);
83 //=========================================================================
85 // XServiceInfo methods.
87 //=========================================================================
89 XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory
,
90 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
91 OUString( PROVIDER_FACTORY_SERVICE_NAME
) );
93 //=========================================================================
95 // Service factory implementation.
97 //=========================================================================
99 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory
);
101 //=========================================================================
103 // XContentProviderFactory methods.
105 //=========================================================================
108 Reference
< XContentProvider
> SAL_CALL
109 UcbContentProviderProxyFactory::createContentProvider(
110 const OUString
& Service
)
111 throw( RuntimeException
)
113 return Reference
< XContentProvider
>(
114 new UcbContentProviderProxy( m_xSMgr
, Service
) );
117 //=========================================================================
118 //=========================================================================
120 // UcbContentProviderProxy Implementation.
122 //=========================================================================
123 //=========================================================================
125 UcbContentProviderProxy::UcbContentProviderProxy(
126 const Reference
< XMultiServiceFactory
>& rxSMgr
,
127 const OUString
& Service
)
128 : m_aService( Service
),
129 m_bReplace( sal_False
),
130 m_bRegister( sal_False
),
135 //=========================================================================
137 UcbContentProviderProxy::~UcbContentProviderProxy()
141 //=========================================================================
143 // XInterface methods.
145 //=========================================================================
147 XINTERFACE_COMMON_IMPL( UcbContentProviderProxy
);
149 //============================================================================
152 UcbContentProviderProxy::queryInterface( const Type
& rType
)
153 throw ( RuntimeException
)
155 Any aRet
= cppu::queryInterface( rType
,
156 static_cast< XTypeProvider
* >( this ),
157 static_cast< XServiceInfo
* >( this ),
158 static_cast< XContentProvider
* >( this ),
159 static_cast< XParameterizedContentProvider
* >( this ),
160 static_cast< XContentProviderSupplier
* >( this ) );
162 if ( !aRet
.hasValue() )
163 aRet
= OWeakObject::queryInterface( rType
);
165 if ( !aRet
.hasValue() )
167 // Get original provider an forward the call...
168 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
169 Reference
< XContentProvider
> xProvider
= getContentProvider();
170 if ( xProvider
.is() )
171 aRet
= xProvider
->queryInterface( rType
);
177 //=========================================================================
179 // XTypeProvider methods.
181 //=========================================================================
183 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy
);
185 //=========================================================================
187 Sequence
< Type
> SAL_CALL
UcbContentProviderProxy::getTypes() \
188 throw( RuntimeException
)
190 // Get original provider an forward the call...
191 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
192 Reference
< XTypeProvider
> xProvider( getContentProvider(), UNO_QUERY
);
193 if ( xProvider
.is() )
195 return xProvider
->getTypes();
199 static cppu::OTypeCollection
collection(
200 CPPU_TYPE_REF( XTypeProvider
),
201 CPPU_TYPE_REF( XServiceInfo
),
202 CPPU_TYPE_REF( XContentProvider
),
203 CPPU_TYPE_REF( XParameterizedContentProvider
),
204 CPPU_TYPE_REF( XContentProviderSupplier
) );
205 return collection
.getTypes();
209 //=========================================================================
211 // XServiceInfo methods.
213 //=========================================================================
215 XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy
,
216 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
217 OUString( PROVIDER_PROXY_SERVICE_NAME
) );
219 //=========================================================================
221 // XContentProvider methods.
223 //=========================================================================
226 Reference
< XContent
> SAL_CALL
UcbContentProviderProxy::queryContent(
227 const Reference
< XContentIdentifier
>& Identifier
)
228 throw( IllegalIdentifierException
,
231 // Get original provider an forward the call...
233 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
235 Reference
< XContentProvider
> xProvider
= getContentProvider();
236 if ( xProvider
.is() )
237 return xProvider
->queryContent( Identifier
);
239 return Reference
< XContent
>();
242 //=========================================================================
244 sal_Int32 SAL_CALL
UcbContentProviderProxy::compareContentIds(
245 const Reference
< XContentIdentifier
>& Id1
,
246 const Reference
< XContentIdentifier
>& Id2
)
247 throw( RuntimeException
)
249 // Get original provider an forward the call...
251 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
252 Reference
< XContentProvider
> xProvider
= getContentProvider();
253 if ( xProvider
.is() )
254 return xProvider
->compareContentIds( Id1
, Id2
);
256 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
262 //=========================================================================
264 // XParameterizedContentProvider methods.
266 //=========================================================================
269 Reference
< XContentProvider
> SAL_CALL
270 UcbContentProviderProxy::registerInstance( const OUString
& Template
,
271 const OUString
& Arguments
,
272 sal_Bool ReplaceExisting
)
273 throw( IllegalArgumentException
,
276 // Just remember that this method was called ( and the params ).
278 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
282 // m_xTargetProvider = 0;
283 m_aTemplate
= Template
;
284 m_aArguments
= Arguments
;
285 m_bReplace
= ReplaceExisting
;
287 m_bRegister
= sal_True
;
292 //=========================================================================
294 Reference
< XContentProvider
> SAL_CALL
295 UcbContentProviderProxy::deregisterInstance( const OUString
& Template
,
296 const OUString
& Arguments
)
297 throw( IllegalArgumentException
,
300 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
302 // registerInstance called at proxy and at original?
303 if ( m_bRegister
&& m_xTargetProvider
.is() )
305 m_bRegister
= sal_False
;
306 m_xTargetProvider
= 0;
308 Reference
< XParameterizedContentProvider
>
309 xParamProvider( m_xProvider
, UNO_QUERY
);
310 if ( xParamProvider
.is() )
314 xParamProvider
->deregisterInstance( Template
, Arguments
);
316 catch ( IllegalIdentifierException
const & )
318 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
319 "Caught IllegalIdentifierException!" );
327 //=========================================================================
329 // XContentProviderSupplier methods.
331 //=========================================================================
334 Reference
< XContentProvider
> SAL_CALL
335 UcbContentProviderProxy::getContentProvider()
336 throw( RuntimeException
)
338 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
339 if ( !m_xProvider
.is() )
344 = Reference
< XContentProvider
>(
345 m_xSMgr
->createInstance( m_aService
), UNO_QUERY
);
346 if ( m_aArguments
== "NoConfig" )
348 Reference
<XInitialization
> xInit(m_xProvider
,UNO_QUERY
);
350 Sequence
<Any
> aArgs(1);
351 aArgs
[0] <<= m_aArguments
;
352 xInit
->initialize(aArgs
);
356 catch ( RuntimeException
const & )
360 catch ( Exception
const & )
364 // registerInstance called at proxy, but not yet at original?
365 if ( m_xProvider
.is() && m_bRegister
)
367 Reference
< XParameterizedContentProvider
>
368 xParamProvider( m_xProvider
, UNO_QUERY
);
369 if ( xParamProvider
.is() )
374 = xParamProvider
->registerInstance( m_aTemplate
,
378 catch ( IllegalIdentifierException
const & )
380 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
381 "Caught IllegalIdentifierException!" );
384 OSL_ENSURE( m_xTargetProvider
.is(),
385 "UcbContentProviderProxy::getContentProvider - "
389 if ( !m_xTargetProvider
.is() )
390 m_xTargetProvider
= m_xProvider
;
393 OSL_ENSURE( m_xProvider
.is(),
394 rtl::OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(rtl::OUStringToOString(m_aService
, osl_getThreadTextEncoding())).append(".").getStr() );
395 return m_xTargetProvider
;
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */