Branch data 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 : :
21 : : /**************************************************************************
22 : : TODO
23 : : **************************************************************************
24 : :
25 : : - This implementation is far away from completion. It has no interface
26 : : for changes notifications etc.
27 : :
28 : : *************************************************************************/
29 : : #include <com/sun/star/ucb/ListActionType.hpp>
30 : : #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
31 : : #include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp>
32 : : #include <com/sun/star/ucb/XSourceInitialization.hpp>
33 : : #include <cppuhelper/interfacecontainer.hxx>
34 : : #include <ucbhelper/resultsethelper.hxx>
35 : :
36 : : #include "osl/diagnose.h"
37 : :
38 : : using namespace com::sun::star;
39 : :
40 : : //=========================================================================
41 : : //=========================================================================
42 : : //
43 : : // ResultSetImplHelper Implementation.
44 : : //
45 : : //=========================================================================
46 : : //=========================================================================
47 : :
48 : : namespace ucbhelper {
49 : :
50 : : //=========================================================================
51 : 65 : ResultSetImplHelper::ResultSetImplHelper(
52 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
53 : : const com::sun::star::ucb::OpenCommandArgument2& rCommand )
54 : : : m_pDisposeEventListeners( 0 ),
55 : : m_bStatic( sal_False ),
56 : : m_bInitDone( sal_False ),
57 : : m_aCommand( rCommand ),
58 [ + - ][ + - ]: 65 : m_xSMgr( rxSMgr )
59 : : {
60 : 65 : }
61 : :
62 : : //=========================================================================
63 : : // virtual
64 [ + - ][ + - ]: 65 : ResultSetImplHelper::~ResultSetImplHelper()
65 : : {
66 [ - + ][ # # ]: 65 : delete m_pDisposeEventListeners;
67 [ - + ]: 65 : }
68 : :
69 : : //=========================================================================
70 : : //
71 : : // XInterface methods.
72 : : //
73 : : //=========================================================================
74 : :
75 [ # # ][ # # ]: 516 : XINTERFACE_IMPL_4( ResultSetImplHelper,
[ # # ]
76 : : lang::XTypeProvider,
77 : : lang::XServiceInfo,
78 : : lang::XComponent, /* base of XDynamicResultSet */
79 : : com::sun::star::ucb::XDynamicResultSet );
80 : :
81 : : //=========================================================================
82 : : //
83 : : // XTypeProvider methods.
84 : : //
85 : : //=========================================================================
86 : :
87 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_3( ResultSetImplHelper,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
88 : : lang::XTypeProvider,
89 : : lang::XServiceInfo,
90 : : com::sun::star::ucb::XDynamicResultSet );
91 : :
92 : : //=========================================================================
93 : : //
94 : : // XServiceInfo methods.
95 : : //
96 : : //=========================================================================
97 : :
98 [ # # ][ # # ]: 0 : XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper,
[ # # ][ # # ]
[ # # ][ # # ]
99 : : rtl::OUString(
100 : : "ResultSetImplHelper" ),
101 : : rtl::OUString(
102 : : DYNAMICRESULTSET_SERVICE_NAME ) );
103 : :
104 : : //=========================================================================
105 : : //
106 : : // XComponent methods.
107 : : //
108 : : //=========================================================================
109 : :
110 : : // virtual
111 : 0 : void SAL_CALL ResultSetImplHelper::dispose()
112 : : throw( uno::RuntimeException )
113 : : {
114 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
115 : :
116 [ # # ][ # # ]: 0 : if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
[ # # ][ # # ]
117 : : {
118 [ # # ]: 0 : lang::EventObject aEvt;
119 [ # # ]: 0 : aEvt.Source = static_cast< lang::XComponent * >( this );
120 [ # # ][ # # ]: 0 : m_pDisposeEventListeners->disposeAndClear( aEvt );
121 [ # # ]: 0 : }
122 : 0 : }
123 : :
124 : : //=========================================================================
125 : : // virtual
126 : 0 : void SAL_CALL ResultSetImplHelper::addEventListener(
127 : : const uno::Reference< lang::XEventListener >& Listener )
128 : : throw( uno::RuntimeException )
129 : : {
130 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
131 : :
132 [ # # ]: 0 : if ( !m_pDisposeEventListeners )
133 : : m_pDisposeEventListeners
134 [ # # ]: 0 : = new cppu::OInterfaceContainerHelper( m_aMutex );
135 : :
136 [ # # ][ # # ]: 0 : m_pDisposeEventListeners->addInterface( Listener );
137 : 0 : }
138 : :
139 : : //=========================================================================
140 : : // virtual
141 : 0 : void SAL_CALL ResultSetImplHelper::removeEventListener(
142 : : const uno::Reference< lang::XEventListener >& Listener )
143 : : throw( uno::RuntimeException )
144 : : {
145 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
146 : :
147 [ # # ]: 0 : if ( m_pDisposeEventListeners )
148 [ # # ][ # # ]: 0 : m_pDisposeEventListeners->removeInterface( Listener );
149 : 0 : }
150 : :
151 : : //=========================================================================
152 : : //
153 : : // XDynamicResultSet methods.
154 : : //
155 : : //=========================================================================
156 : :
157 : : // virtual
158 : : uno::Reference< sdbc::XResultSet > SAL_CALL
159 : 65 : ResultSetImplHelper::getStaticResultSet()
160 : : throw( com::sun::star::ucb::ListenerAlreadySetException,
161 : : uno::RuntimeException )
162 : : {
163 [ + - ]: 65 : osl::MutexGuard aGuard( m_aMutex );
164 : :
165 [ - + ]: 65 : if ( m_xListener.is() )
166 [ # # ]: 0 : throw com::sun::star::ucb::ListenerAlreadySetException();
167 : :
168 [ + - ]: 65 : init( sal_True );
169 [ + - ]: 65 : return m_xResultSet1;
170 : : }
171 : :
172 : : //=========================================================================
173 : : // virtual
174 : 0 : void SAL_CALL ResultSetImplHelper::setListener(
175 : : const uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >&
176 : : Listener )
177 : : throw( com::sun::star::ucb::ListenerAlreadySetException,
178 : : uno::RuntimeException )
179 : : {
180 [ # # ]: 0 : osl::ClearableMutexGuard aGuard( m_aMutex );
181 : :
182 [ # # ][ # # ]: 0 : if ( m_bStatic || m_xListener.is() )
[ # # ]
183 [ # # ]: 0 : throw com::sun::star::ucb::ListenerAlreadySetException();
184 : :
185 [ # # ]: 0 : m_xListener = Listener;
186 : :
187 : : //////////////////////////////////////////////////////////////////////
188 : : // Create "welcome event" and send it to listener.
189 : : //////////////////////////////////////////////////////////////////////
190 : :
191 : : // Note: We only have the implementation for a static result set at the
192 : : // moment (src590). The dynamic result sets passed to the listener
193 : : // are a fake. This implementation will never call "notify" at the
194 : : // listener to propagate any changes!!!
195 : :
196 [ # # ]: 0 : init( sal_False );
197 : :
198 : 0 : uno::Any aInfo;
199 : : aInfo <<= com::sun::star::ucb::WelcomeDynamicResultSetStruct(
200 : : m_xResultSet1 /* "old" */,
201 [ # # ][ # # ]: 0 : m_xResultSet2 /* "new" */ );
[ # # ]
202 : :
203 [ # # ]: 0 : uno::Sequence< com::sun::star::ucb::ListAction > aActions( 1 );
204 : : aActions.getArray()[ 0 ]
205 : : = com::sun::star::ucb::ListAction(
206 : : 0, // Position; not used
207 : : 0, // Count; not used
208 : : com::sun::star::ucb::ListActionType::WELCOME,
209 [ # # ]: 0 : aInfo );
210 [ # # ]: 0 : aGuard.clear();
211 : :
212 [ # # ]: 0 : Listener->notify(
213 : : com::sun::star::ucb::ListEvent(
214 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ), aActions ) );
[ # # ][ # # ]
[ # # ][ # # ]
215 : 0 : }
216 : :
217 : : //=========================================================================
218 : : // virtual
219 : 0 : sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities()
220 : : throw( uno::RuntimeException )
221 : : {
222 : : // ! com::sun::star::ucb::ContentResultSetCapability::SORTED
223 : 0 : return 0;
224 : : }
225 : :
226 : : //=========================================================================
227 : : // virtual
228 : 0 : void SAL_CALL ResultSetImplHelper::connectToCache(
229 : : const uno::Reference< com::sun::star::ucb::XDynamicResultSet > &
230 : : xCache )
231 : : throw( com::sun::star::ucb::ListenerAlreadySetException,
232 : : com::sun::star::ucb::AlreadyInitializedException,
233 : : com::sun::star::ucb::ServiceNotFoundException,
234 : : uno::RuntimeException )
235 : : {
236 [ # # ]: 0 : if ( m_xListener.is() )
237 [ # # ]: 0 : throw com::sun::star::ucb::ListenerAlreadySetException();
238 : :
239 [ # # ]: 0 : if ( m_bStatic )
240 [ # # ]: 0 : throw com::sun::star::ucb::ListenerAlreadySetException();
241 : :
242 : : uno::Reference< com::sun::star::ucb::XSourceInitialization >
243 [ # # ]: 0 : xTarget( xCache, uno::UNO_QUERY );
244 [ # # ]: 0 : if ( xTarget.is() )
245 : : {
246 : : uno::Reference<
247 : : com::sun::star::ucb::XCachedDynamicResultSetStubFactory >
248 : 0 : xStubFactory;
249 : : try
250 : : {
251 : : xStubFactory
252 : : = uno::Reference<
253 : : com::sun::star::ucb::XCachedDynamicResultSetStubFactory >(
254 [ # # ]: 0 : m_xSMgr->createInstance(
255 : : rtl::OUString(
256 : 0 : "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ),
257 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ][ # # ]
258 : : }
259 [ # # ]: 0 : catch ( uno::Exception const & )
260 : : {
261 : : }
262 : :
263 [ # # ]: 0 : if ( xStubFactory.is() )
264 : : {
265 [ # # ]: 0 : xStubFactory->connectToCache(
266 [ # # ][ # # ]: 0 : this, xCache, m_aCommand.SortingInfo, 0 );
[ # # ]
267 : 0 : return;
268 [ # # ]: 0 : }
269 : : }
270 [ # # ]: 0 : throw com::sun::star::ucb::ServiceNotFoundException();
271 : : }
272 : :
273 : : //=========================================================================
274 : : //
275 : : // Non-interface methods.
276 : : //
277 : : //=========================================================================
278 : :
279 : 65 : void ResultSetImplHelper::init( sal_Bool bStatic )
280 : : {
281 [ + - ]: 65 : osl::MutexGuard aGuard( m_aMutex );
282 : :
283 [ + - ]: 65 : if ( !m_bInitDone )
284 : : {
285 [ + - ]: 65 : if ( bStatic )
286 : : {
287 : : // virtual... derived class fills m_xResultSet1
288 [ + - ]: 65 : initStatic();
289 : :
290 : : OSL_ENSURE( m_xResultSet1.is(),
291 : : "ResultSetImplHelper::init - No 1st result set!" );
292 : 65 : m_bStatic = sal_True;
293 : : }
294 : : else
295 : : {
296 : : // virtual... derived class fills m_xResultSet1 and m_xResultSet2
297 [ # # ]: 0 : initDynamic();
298 : :
299 : : OSL_ENSURE( m_xResultSet1.is(),
300 : : "ResultSetImplHelper::init - No 1st result set!" );
301 : : OSL_ENSURE( m_xResultSet2.is(),
302 : : "ResultSetImplHelper::init - No 2nd result set!" );
303 : 0 : m_bStatic = sal_False;
304 : : }
305 : 65 : m_bInitDone = sal_True;
306 [ + - ]: 65 : }
307 : 65 : }
308 : :
309 : : } // namespace ucbhelper
310 : :
311 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|