1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucb.hxx"
26 #include <osl/diagnose.h>
27 #include "provprox.hxx"
28 #include <com/sun/star/lang/XInitialization.hpp>
29
30 using namespace rtl;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::ucb;
33 using namespace com::sun::star::uno;
34
35 //=========================================================================
36 //=========================================================================
37 //
38 // UcbContentProviderProxyFactory Implementation.
39 //
40 //=========================================================================
41 //=========================================================================
42
UcbContentProviderProxyFactory(const Reference<XMultiServiceFactory> & rxSMgr)43 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
44 const Reference< XMultiServiceFactory >& rxSMgr )
45 : m_xSMgr( rxSMgr )
46 {
47 }
48
49 //=========================================================================
50 // virtual
~UcbContentProviderProxyFactory()51 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
52 {
53 }
54
55 //=========================================================================
56 //
57 // XInterface methods.
58 //
59 //=========================================================================
60
61 XINTERFACE_IMPL_3( UcbContentProviderProxyFactory,
62 XTypeProvider,
63 XServiceInfo,
64 XContentProviderFactory );
65
66 //=========================================================================
67 //
68 // XTypeProvider methods.
69 //
70 //=========================================================================
71
72 XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory,
73 XTypeProvider,
74 XServiceInfo,
75 XContentProviderFactory );
76
77 //=========================================================================
78 //
79 // XServiceInfo methods.
80 //
81 //=========================================================================
82
83 XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
84 OUString::createFromAscii(
85 "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
86 OUString::createFromAscii(
87 PROVIDER_FACTORY_SERVICE_NAME ) );
88
89 //=========================================================================
90 //
91 // Service factory implementation.
92 //
93 //=========================================================================
94
95 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
96
97 //=========================================================================
98 //
99 // XContentProviderFactory methods.
100 //
101 //=========================================================================
102
103 // virtual
104 Reference< XContentProvider > SAL_CALL
createContentProvider(const OUString & Service)105 UcbContentProviderProxyFactory::createContentProvider(
106 const OUString& Service )
107 throw( RuntimeException )
108 {
109 return Reference< XContentProvider >(
110 new UcbContentProviderProxy( m_xSMgr, Service ) );
111 }
112
113 //=========================================================================
114 //=========================================================================
115 //
116 // UcbContentProviderProxy Implementation.
117 //
118 //=========================================================================
119 //=========================================================================
120
UcbContentProviderProxy(const Reference<XMultiServiceFactory> & rxSMgr,const OUString & Service)121 UcbContentProviderProxy::UcbContentProviderProxy(
122 const Reference< XMultiServiceFactory >& rxSMgr,
123 const OUString& Service )
124 : m_aService( Service ),
125 m_bReplace( sal_False ),
126 m_bRegister( sal_False ),
127 m_xSMgr( rxSMgr )
128 {
129 }
130
131 //=========================================================================
132 // virtual
~UcbContentProviderProxy()133 UcbContentProviderProxy::~UcbContentProviderProxy()
134 {
135 }
136
137 //=========================================================================
138 //
139 // XInterface methods.
140 //
141 //=========================================================================
142
143 XINTERFACE_COMMON_IMPL( UcbContentProviderProxy );
144
145 //============================================================================
146 // virtual
147 Any SAL_CALL
queryInterface(const Type & rType)148 UcbContentProviderProxy::queryInterface( const Type & rType )
149 throw ( RuntimeException )
150 {
151 Any aRet = cppu::queryInterface( rType,
152 static_cast< XTypeProvider * >( this ),
153 static_cast< XServiceInfo * >( this ),
154 static_cast< XContentProvider * >( this ),
155 static_cast< XParameterizedContentProvider * >( this ),
156 static_cast< XContentProviderSupplier * >( this ) );
157
158 if ( !aRet.hasValue() )
159 aRet = OWeakObject::queryInterface( rType );
160
161 if ( !aRet.hasValue() )
162 {
163 // Get original provider and forward the call...
164 osl::Guard< osl::Mutex > aGuard( m_aMutex );
165 Reference< XContentProvider > xProvider = getContentProvider();
166 if ( xProvider.is() )
167 aRet = xProvider->queryInterface( rType );
168 }
169
170 return aRet;
171 }
172
173 //=========================================================================
174 //
175 // XTypeProvider methods.
176 //
177 //=========================================================================
178
179 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
180
181 //=========================================================================
182
getTypes()183 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \
184 throw( RuntimeException )
185 {
186 // Get original provider and forward the call...
187 osl::Guard< osl::Mutex > aGuard( m_aMutex );
188 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
189 if ( xProvider.is() )
190 {
191 return xProvider->getTypes();
192 }
193 else
194 {
195 static cppu::OTypeCollection collection(
196 CPPU_TYPE_REF( XTypeProvider ),
197 CPPU_TYPE_REF( XServiceInfo ),
198 CPPU_TYPE_REF( XContentProvider ),
199 CPPU_TYPE_REF( XParameterizedContentProvider ),
200 CPPU_TYPE_REF( XContentProviderSupplier ) );
201 return collection.getTypes();
202 }
203 }
204
205 //=========================================================================
206 //
207 // XServiceInfo methods.
208 //
209 //=========================================================================
210
211 XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
212 OUString::createFromAscii(
213 "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
214 OUString::createFromAscii(
215 PROVIDER_PROXY_SERVICE_NAME ) );
216
217 //=========================================================================
218 //
219 // XContentProvider methods.
220 //
221 //=========================================================================
222
223 // virtual
queryContent(const Reference<XContentIdentifier> & Identifier)224 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
225 const Reference< XContentIdentifier >& Identifier )
226 throw( IllegalIdentifierException,
227 RuntimeException )
228 {
229 // Get original provider and forward the call...
230
231 osl::Guard< osl::Mutex > aGuard( m_aMutex );
232
233 Reference< XContentProvider > xProvider = getContentProvider();
234 if ( xProvider.is() )
235 return xProvider->queryContent( Identifier );
236
237 return Reference< XContent >();
238 }
239
240 //=========================================================================
241 // virtual
compareContentIds(const Reference<XContentIdentifier> & Id1,const Reference<XContentIdentifier> & Id2)242 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
243 const Reference< XContentIdentifier >& Id1,
244 const Reference< XContentIdentifier >& Id2 )
245 throw( RuntimeException )
246 {
247 // Get original provider and forward the call...
248
249 osl::Guard< osl::Mutex > aGuard( m_aMutex );
250 Reference< XContentProvider > xProvider = getContentProvider();
251 if ( xProvider.is() )
252 return xProvider->compareContentIds( Id1, Id2 );
253
254 // OSL_ENSURE( sal_False,
255 // "UcbContentProviderProxy::compareContentIds - No provider!" );
256
257 // @@@ What else?
258 return 0;
259 }
260
261 //=========================================================================
262 //
263 // XParameterizedContentProvider methods.
264 //
265 //=========================================================================
266
267 // virtual
268 Reference< XContentProvider > SAL_CALL
registerInstance(const OUString & Template,const OUString & Arguments,sal_Bool ReplaceExisting)269 UcbContentProviderProxy::registerInstance( const OUString& Template,
270 const OUString& Arguments,
271 sal_Bool ReplaceExisting )
272 throw( IllegalArgumentException,
273 RuntimeException )
274 {
275 // Just remember that this method was called ( and the params ).
276
277 osl::Guard< osl::Mutex > aGuard( m_aMutex );
278
279 if ( !m_bRegister )
280 {
281 // m_xTargetProvider = 0;
282 m_aTemplate = Template;
283 m_aArguments = Arguments;
284 m_bReplace = ReplaceExisting;
285
286 m_bRegister = sal_True;
287 }
288 return this;
289 }
290
291 //=========================================================================
292 // virtual
293 Reference< XContentProvider > SAL_CALL
deregisterInstance(const OUString & Template,const OUString & Arguments)294 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
295 const OUString& Arguments )
296 throw( IllegalArgumentException,
297 RuntimeException )
298 {
299 osl::Guard< osl::Mutex > aGuard( m_aMutex );
300
301 // registerInstance called at proxy and at original?
302 if ( m_bRegister && m_xTargetProvider.is() )
303 {
304 m_bRegister = sal_False;
305 m_xTargetProvider = 0;
306
307 Reference< XParameterizedContentProvider >
308 xParamProvider( m_xProvider, UNO_QUERY );
309 if ( xParamProvider.is() )
310 {
311 try
312 {
313 xParamProvider->deregisterInstance( Template, Arguments );
314 }
315 catch ( IllegalIdentifierException const & )
316 {
317 OSL_ENSURE( sal_False,
318 "UcbContentProviderProxy::deregisterInstance - "
319 "Caught IllegalIdentifierException!" );
320 }
321 }
322 }
323
324 return this;
325 }
326
327 //=========================================================================
328 //
329 // XContentProviderSupplier methods.
330 //
331 //=========================================================================
332
333 // virtual
334 Reference< XContentProvider > SAL_CALL
getContentProvider()335 UcbContentProviderProxy::getContentProvider()
336 throw( RuntimeException )
337 {
338 osl::Guard< osl::Mutex > aGuard( m_aMutex );
339 if ( !m_xProvider.is() )
340 {
341 try
342 {
343 m_xProvider
344 = Reference< XContentProvider >(
345 m_xSMgr->createInstance( m_aService ), UNO_QUERY );
346 if(m_aArguments.compareToAscii("NoConfig") == 0)
347 {
348 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
349 if(xInit.is()) {
350 Sequence<Any> aArgs(1);
351 aArgs[0] <<= m_aArguments;
352 xInit->initialize(aArgs);
353 }
354 }
355 }
356 catch ( RuntimeException const & )
357 {
358 throw;
359 }
360 catch ( Exception const & )
361 {
362 }
363
364 // registerInstance called at proxy, but not yet at original?
365 if ( m_xProvider.is() && m_bRegister )
366 {
367 Reference< XParameterizedContentProvider >
368 xParamProvider( m_xProvider, UNO_QUERY );
369 if ( xParamProvider.is() )
370 {
371 try
372 {
373 m_xTargetProvider
374 = xParamProvider->registerInstance( m_aTemplate,
375 m_aArguments,
376 m_bReplace );
377 }
378 catch ( IllegalIdentifierException const & )
379 {
380 OSL_ENSURE( sal_False,
381 "UcbContentProviderProxy::getContentProvider - "
382 "Caught IllegalIdentifierException!" );
383 }
384
385 OSL_ENSURE( m_xTargetProvider.is(),
386 "UcbContentProviderProxy::getContentProvider - "
387 "No provider!" );
388 }
389 }
390 if ( !m_xTargetProvider.is() )
391 m_xTargetProvider = m_xProvider;
392 }
393
394 OSL_ENSURE( m_xProvider.is(),
395 "UcbContentProviderProxy::getContentProvider - No provider!" );
396 return m_xTargetProvider;
397 }
398