Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
26 : using namespace com::sun::star::lang;
27 : using namespace com::sun::star::ucb;
28 : using namespace com::sun::star::uno;
29 :
30 :
31 :
32 :
33 :
34 : // UcbContentProviderProxyFactory Implementation.
35 :
36 :
37 :
38 :
39 133 : UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
40 : const Reference< XMultiServiceFactory >& rxSMgr )
41 133 : : m_xSMgr( rxSMgr )
42 : {
43 133 : }
44 :
45 :
46 : // virtual
47 266 : UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
48 : {
49 266 : }
50 :
51 : // XServiceInfo methods.
52 :
53 :
54 :
55 718 : XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
56 : OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
57 : PROVIDER_FACTORY_SERVICE_NAME );
58 :
59 :
60 :
61 : // Service factory implementation.
62 :
63 :
64 :
65 133 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
66 :
67 :
68 :
69 : // XContentProviderFactory methods.
70 :
71 :
72 :
73 : // virtual
74 : Reference< XContentProvider > SAL_CALL
75 1849 : UcbContentProviderProxyFactory::createContentProvider(
76 : const OUString& Service )
77 : throw( RuntimeException, std::exception )
78 : {
79 : return Reference< XContentProvider >(
80 1849 : new UcbContentProviderProxy( m_xSMgr, Service ) );
81 : }
82 :
83 :
84 :
85 :
86 : // UcbContentProviderProxy Implementation.
87 :
88 :
89 :
90 :
91 1849 : UcbContentProviderProxy::UcbContentProviderProxy(
92 : const Reference< XMultiServiceFactory >& rxSMgr,
93 : const OUString& Service )
94 : : m_aService( Service ),
95 : m_bReplace( false ),
96 : m_bRegister( false ),
97 1849 : m_xSMgr( rxSMgr )
98 : {
99 1849 : }
100 :
101 :
102 : // virtual
103 3698 : UcbContentProviderProxy::~UcbContentProviderProxy()
104 : {
105 3698 : }
106 :
107 :
108 : // XInterface methods.
109 22934 : void SAL_CALL UcbContentProviderProxy::acquire()
110 : throw()
111 : {
112 22934 : OWeakObject::acquire();
113 22934 : }
114 :
115 22934 : void SAL_CALL UcbContentProviderProxy::release()
116 : throw()
117 : {
118 22934 : OWeakObject::release();
119 22934 : }
120 :
121 : // virtual
122 : Any SAL_CALL
123 8010 : UcbContentProviderProxy::queryInterface( const Type & rType )
124 : throw ( RuntimeException, std::exception )
125 : {
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 8010 : static_cast< XContentProviderSupplier * >( this ) );
132 :
133 8010 : if ( !aRet.hasValue() )
134 5842 : aRet = OWeakObject::queryInterface( rType );
135 :
136 8010 : if ( !aRet.hasValue() )
137 : {
138 : // Get original provider an forward the call...
139 5827 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
140 11654 : Reference< XContentProvider > xProvider = getContentProvider();
141 5827 : if ( xProvider.is() )
142 11654 : aRet = xProvider->queryInterface( rType );
143 : }
144 :
145 8010 : return aRet;
146 : }
147 :
148 :
149 :
150 : // XTypeProvider methods.
151 :
152 :
153 :
154 0 : XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
155 :
156 :
157 :
158 0 : Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \
159 : throw( RuntimeException, std::exception )
160 : {
161 : // Get original provider an forward the call...
162 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
163 0 : Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
164 0 : if ( xProvider.is() )
165 : {
166 0 : return xProvider->getTypes();
167 : }
168 : else
169 : {
170 : static cppu::OTypeCollection collection(
171 0 : CPPU_TYPE_REF( XTypeProvider ),
172 0 : CPPU_TYPE_REF( XServiceInfo ),
173 0 : CPPU_TYPE_REF( XContentProvider ),
174 0 : CPPU_TYPE_REF( XParameterizedContentProvider ),
175 0 : CPPU_TYPE_REF( XContentProviderSupplier ) );
176 0 : return collection.getTypes();
177 0 : }
178 : }
179 :
180 :
181 :
182 : // XServiceInfo methods.
183 :
184 :
185 :
186 0 : XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
187 : OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
188 : PROVIDER_PROXY_SERVICE_NAME );
189 :
190 :
191 :
192 : // XContentProvider methods.
193 :
194 :
195 :
196 : // virtual
197 0 : Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
198 : const Reference< XContentIdentifier >& Identifier )
199 : throw( IllegalIdentifierException,
200 : RuntimeException, std::exception )
201 : {
202 : // Get original provider an forward the call...
203 :
204 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
205 :
206 0 : Reference< XContentProvider > xProvider = getContentProvider();
207 0 : if ( xProvider.is() )
208 0 : return xProvider->queryContent( Identifier );
209 :
210 0 : return Reference< XContent >();
211 : }
212 :
213 :
214 : // virtual
215 0 : sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
216 : const Reference< XContentIdentifier >& Id1,
217 : const Reference< XContentIdentifier >& Id2 )
218 : throw( RuntimeException, std::exception )
219 : {
220 : // Get original provider an forward the call...
221 :
222 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
223 0 : Reference< XContentProvider > xProvider = getContentProvider();
224 0 : if ( xProvider.is() )
225 0 : return xProvider->compareContentIds( Id1, Id2 );
226 :
227 : // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
228 :
229 : // @@@ What else?
230 0 : return 0;
231 : }
232 :
233 :
234 :
235 : // XParameterizedContentProvider methods.
236 :
237 :
238 :
239 : // virtual
240 : Reference< XContentProvider > SAL_CALL
241 1848 : UcbContentProviderProxy::registerInstance( const OUString& Template,
242 : const OUString& Arguments,
243 : sal_Bool ReplaceExisting )
244 : throw( IllegalArgumentException,
245 : RuntimeException, std::exception )
246 : {
247 : // Just remember that this method was called ( and the params ).
248 :
249 1848 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
250 :
251 1848 : if ( !m_bRegister )
252 : {
253 : // m_xTargetProvider = 0;
254 1848 : m_aTemplate = Template;
255 1848 : m_aArguments = Arguments;
256 1848 : m_bReplace = ReplaceExisting;
257 :
258 1848 : m_bRegister = true;
259 : }
260 1848 : return this;
261 : }
262 :
263 :
264 : // virtual
265 : Reference< XContentProvider > SAL_CALL
266 0 : UcbContentProviderProxy::deregisterInstance( const OUString& Template,
267 : const OUString& Arguments )
268 : throw( IllegalArgumentException,
269 : RuntimeException, std::exception )
270 : {
271 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
272 :
273 : // registerInstance called at proxy and at original?
274 0 : if ( m_bRegister && m_xTargetProvider.is() )
275 : {
276 0 : m_bRegister = false;
277 0 : m_xTargetProvider = 0;
278 :
279 : Reference< XParameterizedContentProvider >
280 0 : xParamProvider( m_xProvider, UNO_QUERY );
281 0 : if ( xParamProvider.is() )
282 : {
283 : try
284 : {
285 0 : xParamProvider->deregisterInstance( Template, Arguments );
286 : }
287 0 : catch ( IllegalIdentifierException const & )
288 : {
289 : OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
290 : "Caught IllegalIdentifierException!" );
291 : }
292 0 : }
293 : }
294 :
295 0 : return this;
296 : }
297 :
298 :
299 :
300 : // XContentProviderSupplier methods.
301 :
302 :
303 :
304 : // virtual
305 : Reference< XContentProvider > SAL_CALL
306 6147 : UcbContentProviderProxy::getContentProvider()
307 : throw( RuntimeException, std::exception )
308 : {
309 6147 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
310 6147 : if ( !m_xProvider.is() )
311 : {
312 : try
313 : {
314 : m_xProvider
315 642 : = Reference< XContentProvider >(
316 642 : m_xSMgr->createInstance( m_aService ), UNO_QUERY );
317 321 : if ( m_aArguments == "NoConfig" )
318 : {
319 0 : Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
320 0 : if(xInit.is()) {
321 0 : Sequence<Any> aArgs(1);
322 0 : aArgs[0] <<= m_aArguments;
323 0 : xInit->initialize(aArgs);
324 0 : }
325 : }
326 : }
327 0 : catch ( RuntimeException const & )
328 : {
329 0 : throw;
330 : }
331 0 : catch ( Exception const & e)
332 : {
333 : SAL_INFO( "ucb.core", "Exception when getting content provider: " << e.Message );
334 : }
335 :
336 : // registerInstance called at proxy, but not yet at original?
337 321 : if ( m_xProvider.is() && m_bRegister )
338 : {
339 : Reference< XParameterizedContentProvider >
340 321 : xParamProvider( m_xProvider, UNO_QUERY );
341 321 : if ( xParamProvider.is() )
342 : {
343 : try
344 : {
345 : m_xTargetProvider
346 0 : = xParamProvider->registerInstance( m_aTemplate,
347 : m_aArguments,
348 0 : m_bReplace );
349 : }
350 0 : catch ( IllegalIdentifierException const & )
351 : {
352 : OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
353 : "Caught IllegalIdentifierException!" );
354 : }
355 :
356 : OSL_ENSURE( m_xTargetProvider.is(),
357 : "UcbContentProviderProxy::getContentProvider - "
358 : "No provider!" );
359 321 : }
360 : }
361 321 : if ( !m_xTargetProvider.is() )
362 321 : m_xTargetProvider = m_xProvider;
363 : }
364 :
365 : OSL_ENSURE( m_xProvider.is(),
366 : OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
367 6147 : return m_xTargetProvider;
368 : }
369 :
370 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|