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