1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
23 **************************************************************************
25 - This implementation is far away from completion. It has no interface
26 for changes notifications etc.
28 *************************************************************************/
29 #include <com/sun/star/ucb/ListActionType.hpp>
30 #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
31 #include <com/sun/star/ucb/CachedDynamicResultSetStubFactory.hpp>
32 #include <com/sun/star/ucb/XSourceInitialization.hpp>
33 #include <cppuhelper/interfacecontainer.hxx>
34 #include <ucbhelper/resultsethelper.hxx>
35 #include <ucbhelper/getcomponentcontext.hxx>
37 #include "osl/diagnose.h"
39 using namespace com::sun::star
;
44 // ResultSetImplHelper Implementation.
52 ResultSetImplHelper::ResultSetImplHelper(
53 const uno::Reference
< uno::XComponentContext
>& rxContext
,
54 const com::sun::star::ucb::OpenCommandArgument2
& rCommand
)
55 : m_pDisposeEventListeners( 0 ),
58 m_aCommand( rCommand
),
59 m_xContext( rxContext
)
65 ResultSetImplHelper::~ResultSetImplHelper()
67 delete m_pDisposeEventListeners
;
72 // XInterface methods.
73 void SAL_CALL
ResultSetImplHelper::acquire()
76 OWeakObject::acquire();
79 void SAL_CALL
ResultSetImplHelper::release()
82 OWeakObject::release();
85 css::uno::Any SAL_CALL
ResultSetImplHelper::queryInterface( const css::uno::Type
& rType
)
86 throw( css::uno::RuntimeException
, std::exception
)
88 css::uno::Any aRet
= cppu::queryInterface( rType
,
89 (static_cast< lang::XTypeProvider
* >(this)),
90 (static_cast< lang::XServiceInfo
* >(this)),
91 (static_cast< lang::XComponent
* >(this)),
92 (static_cast< css::ucb::XDynamicResultSet
* >(this))
94 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
97 // XTypeProvider methods.
101 XTYPEPROVIDER_IMPL_3( ResultSetImplHelper
,
104 com::sun::star::ucb::XDynamicResultSet
);
108 // XServiceInfo methods.
112 XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper
,
114 "ResultSetImplHelper" ),
115 DYNAMICRESULTSET_SERVICE_NAME
);
119 // XComponent methods.
124 void SAL_CALL
ResultSetImplHelper::dispose()
125 throw( uno::RuntimeException
, std::exception
)
127 osl::MutexGuard
aGuard( m_aMutex
);
129 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
131 lang::EventObject aEvt
;
132 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
133 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
139 void SAL_CALL
ResultSetImplHelper::addEventListener(
140 const uno::Reference
< lang::XEventListener
>& Listener
)
141 throw( uno::RuntimeException
, std::exception
)
143 osl::MutexGuard
aGuard( m_aMutex
);
145 if ( !m_pDisposeEventListeners
)
146 m_pDisposeEventListeners
147 = new cppu::OInterfaceContainerHelper( m_aMutex
);
149 m_pDisposeEventListeners
->addInterface( Listener
);
154 void SAL_CALL
ResultSetImplHelper::removeEventListener(
155 const uno::Reference
< lang::XEventListener
>& Listener
)
156 throw( uno::RuntimeException
, std::exception
)
158 osl::MutexGuard
aGuard( m_aMutex
);
160 if ( m_pDisposeEventListeners
)
161 m_pDisposeEventListeners
->removeInterface( Listener
);
166 // XDynamicResultSet methods.
171 uno::Reference
< sdbc::XResultSet
> SAL_CALL
172 ResultSetImplHelper::getStaticResultSet()
173 throw( com::sun::star::ucb::ListenerAlreadySetException
,
174 uno::RuntimeException
, std::exception
)
176 osl::MutexGuard
aGuard( m_aMutex
);
178 if ( m_xListener
.is() )
179 throw com::sun::star::ucb::ListenerAlreadySetException();
182 return m_xResultSet1
;
187 void SAL_CALL
ResultSetImplHelper::setListener(
188 const uno::Reference
< com::sun::star::ucb::XDynamicResultSetListener
>&
190 throw( com::sun::star::ucb::ListenerAlreadySetException
,
191 uno::RuntimeException
, std::exception
)
193 osl::ClearableMutexGuard
aGuard( m_aMutex
);
195 if ( m_bStatic
|| m_xListener
.is() )
196 throw com::sun::star::ucb::ListenerAlreadySetException();
198 m_xListener
= Listener
;
201 // Create "welcome event" and send it to listener.
204 // Note: We only have the implementation for a static result set at the
205 // moment (src590). The dynamic result sets passed to the listener
206 // are a fake. This implementation will never call "notify" at the
207 // listener to propagate any changes!!!
212 aInfo
<<= com::sun::star::ucb::WelcomeDynamicResultSetStruct(
213 m_xResultSet1
/* "old" */,
214 m_xResultSet2
/* "new" */ );
216 uno::Sequence
< com::sun::star::ucb::ListAction
> aActions( 1 );
217 aActions
.getArray()[ 0 ]
218 = com::sun::star::ucb::ListAction(
219 0, // Position; not used
220 0, // Count; not used
221 com::sun::star::ucb::ListActionType::WELCOME
,
226 com::sun::star::ucb::ListEvent(
227 static_cast< cppu::OWeakObject
* >( this ), aActions
) );
232 sal_Int16 SAL_CALL
ResultSetImplHelper::getCapabilities()
233 throw( uno::RuntimeException
, std::exception
)
235 // ! com::sun::star::ucb::ContentResultSetCapability::SORTED
241 void SAL_CALL
ResultSetImplHelper::connectToCache(
242 const uno::Reference
< com::sun::star::ucb::XDynamicResultSet
> &
244 throw( com::sun::star::ucb::ListenerAlreadySetException
,
245 com::sun::star::ucb::AlreadyInitializedException
,
246 com::sun::star::ucb::ServiceNotFoundException
,
247 uno::RuntimeException
, std::exception
)
249 if ( m_xListener
.is() )
250 throw com::sun::star::ucb::ListenerAlreadySetException();
253 throw com::sun::star::ucb::ListenerAlreadySetException();
255 uno::Reference
< com::sun::star::ucb::XSourceInitialization
>
256 xTarget( xCache
, uno::UNO_QUERY
);
260 com::sun::star::ucb::XCachedDynamicResultSetStubFactory
>
265 = com::sun::star::ucb::CachedDynamicResultSetStubFactory::create(
268 catch ( uno::Exception
const & )
272 if ( xStubFactory
.is() )
274 xStubFactory
->connectToCache(
275 this, xCache
, m_aCommand
.SortingInfo
, 0 );
279 throw com::sun::star::ucb::ServiceNotFoundException();
284 // Non-interface methods.
288 void ResultSetImplHelper::init( bool bStatic
)
290 osl::MutexGuard
aGuard( m_aMutex
);
296 // virtual... derived class fills m_xResultSet1
299 OSL_ENSURE( m_xResultSet1
.is(),
300 "ResultSetImplHelper::init - No 1st result set!" );
305 // virtual... derived class fills m_xResultSet1 and m_xResultSet2
308 OSL_ENSURE( m_xResultSet1
.is(),
309 "ResultSetImplHelper::init - No 1st result set!" );
310 OSL_ENSURE( m_xResultSet2
.is(),
311 "ResultSetImplHelper::init - No 2nd result set!" );
318 } // namespace ucbhelper
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */