LibreOffice Module ucbhelper (master)  1
resultsethelper.cxx
Go to the documentation of this file.
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/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>
38 #include <ucbhelper/macros.hxx>
39 
40 #include <osl/diagnose.h>
41 
42 using namespace com::sun::star;
43 
44 
45 // ResultSetImplHelper Implementation.
46 
47 
48 namespace ucbhelper {
49 
50 
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 )
58 {
59 }
60 
61 
62 // virtual
64 {
65 }
66 
67 
68 // XServiceInfo methods.
69 
71 {
72  return "ResultSetImplHelper";
73 }
74 
75 sal_Bool SAL_CALL ResultSetImplHelper::supportsService( const OUString& ServiceName )
76 {
77  return cppu::supportsService( this, ServiceName );
78 }
79 
80 css::uno::Sequence< OUString > SAL_CALL ResultSetImplHelper::getSupportedServiceNames()
81 {
83 }
84 
85 // XComponent methods.
86 
87 
88 // virtual
90 {
91  osl::MutexGuard aGuard( m_aMutex );
92 
94  {
95  lang::EventObject aEvt;
96  aEvt.Source = static_cast< lang::XComponent * >( this );
97  m_pDisposeEventListeners->disposeAndClear( aEvt );
98  }
99 }
100 
101 
102 // virtual
104  const uno::Reference< lang::XEventListener >& Listener )
105 {
106  osl::MutexGuard aGuard( m_aMutex );
107 
110 
111  m_pDisposeEventListeners->addInterface( Listener );
112 }
113 
114 
115 // virtual
117  const uno::Reference< lang::XEventListener >& Listener )
118 {
119  osl::MutexGuard aGuard( m_aMutex );
120 
122  m_pDisposeEventListeners->removeInterface( Listener );
123 }
124 
125 
126 // XDynamicResultSet methods.
127 
128 
129 // virtual
130 uno::Reference< sdbc::XResultSet > SAL_CALL
132 {
133  osl::MutexGuard aGuard( m_aMutex );
134 
135  if ( m_xListener.is() )
136  throw css::ucb::ListenerAlreadySetException();
137 
138  init( true );
139  return m_xResultSet1;
140 }
141 
142 
143 // virtual
145  const uno::Reference< css::ucb::XDynamicResultSetListener >& Listener )
146 {
147  osl::ClearableMutexGuard aGuard( m_aMutex );
148 
149  if ( m_bStatic || m_xListener.is() )
150  throw css::ucb::ListenerAlreadySetException();
151 
152  m_xListener = Listener;
153 
154 
155  // Create "welcome event" and send it to listener.
156 
157 
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!!!
162 
163  init( false );
164 
165  uno::Any aInfo;
166  aInfo <<= css::ucb::WelcomeDynamicResultSetStruct(
167  m_xResultSet1 /* "old" */,
168  m_xResultSet2 /* "new" */ );
169 
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();
177 
178  Listener->notify(
179  css::ucb::ListEvent(
180  static_cast< cppu::OWeakObject * >( this ), aActions ) );
181 }
182 
183 
184 // virtual
186 {
187  // ! css::ucb::ContentResultSetCapability::SORTED
188  return 0;
189 }
190 
191 
192 // virtual
194  const uno::Reference< css::ucb::XDynamicResultSet > & xCache )
195 {
196  if ( m_xListener.is() )
197  throw css::ucb::ListenerAlreadySetException();
198 
199  if ( m_bStatic )
200  throw css::ucb::ListenerAlreadySetException();
201 
202  uno::Reference< css::ucb::XSourceInitialization > xTarget( xCache, uno::UNO_QUERY );
203  if ( xTarget.is() )
204  {
205  uno::Reference< css::ucb::XCachedDynamicResultSetStubFactory > xStubFactory;
206  try
207  {
208  xStubFactory
209  = css::ucb::CachedDynamicResultSetStubFactory::create(
210  m_xContext );
211  }
212  catch ( uno::Exception const & )
213  {
214  }
215 
216  if ( xStubFactory.is() )
217  {
218  xStubFactory->connectToCache(
219  this, xCache, m_aCommand.SortingInfo, nullptr );
220  return;
221  }
222  }
223  throw css::ucb::ServiceNotFoundException();
224 }
225 
226 
227 // Non-interface methods.
228 
229 
230 void ResultSetImplHelper::init( bool bStatic )
231 {
232  osl::MutexGuard aGuard( m_aMutex );
233 
234  if ( m_bInitDone )
235  return;
236 
237  if ( bStatic )
238  {
239  // virtual... derived class fills m_xResultSet1
240  initStatic();
241 
242  OSL_ENSURE( m_xResultSet1.is(),
243  "ResultSetImplHelper::init - No 1st result set!" );
244  m_bStatic = true;
245  }
246  else
247  {
248  // virtual... derived class fills m_xResultSet1 and m_xResultSet2
249  initDynamic();
250 
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;
256  }
257  m_bInitDone = true;
258 }
259 
260 } // namespace ucbhelper
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int16 SAL_CALL getCapabilities() override
The implementation of this method always returns 0.
virtual OUString SAL_CALL getImplementationName() override
css::ucb::OpenCommandArgument2 m_aCommand
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet2
virtual UCBHELPER_DLLPRIVATE void initDynamic()=0
Your implementation of this method has to fill the protected members m_xResultSet1 and m_xResultSet2 ...
Reference< XInterface > xTarget
css::uno::Reference< css::ucb::XDynamicResultSetListener > m_xListener
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::unique_ptr< cppu::OInterfaceContainerHelper > m_pDisposeEventListeners
virtual ~ResultSetImplHelper() override
Destructor.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL setListener(const css::uno::Reference< css::ucb::XDynamicResultSetListener > &Listener) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
#define DYNAMICRESULTSET_SERVICE_NAME
virtual UCBHELPER_DLLPRIVATE void initStatic()=0
Your implementation of this method has to fill the protected member m_xResultSet1.
css::uno::Reference< css::uno::XComponentContext > m_xContext
UCBHELPER_DLLPRIVATE void init(bool bStatic)
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getStaticResultSet() override
unsigned char sal_Bool
virtual void SAL_CALL dispose() override
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet1
Reference< XComponentContext > m_xContext
virtual void SAL_CALL connectToCache(const css::uno::Reference< css::ucb::XDynamicResultSet > &xCache) override