fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / resultsetbase.cxx
blob75ae7b4a83709f9af9fd01aab915e21d5667df1a
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 .
20 #include <comphelper/processfactory.hxx>
21 #include <ucbhelper/contentidentifier.hxx>
22 #include <com/sun/star/ucb/OpenMode.hpp>
23 #include <com/sun/star/uno/Reference.h>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/ucb/ListActionType.hpp>
26 #include <com/sun/star/ucb/XSourceInitialization.hpp>
27 #include <ucbhelper/resultsetmetadata.hxx>
29 #include "resultsetbase.hxx"
31 using namespace chelp;
32 using namespace com::sun::star;
34 ResultSetBase::ResultSetBase( const uno::Reference< uno::XComponentContext >& rxContext,
35 const uno::Reference< ucb::XContentProvider >& xProvider,
36 sal_Int32 nOpenMode,
37 const uno::Sequence< beans::Property >& seq,
38 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort )
39 : m_xContext( rxContext ),
40 m_xProvider( xProvider ),
41 m_nRow( -1 ),
42 m_nWasNull( true ),
43 m_nOpenMode( nOpenMode ),
44 m_bRowCountFinal( true ),
45 m_sProperty( seq ),
46 m_sSortingInfo( seqSort ),
47 m_pDisposeEventListeners( 0 ),
48 m_pRowCountListeners( 0 ),
49 m_pIsFinalListeners( 0 )
53 ResultSetBase::~ResultSetBase()
55 delete m_pIsFinalListeners;
56 delete m_pRowCountListeners;
57 delete m_pDisposeEventListeners;
61 // XInterface
63 void SAL_CALL
64 ResultSetBase::acquire(
65 void )
66 throw()
68 OWeakObject::acquire();
72 void SAL_CALL
73 ResultSetBase::release(
74 void )
75 throw()
77 OWeakObject::release();
82 uno::Any SAL_CALL
83 ResultSetBase::queryInterface(
84 const uno::Type& rType )
85 throw( uno::RuntimeException )
87 uno::Any aRet = cppu::queryInterface( rType,
88 (static_cast< lang::XComponent* >(this)),
89 (static_cast< sdbc::XRow* >(this)),
90 (static_cast< sdbc::XResultSet* >(this)),
91 (static_cast< sdbc::XResultSetMetaDataSupplier* >(this)),
92 (static_cast< beans::XPropertySet* >(this)),
93 (static_cast< ucb::XContentAccess* >(this)) );
94 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
99 // XComponent
102 void SAL_CALL
103 ResultSetBase::addEventListener(
104 const uno::Reference< lang::XEventListener >& Listener )
105 throw( uno::RuntimeException )
107 osl::MutexGuard aGuard( m_aMutex );
109 if ( ! m_pDisposeEventListeners )
110 m_pDisposeEventListeners =
111 new cppu::OInterfaceContainerHelper( m_aMutex );
113 m_pDisposeEventListeners->addInterface( Listener );
117 void SAL_CALL
118 ResultSetBase::removeEventListener(
119 const uno::Reference< lang::XEventListener >& Listener )
120 throw( uno::RuntimeException )
122 osl::MutexGuard aGuard( m_aMutex );
124 if ( m_pDisposeEventListeners )
125 m_pDisposeEventListeners->removeInterface( Listener );
130 void SAL_CALL
131 ResultSetBase::dispose()
132 throw( uno::RuntimeException )
134 osl::MutexGuard aGuard( m_aMutex );
136 lang::EventObject aEvt;
137 aEvt.Source = static_cast< lang::XComponent * >( this );
139 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
141 m_pDisposeEventListeners->disposeAndClear( aEvt );
143 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
145 m_pRowCountListeners->disposeAndClear( aEvt );
147 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
149 m_pIsFinalListeners->disposeAndClear( aEvt );
155 // XResultSet
157 sal_Bool SAL_CALL
158 ResultSetBase::next(
159 void )
160 throw( sdbc::SQLException,
161 uno::RuntimeException )
163 sal_Bool test;
164 m_nRow++;
165 if( sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
166 test = true;
167 else
168 test = false;
169 return test;
173 sal_Bool SAL_CALL
174 ResultSetBase::isBeforeFirst(
175 void )
176 throw( sdbc::SQLException,
177 uno::RuntimeException )
179 return m_nRow == -1;
183 sal_Bool SAL_CALL
184 ResultSetBase::isAfterLast(
185 void )
186 throw( sdbc::SQLException,
187 uno::RuntimeException )
189 return sal::static_int_cast<sal_uInt32>( m_nRow ) >= m_aItems.size(); // Cannot happen, if m_aFolder.isOpen()
193 sal_Bool SAL_CALL
194 ResultSetBase::isFirst(
195 void )
196 throw( sdbc::SQLException,
197 uno::RuntimeException )
199 return m_nRow == 0;
203 sal_Bool SAL_CALL
204 ResultSetBase::isLast(
205 void )
206 throw( sdbc::SQLException,
207 uno::RuntimeException)
209 if( sal::static_int_cast<sal_uInt32>( m_nRow ) == m_aItems.size() - 1 )
210 return true;
211 else
212 return false;
216 void SAL_CALL
217 ResultSetBase::beforeFirst(
218 void )
219 throw( sdbc::SQLException,
220 uno::RuntimeException)
222 m_nRow = -1;
226 void SAL_CALL
227 ResultSetBase::afterLast(
228 void )
229 throw( sdbc::SQLException,
230 uno::RuntimeException )
232 m_nRow = m_aItems.size();
236 sal_Bool SAL_CALL
237 ResultSetBase::first(
238 void )
239 throw( sdbc::SQLException,
240 uno::RuntimeException)
242 m_nRow = -1;
243 return next();
247 sal_Bool SAL_CALL
248 ResultSetBase::last(
249 void )
250 throw( sdbc::SQLException,
251 uno::RuntimeException )
253 m_nRow = m_aItems.size() - 1;
254 return true;
258 sal_Int32 SAL_CALL
259 ResultSetBase::getRow(
260 void )
261 throw( sdbc::SQLException,
262 uno::RuntimeException)
264 // Test, whether behind last row
265 if( -1 == m_nRow || sal::static_int_cast<sal_uInt32>( m_nRow ) >= m_aItems.size() )
266 return 0;
267 else
268 return m_nRow+1;
272 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
273 throw( sdbc::SQLException, uno::RuntimeException)
275 if( row >= 0 )
276 m_nRow = row - 1;
277 else
279 last();
280 m_nRow += ( row + 1 );
281 if( m_nRow < -1 )
282 m_nRow = -1;
285 return 0<= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
291 sal_Bool SAL_CALL
292 ResultSetBase::relative(
293 sal_Int32 row )
294 throw( sdbc::SQLException,
295 uno::RuntimeException)
297 if( isAfterLast() || isBeforeFirst() )
298 throw sdbc::SQLException();
300 if( row > 0 )
301 while( row-- )
302 next();
303 else if( row < 0 )
304 while( row++ && m_nRow > -1 )
305 previous();
307 return 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
312 sal_Bool SAL_CALL
313 ResultSetBase::previous(
314 void )
315 throw( sdbc::SQLException,
316 uno::RuntimeException)
318 if( sal::static_int_cast<sal_uInt32>( m_nRow ) > m_aItems.size() )
319 m_nRow = m_aItems.size(); // Correct Handling of afterLast
320 if( 0 <= m_nRow ) -- m_nRow;
322 return 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
326 void SAL_CALL
327 ResultSetBase::refreshRow(
328 void )
329 throw( sdbc::SQLException,
330 uno::RuntimeException)
335 sal_Bool SAL_CALL
336 ResultSetBase::rowUpdated(
337 void )
338 throw( sdbc::SQLException,
339 uno::RuntimeException )
341 return false;
344 sal_Bool SAL_CALL
345 ResultSetBase::rowInserted(
346 void )
347 throw( sdbc::SQLException,
348 uno::RuntimeException )
350 return false;
353 sal_Bool SAL_CALL
354 ResultSetBase::rowDeleted(
355 void )
356 throw( sdbc::SQLException,
357 uno::RuntimeException )
359 return false;
363 uno::Reference< uno::XInterface > SAL_CALL
364 ResultSetBase::getStatement(
365 void )
366 throw( sdbc::SQLException,
367 uno::RuntimeException )
369 uno::Reference< uno::XInterface > test( 0 );
370 return test;
374 // XCloseable
376 void SAL_CALL
377 ResultSetBase::close(
378 void )
379 throw( sdbc::SQLException,
380 uno::RuntimeException)
385 OUString SAL_CALL
386 ResultSetBase::queryContentIdentifierString(
387 void )
388 throw( uno::RuntimeException )
390 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
391 return m_aPath[m_nRow];
392 else
393 return OUString();
397 uno::Reference< ucb::XContentIdentifier > SAL_CALL
398 ResultSetBase::queryContentIdentifier(
399 void )
400 throw( uno::RuntimeException )
402 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
404 OUString url = queryContentIdentifierString();
405 if( ! m_aIdents[m_nRow].is() && !url.isEmpty() )
406 m_aIdents[m_nRow] = uno::Reference< ucb::XContentIdentifier >(
407 new ::ucbhelper::ContentIdentifier( url ) );
408 return m_aIdents[m_nRow];
411 return uno::Reference< ucb::XContentIdentifier >();
415 uno::Reference< ucb::XContent > SAL_CALL
416 ResultSetBase::queryContent(
417 void )
418 throw( uno::RuntimeException )
420 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
421 return m_xProvider->queryContent( queryContentIdentifier() );
422 else
423 return uno::Reference< ucb::XContent >();
428 class XPropertySetInfoImpl
429 : public cppu::OWeakObject,
430 public beans::XPropertySetInfo
432 public:
434 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
435 : m_aSeq( aSeq )
439 void SAL_CALL acquire( void )
440 throw()
442 OWeakObject::acquire();
446 void SAL_CALL release( void )
447 throw()
449 OWeakObject::release();
452 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
453 throw( uno::RuntimeException )
455 uno::Any aRet = cppu::queryInterface( rType,
456 (static_cast< beans::XPropertySetInfo* >(this)) );
457 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
460 uno::Sequence< beans::Property > SAL_CALL getProperties()
461 throw( uno::RuntimeException )
463 return m_aSeq;
466 beans::Property SAL_CALL getPropertyByName( const OUString& aName )
467 throw( beans::UnknownPropertyException,
468 uno::RuntimeException)
470 for( int i = 0; i < m_aSeq.getLength(); ++i )
471 if( aName == m_aSeq[i].Name )
472 return m_aSeq[i];
473 throw beans::UnknownPropertyException();
476 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
477 throw( uno::RuntimeException )
479 for( int i = 0; i < m_aSeq.getLength(); ++i )
480 if( Name == m_aSeq[i].Name )
481 return true;
482 return false;
485 private:
487 uno::Sequence< beans::Property > m_aSeq;
492 // XPropertySet
493 uno::Reference< beans::XPropertySetInfo > SAL_CALL
494 ResultSetBase::getPropertySetInfo()
495 throw( uno::RuntimeException)
497 uno::Sequence< beans::Property > seq(2);
498 seq[0].Name = OUString( "RowCount" );
499 seq[0].Handle = -1;
500 seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) );
501 seq[0].Attributes = beans::PropertyAttribute::READONLY;
503 seq[1].Name = OUString( "IsRowCountFinal" );
504 seq[1].Handle = -1;
505 seq[1].Type = getCppuType( static_cast< sal_Bool* >(0) );
506 seq[1].Attributes = beans::PropertyAttribute::READONLY;
509 return uno::Reference< beans::XPropertySetInfo > ( new XPropertySetInfoImpl( seq ) );
514 void SAL_CALL ResultSetBase::setPropertyValue(
515 const OUString& aPropertyName, const uno::Any& aValue )
516 throw( beans::UnknownPropertyException,
517 beans::PropertyVetoException,
518 lang::IllegalArgumentException,
519 lang::WrappedTargetException,
520 uno::RuntimeException)
522 (void)aValue;
524 if( aPropertyName == OUString( "IsRowCountFinal" ) ||
525 aPropertyName == OUString( "RowCount" ) )
526 return;
528 throw beans::UnknownPropertyException();
532 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
533 const OUString& PropertyName )
534 throw( beans::UnknownPropertyException,
535 lang::WrappedTargetException,
536 uno::RuntimeException)
538 if( PropertyName == OUString( "IsRowCountFinal" ) )
540 uno::Any aAny;
541 aAny <<= m_bRowCountFinal;
542 return aAny;
544 else if ( PropertyName == OUString( "RowCount" ) )
546 uno::Any aAny;
547 sal_Int32 count = m_aItems.size();
548 aAny <<= count;
549 return aAny;
551 else
552 throw beans::UnknownPropertyException();
556 void SAL_CALL ResultSetBase::addPropertyChangeListener(
557 const OUString& aPropertyName,
558 const uno::Reference< beans::XPropertyChangeListener >& xListener )
559 throw( beans::UnknownPropertyException,
560 lang::WrappedTargetException,
561 uno::RuntimeException)
563 if( aPropertyName == OUString( "IsRowCountFinal" ) )
565 osl::MutexGuard aGuard( m_aMutex );
566 if ( ! m_pIsFinalListeners )
567 m_pIsFinalListeners =
568 new cppu::OInterfaceContainerHelper( m_aMutex );
570 m_pIsFinalListeners->addInterface( xListener );
572 else if ( aPropertyName == OUString( "RowCount" ) )
574 osl::MutexGuard aGuard( m_aMutex );
575 if ( ! m_pRowCountListeners )
576 m_pRowCountListeners =
577 new cppu::OInterfaceContainerHelper( m_aMutex );
578 m_pRowCountListeners->addInterface( xListener );
580 else
581 throw beans::UnknownPropertyException();
585 void SAL_CALL ResultSetBase::removePropertyChangeListener(
586 const OUString& aPropertyName,
587 const uno::Reference< beans::XPropertyChangeListener >& aListener )
588 throw( beans::UnknownPropertyException,
589 lang::WrappedTargetException,
590 uno::RuntimeException)
592 if( aPropertyName == OUString( "IsRowCountFinal" ) &&
593 m_pIsFinalListeners )
595 osl::MutexGuard aGuard( m_aMutex );
596 m_pIsFinalListeners->removeInterface( aListener );
598 else if ( aPropertyName == OUString( "RowCount" ) &&
599 m_pRowCountListeners )
601 osl::MutexGuard aGuard( m_aMutex );
602 m_pRowCountListeners->removeInterface( aListener );
604 else
605 throw beans::UnknownPropertyException();
609 void SAL_CALL ResultSetBase::addVetoableChangeListener(
610 const OUString& PropertyName,
611 const uno::Reference< beans::XVetoableChangeListener >& aListener )
612 throw( beans::UnknownPropertyException,
613 lang::WrappedTargetException,
614 uno::RuntimeException)
616 (void)PropertyName;
617 (void)aListener;
621 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
622 const OUString& PropertyName,
623 const uno::Reference< beans::XVetoableChangeListener >& aListener )
624 throw( beans::UnknownPropertyException,
625 lang::WrappedTargetException,
626 uno::RuntimeException)
628 (void)PropertyName;
629 (void)aListener;
634 // XResultSetMetaDataSupplier
635 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
636 ResultSetBase::getMetaData(
637 void )
638 throw( sdbc::SQLException,
639 uno::RuntimeException )
641 ::ucbhelper::ResultSetMetaData* p =
642 new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
643 return uno::Reference< sdbc::XResultSetMetaData >( p );
646 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */