nss: upgrade to release 3.73
[LibreOffice.git] / ucbhelper / source / provider / resultsethelper.cxx
blob5ff9e6c2748307ceea5012dce3bb9411c55ea0b5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /**************************************************************************
22 TODO
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/ListenerAlreadySetException.hpp>
31 #include <com/sun/star/ucb/ServiceNotFoundException.hpp>
32 #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
33 #include <com/sun/star/ucb/CachedDynamicResultSetStubFactory.hpp>
34 #include <com/sun/star/ucb/XSourceInitialization.hpp>
35 #include <cppuhelper/interfacecontainer.h>
36 #include <cppuhelper/queryinterface.hxx>
37 #include <ucbhelper/resultsethelper.hxx>
38 #include <ucbhelper/macros.hxx>
40 #include <osl/diagnose.h>
42 using namespace com::sun::star;
45 // ResultSetImplHelper Implementation.
48 namespace ucbhelper {
51 ResultSetImplHelper::ResultSetImplHelper(
52 const uno::Reference< uno::XComponentContext >& rxContext,
53 const css::ucb::OpenCommandArgument2& rCommand )
54 : m_bStatic( false ),
55 m_bInitDone( false ),
56 m_aCommand( rCommand ),
57 m_xContext( rxContext )
62 // virtual
63 ResultSetImplHelper::~ResultSetImplHelper()
68 // XServiceInfo methods.
70 OUString SAL_CALL ResultSetImplHelper::getImplementationName()
72 return "ResultSetImplHelper";
75 sal_Bool SAL_CALL ResultSetImplHelper::supportsService( const OUString& ServiceName )
77 return cppu::supportsService( this, ServiceName );
80 css::uno::Sequence< OUString > SAL_CALL ResultSetImplHelper::getSupportedServiceNames()
82 return { DYNAMICRESULTSET_SERVICE_NAME };
85 // XComponent methods.
88 // virtual
89 void SAL_CALL ResultSetImplHelper::dispose()
91 osl::MutexGuard aGuard( m_aMutex );
93 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
95 lang::EventObject aEvt;
96 aEvt.Source = static_cast< lang::XComponent * >( this );
97 m_pDisposeEventListeners->disposeAndClear( aEvt );
102 // virtual
103 void SAL_CALL ResultSetImplHelper::addEventListener(
104 const uno::Reference< lang::XEventListener >& Listener )
106 osl::MutexGuard aGuard( m_aMutex );
108 if ( !m_pDisposeEventListeners )
109 m_pDisposeEventListeners.reset(new cppu::OInterfaceContainerHelper( m_aMutex ));
111 m_pDisposeEventListeners->addInterface( Listener );
115 // virtual
116 void SAL_CALL ResultSetImplHelper::removeEventListener(
117 const uno::Reference< lang::XEventListener >& Listener )
119 osl::MutexGuard aGuard( m_aMutex );
121 if ( m_pDisposeEventListeners )
122 m_pDisposeEventListeners->removeInterface( Listener );
126 // XDynamicResultSet methods.
129 // virtual
130 uno::Reference< sdbc::XResultSet > SAL_CALL
131 ResultSetImplHelper::getStaticResultSet()
133 osl::MutexGuard aGuard( m_aMutex );
135 if ( m_xListener.is() )
136 throw css::ucb::ListenerAlreadySetException();
138 init( true );
139 return m_xResultSet1;
143 // virtual
144 void SAL_CALL ResultSetImplHelper::setListener(
145 const uno::Reference< css::ucb::XDynamicResultSetListener >& Listener )
147 osl::ClearableMutexGuard aGuard( m_aMutex );
149 if ( m_bStatic || m_xListener.is() )
150 throw css::ucb::ListenerAlreadySetException();
152 m_xListener = Listener;
155 // Create "welcome event" and send it to listener.
158 // Note: We only have the implementation for a static result set at the
159 // moment (src590). The dynamic result sets passed to the listener
160 // are a fake. This implementation will never call "notify" at the
161 // listener to propagate any changes!!!
163 init( false );
165 uno::Any aInfo;
166 aInfo <<= css::ucb::WelcomeDynamicResultSetStruct(
167 m_xResultSet1 /* "old" */,
168 m_xResultSet2 /* "new" */ );
170 uno::Sequence< css::ucb::ListAction > aActions {
171 css::ucb::ListAction(
172 0, // Position; not used
173 0, // Count; not used
174 css::ucb::ListActionType::WELCOME,
175 aInfo ) };
176 aGuard.clear();
178 Listener->notify(
179 css::ucb::ListEvent(
180 static_cast< cppu::OWeakObject * >( this ), aActions ) );
184 // virtual
185 sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities()
187 // ! css::ucb::ContentResultSetCapability::SORTED
188 return 0;
192 // virtual
193 void SAL_CALL ResultSetImplHelper::connectToCache(
194 const uno::Reference< css::ucb::XDynamicResultSet > & xCache )
196 if ( m_xListener.is() )
197 throw css::ucb::ListenerAlreadySetException();
199 if ( m_bStatic )
200 throw css::ucb::ListenerAlreadySetException();
202 uno::Reference< css::ucb::XSourceInitialization > xTarget( xCache, uno::UNO_QUERY );
203 if ( xTarget.is() )
205 uno::Reference< css::ucb::XCachedDynamicResultSetStubFactory > xStubFactory;
208 xStubFactory
209 = css::ucb::CachedDynamicResultSetStubFactory::create(
210 m_xContext );
212 catch ( uno::Exception const & )
216 if ( xStubFactory.is() )
218 xStubFactory->connectToCache(
219 this, xCache, m_aCommand.SortingInfo, nullptr );
220 return;
223 throw css::ucb::ServiceNotFoundException();
227 // Non-interface methods.
230 void ResultSetImplHelper::init( bool bStatic )
232 osl::MutexGuard aGuard( m_aMutex );
234 if ( m_bInitDone )
235 return;
237 if ( bStatic )
239 // virtual... derived class fills m_xResultSet1
240 initStatic();
242 OSL_ENSURE( m_xResultSet1.is(),
243 "ResultSetImplHelper::init - No 1st result set!" );
244 m_bStatic = true;
246 else
248 // virtual... derived class fills m_xResultSet1 and m_xResultSet2
249 initDynamic();
251 OSL_ENSURE( m_xResultSet1.is(),
252 "ResultSetImplHelper::init - No 1st result set!" );
253 OSL_ENSURE( m_xResultSet2.is(),
254 "ResultSetImplHelper::init - No 2nd result set!" );
255 m_bStatic = false;
257 m_bInitDone = true;
260 } // namespace ucbhelper
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */