1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resultsethelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
34 /**************************************************************************
36 **************************************************************************
38 - This implementation is far away from completion. It has no interface
39 for changes notifications etc.
41 *************************************************************************/
42 #include <com/sun/star/ucb/ListActionType.hpp>
43 #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
44 #include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp>
45 #include <com/sun/star/ucb/XSourceInitialization.hpp>
46 #include <cppuhelper/interfacecontainer.hxx>
47 #include <ucbhelper/resultsethelper.hxx>
49 #include "osl/diagnose.h"
51 using namespace com::sun::star
;
53 //=========================================================================
54 //=========================================================================
56 // ResultSetImplHelper Implementation.
58 //=========================================================================
59 //=========================================================================
63 //=========================================================================
64 ResultSetImplHelper::ResultSetImplHelper(
65 const uno::Reference
< lang::XMultiServiceFactory
>& rxSMgr
)
66 : m_pDisposeEventListeners( 0 ),
67 m_bStatic( sal_False
),
68 m_bInitDone( sal_False
),
73 //=========================================================================
74 ResultSetImplHelper::ResultSetImplHelper(
75 const uno::Reference
< lang::XMultiServiceFactory
>& rxSMgr
,
76 const com::sun::star::ucb::OpenCommandArgument2
& rCommand
)
77 : m_pDisposeEventListeners( 0 ),
78 m_bStatic( sal_False
),
79 m_bInitDone( sal_False
),
80 m_aCommand( rCommand
),
85 //=========================================================================
87 ResultSetImplHelper::~ResultSetImplHelper()
89 delete m_pDisposeEventListeners
;
92 //=========================================================================
94 // XInterface methods.
96 //=========================================================================
98 XINTERFACE_IMPL_4( ResultSetImplHelper
,
101 lang::XComponent
, /* base of XDynamicResultSet */
102 com::sun::star::ucb::XDynamicResultSet
);
104 //=========================================================================
106 // XTypeProvider methods.
108 //=========================================================================
110 XTYPEPROVIDER_IMPL_3( ResultSetImplHelper
,
113 com::sun::star::ucb::XDynamicResultSet
);
115 //=========================================================================
117 // XServiceInfo methods.
119 //=========================================================================
121 XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper
,
122 rtl::OUString::createFromAscii(
123 "ResultSetImplHelper" ),
124 rtl::OUString::createFromAscii(
125 DYNAMICRESULTSET_SERVICE_NAME
) );
127 //=========================================================================
129 // XComponent methods.
131 //=========================================================================
134 void SAL_CALL
ResultSetImplHelper::dispose()
135 throw( uno::RuntimeException
)
137 osl::MutexGuard
aGuard( m_aMutex
);
139 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
141 lang::EventObject aEvt
;
142 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
143 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
147 //=========================================================================
149 void SAL_CALL
ResultSetImplHelper::addEventListener(
150 const uno::Reference
< lang::XEventListener
>& Listener
)
151 throw( uno::RuntimeException
)
153 osl::MutexGuard
aGuard( m_aMutex
);
155 if ( !m_pDisposeEventListeners
)
156 m_pDisposeEventListeners
157 = new cppu::OInterfaceContainerHelper( m_aMutex
);
159 m_pDisposeEventListeners
->addInterface( Listener
);
162 //=========================================================================
164 void SAL_CALL
ResultSetImplHelper::removeEventListener(
165 const uno::Reference
< lang::XEventListener
>& Listener
)
166 throw( uno::RuntimeException
)
168 osl::MutexGuard
aGuard( m_aMutex
);
170 if ( m_pDisposeEventListeners
)
171 m_pDisposeEventListeners
->removeInterface( Listener
);
174 //=========================================================================
176 // XDynamicResultSet methods.
178 //=========================================================================
181 uno::Reference
< sdbc::XResultSet
> SAL_CALL
182 ResultSetImplHelper::getStaticResultSet()
183 throw( com::sun::star::ucb::ListenerAlreadySetException
,
184 uno::RuntimeException
)
186 osl::MutexGuard
aGuard( m_aMutex
);
188 if ( m_xListener
.is() )
189 throw com::sun::star::ucb::ListenerAlreadySetException();
192 return m_xResultSet1
;
195 //=========================================================================
197 void SAL_CALL
ResultSetImplHelper::setListener(
198 const uno::Reference
< com::sun::star::ucb::XDynamicResultSetListener
>&
200 throw( com::sun::star::ucb::ListenerAlreadySetException
,
201 uno::RuntimeException
)
203 osl::ClearableMutexGuard
aGuard( m_aMutex
);
205 if ( m_bStatic
|| m_xListener
.is() )
206 throw com::sun::star::ucb::ListenerAlreadySetException();
208 m_xListener
= Listener
;
210 //////////////////////////////////////////////////////////////////////
211 // Create "welcome event" and send it to listener.
212 //////////////////////////////////////////////////////////////////////
214 // Note: We only have the implementation for a static result set at the
215 // moment (src590). The dynamic result sets passed to the listener
216 // are a fake. This implementation will never call "notify" at the
217 // listener to propagate any changes!!!
222 aInfo
<<= com::sun::star::ucb::WelcomeDynamicResultSetStruct(
223 m_xResultSet1
/* "old" */,
224 m_xResultSet2
/* "new" */ );
226 uno::Sequence
< com::sun::star::ucb::ListAction
> aActions( 1 );
227 aActions
.getArray()[ 0 ]
228 = com::sun::star::ucb::ListAction(
229 0, // Position; not used
230 0, // Count; not used
231 com::sun::star::ucb::ListActionType::WELCOME
,
236 com::sun::star::ucb::ListEvent(
237 static_cast< cppu::OWeakObject
* >( this ), aActions
) );
240 //=========================================================================
242 sal_Int16 SAL_CALL
ResultSetImplHelper::getCapabilities()
243 throw( uno::RuntimeException
)
245 // ! com::sun::star::ucb::ContentResultSetCapability::SORTED
249 //=========================================================================
251 void SAL_CALL
ResultSetImplHelper::connectToCache(
252 const uno::Reference
< com::sun::star::ucb::XDynamicResultSet
> &
254 throw( com::sun::star::ucb::ListenerAlreadySetException
,
255 com::sun::star::ucb::AlreadyInitializedException
,
256 com::sun::star::ucb::ServiceNotFoundException
,
257 uno::RuntimeException
)
259 if ( m_xListener
.is() )
260 throw com::sun::star::ucb::ListenerAlreadySetException();
263 throw com::sun::star::ucb::ListenerAlreadySetException();
265 uno::Reference
< com::sun::star::ucb::XSourceInitialization
>
266 xTarget( xCache
, uno::UNO_QUERY
);
270 com::sun::star::ucb::XCachedDynamicResultSetStubFactory
>
276 com::sun::star::ucb::XCachedDynamicResultSetStubFactory
>(
277 m_xSMgr
->createInstance(
278 rtl::OUString::createFromAscii(
279 "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ),
282 catch ( uno::Exception
const & )
286 if ( xStubFactory
.is() )
288 xStubFactory
->connectToCache(
289 this, xCache
, m_aCommand
.SortingInfo
, 0 );
293 throw com::sun::star::ucb::ServiceNotFoundException();
296 //=========================================================================
298 // Non-interface methods.
300 //=========================================================================
302 void ResultSetImplHelper::init( sal_Bool bStatic
)
304 osl::MutexGuard
aGuard( m_aMutex
);
310 // virtual... derived class fills m_xResultSet1
313 OSL_ENSURE( m_xResultSet1
.is(),
314 "ResultSetImplHelper::init - No 1st result set!" );
315 m_bStatic
= sal_True
;
319 // virtual... derived class fills m_xResultSet1 and m_xResultSet2
322 OSL_ENSURE( m_xResultSet1
.is(),
323 "ResultSetImplHelper::init - No 1st result set!" );
324 OSL_ENSURE( m_xResultSet2
.is(),
325 "ResultSetImplHelper::init - No 2nd result set!" );
326 m_bStatic
= sal_False
;
328 m_bInitDone
= sal_True
;
332 } // namespace ucbhelper