Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
bloba876bce0f6c268fd9461589b01fbb9a6ec914008
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <ucbhelper/contentidentifier.hxx>
30 #include <com/sun/star/ucb/OpenMode.hpp>
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/ucb/ListActionType.hpp>
34 #include <com/sun/star/ucb/XSourceInitialization.hpp>
35 #include <ucbhelper/resultsetmetadata.hxx>
36 #include "ftpresultsetbase.hxx"
38 using namespace ftp;
39 using namespace com::sun::star;
41 ResultSetBase::ResultSetBase(
42 const uno::Reference< lang::XMultiServiceFactory >& xMSF,
43 const uno::Reference< ucb::XContentProvider >& xProvider,
44 sal_Int32 nOpenMode,
45 const uno::Sequence< beans::Property >& seq,
46 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort )
47 : m_xMSF( xMSF ),
48 m_xProvider( xProvider ),
49 m_nRow( -1 ),
50 m_nWasNull( true ),
51 m_nOpenMode( nOpenMode ),
52 m_bRowCountFinal( true ),
53 m_sProperty( seq ),
54 m_sSortingInfo( seqSort ),
55 m_pDisposeEventListeners( 0 ),
56 m_pRowCountListeners( 0 ),
57 m_pIsFinalListeners( 0 )
61 ResultSetBase::~ResultSetBase()
63 delete m_pIsFinalListeners;
64 delete m_pRowCountListeners;
65 delete m_pDisposeEventListeners;
69 // XInterface
71 void SAL_CALL
72 ResultSetBase::acquire(
73 void )
74 throw()
76 OWeakObject::acquire();
80 void SAL_CALL
81 ResultSetBase::release(
82 void )
83 throw()
85 OWeakObject::release();
90 uno::Any SAL_CALL
91 ResultSetBase::queryInterface(
92 const uno::Type& rType )
93 throw( uno::RuntimeException )
95 uno::Any aRet = cppu::queryInterface(
96 rType,
97 (static_cast< lang::XComponent* >(this)),
98 (static_cast< sdbc::XRow* >(this)),
99 (static_cast< sdbc::XResultSet* >(this)),
100 (static_cast< sdbc::XResultSetMetaDataSupplier* >(this)),
101 (static_cast< beans::XPropertySet* >(this)),
102 (static_cast< ucb::XContentAccess* >(this)) );
103 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
108 // XComponent
111 void SAL_CALL
112 ResultSetBase::addEventListener(
113 const uno::Reference< lang::XEventListener >& Listener )
114 throw( uno::RuntimeException )
116 osl::MutexGuard aGuard( m_aMutex );
118 if ( ! m_pDisposeEventListeners )
119 m_pDisposeEventListeners =
120 new cppu::OInterfaceContainerHelper( m_aMutex );
122 m_pDisposeEventListeners->addInterface( Listener );
126 void SAL_CALL
127 ResultSetBase::removeEventListener(
128 const uno::Reference< lang::XEventListener >& Listener )
129 throw( uno::RuntimeException )
131 osl::MutexGuard aGuard( m_aMutex );
133 if ( m_pDisposeEventListeners )
134 m_pDisposeEventListeners->removeInterface( Listener );
139 void SAL_CALL
140 ResultSetBase::dispose()
141 throw( uno::RuntimeException )
143 osl::MutexGuard aGuard( m_aMutex );
145 lang::EventObject aEvt;
146 aEvt.Source = static_cast< lang::XComponent * >( this );
148 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
150 m_pDisposeEventListeners->disposeAndClear( aEvt );
152 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
154 m_pRowCountListeners->disposeAndClear( aEvt );
156 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
158 m_pIsFinalListeners->disposeAndClear( aEvt );
164 // XResultSet
166 sal_Bool SAL_CALL
167 ResultSetBase::next(
168 void )
169 throw( sdbc::SQLException,
170 uno::RuntimeException )
172 sal_Bool test;
173 if( ++m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
174 test = true;
175 else
176 test = false;
177 return test;
181 sal_Bool SAL_CALL
182 ResultSetBase::isBeforeFirst(
183 void )
184 throw( sdbc::SQLException,
185 uno::RuntimeException )
187 return m_nRow == -1;
191 sal_Bool SAL_CALL
192 ResultSetBase::isAfterLast(
193 void )
194 throw( sdbc::SQLException,
195 uno::RuntimeException )
197 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
201 sal_Bool SAL_CALL
202 ResultSetBase::isFirst(
203 void )
204 throw( sdbc::SQLException,
205 uno::RuntimeException )
207 return m_nRow == 0;
211 sal_Bool SAL_CALL
212 ResultSetBase::isLast(
213 void )
214 throw( sdbc::SQLException,
215 uno::RuntimeException)
217 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
218 return true;
219 else
220 return false;
224 void SAL_CALL
225 ResultSetBase::beforeFirst(
226 void )
227 throw( sdbc::SQLException,
228 uno::RuntimeException)
230 m_nRow = -1;
234 void SAL_CALL
235 ResultSetBase::afterLast(
236 void )
237 throw( sdbc::SQLException,
238 uno::RuntimeException )
240 m_nRow = m_aItems.size();
244 sal_Bool SAL_CALL
245 ResultSetBase::first(
246 void )
247 throw( sdbc::SQLException,
248 uno::RuntimeException)
250 m_nRow = -1;
251 return next();
255 sal_Bool SAL_CALL
256 ResultSetBase::last(
257 void )
258 throw( sdbc::SQLException,
259 uno::RuntimeException )
261 m_nRow = m_aItems.size() - 1;
262 return true;
266 sal_Int32 SAL_CALL
267 ResultSetBase::getRow(
268 void )
269 throw( sdbc::SQLException,
270 uno::RuntimeException)
272 // Test, whether behind last row
273 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
274 return 0;
275 else
276 return m_nRow+1;
280 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
281 throw( sdbc::SQLException, uno::RuntimeException)
283 if( row >= 0 )
284 m_nRow = row - 1;
285 else
287 last();
288 m_nRow += ( row + 1 );
289 if( m_nRow < -1 )
290 m_nRow = -1;
293 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
299 sal_Bool SAL_CALL
300 ResultSetBase::relative(
301 sal_Int32 row )
302 throw( sdbc::SQLException,
303 uno::RuntimeException)
305 if( isAfterLast() || isBeforeFirst() )
306 throw sdbc::SQLException();
308 if( row > 0 )
309 while( row-- )
310 next();
311 else if( row < 0 )
312 while( row++ && m_nRow > - 1 )
313 previous();
315 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
320 sal_Bool SAL_CALL
321 ResultSetBase::previous(
322 void )
323 throw( sdbc::SQLException,
324 uno::RuntimeException)
326 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
327 m_nRow = m_aItems.size(); // Correct Handling of afterLast
328 if( 0 <= m_nRow ) -- m_nRow;
330 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
334 void SAL_CALL
335 ResultSetBase::refreshRow(
336 void )
337 throw( sdbc::SQLException,
338 uno::RuntimeException)
343 sal_Bool SAL_CALL
344 ResultSetBase::rowUpdated(
345 void )
346 throw( sdbc::SQLException,
347 uno::RuntimeException )
349 return false;
352 sal_Bool SAL_CALL
353 ResultSetBase::rowInserted(
354 void )
355 throw( sdbc::SQLException,
356 uno::RuntimeException )
358 return false;
361 sal_Bool SAL_CALL
362 ResultSetBase::rowDeleted(
363 void )
364 throw( sdbc::SQLException,
365 uno::RuntimeException )
367 return false;
371 uno::Reference< uno::XInterface > SAL_CALL
372 ResultSetBase::getStatement(
373 void )
374 throw( sdbc::SQLException,
375 uno::RuntimeException )
377 uno::Reference< uno::XInterface > test( 0 );
378 return test;
382 // XCloseable
384 void SAL_CALL
385 ResultSetBase::close(
386 void )
387 throw( sdbc::SQLException,
388 uno::RuntimeException)
393 rtl::OUString SAL_CALL
394 ResultSetBase::queryContentIdentifierString(
395 void )
396 throw( uno::RuntimeException )
398 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
399 return m_aPath[m_nRow];
400 else
401 return rtl::OUString();
405 uno::Reference< ucb::XContentIdentifier > SAL_CALL
406 ResultSetBase::queryContentIdentifier(
407 void
409 throw(
410 uno::RuntimeException
413 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
415 if(!m_aIdents[m_nRow].is()) {
416 rtl::OUString url = queryContentIdentifierString();
417 if(!url.isEmpty() )
418 m_aIdents[m_nRow] =
419 uno::Reference< ucb::XContentIdentifier >(
420 new ::ucbhelper::ContentIdentifier(m_xMSF,url) );
422 return m_aIdents[m_nRow];
425 return uno::Reference<ucb::XContentIdentifier>();
429 uno::Reference< ucb::XContent > SAL_CALL
430 ResultSetBase::queryContent(
431 void )
432 throw( uno::RuntimeException )
434 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
435 return m_xProvider->queryContent(queryContentIdentifier());
436 else
437 return uno::Reference< ucb::XContent >();
442 class XPropertySetInfoImpl
443 : public cppu::OWeakObject,
444 public beans::XPropertySetInfo
446 public:
448 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
449 : m_aSeq( aSeq )
453 void SAL_CALL acquire( void )
454 throw()
456 OWeakObject::acquire();
460 void SAL_CALL release( void )
461 throw()
463 OWeakObject::release();
466 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
467 throw( uno::RuntimeException )
469 uno::Any aRet = cppu::queryInterface(
470 rType,
471 (static_cast< beans::XPropertySetInfo* >(this)) );
472 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
475 uno::Sequence< beans::Property > SAL_CALL getProperties()
476 throw( uno::RuntimeException )
478 return m_aSeq;
481 beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName )
482 throw( beans::UnknownPropertyException,
483 uno::RuntimeException)
485 for( int i = 0; i < m_aSeq.getLength(); ++i )
486 if( aName == m_aSeq[i].Name )
487 return m_aSeq[i];
488 throw beans::UnknownPropertyException();
491 sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name )
492 throw( uno::RuntimeException )
494 for( int i = 0; i < m_aSeq.getLength(); ++i )
495 if( Name == m_aSeq[i].Name )
496 return true;
497 return false;
500 private:
502 uno::Sequence< beans::Property > m_aSeq;
507 // XPropertySet
508 uno::Reference< beans::XPropertySetInfo > SAL_CALL
509 ResultSetBase::getPropertySetInfo()
510 throw( uno::RuntimeException)
512 uno::Sequence< beans::Property > seq(2);
513 seq[0].Name = rtl::OUString("RowCount");
514 seq[0].Handle = -1;
515 seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) );
516 seq[0].Attributes = beans::PropertyAttribute::READONLY;
518 seq[1].Name = rtl::OUString("IsRowCountFinal");
519 seq[1].Handle = -1;
520 seq[1].Type = getCppuType( static_cast< sal_Bool* >(0) );
521 seq[1].Attributes = beans::PropertyAttribute::READONLY;
524 return uno::Reference< beans::XPropertySetInfo > (
525 new XPropertySetInfoImpl( seq ) );
530 void SAL_CALL ResultSetBase::setPropertyValue(
531 const rtl::OUString& aPropertyName, const uno::Any& /*aValue*/ )
532 throw( beans::UnknownPropertyException,
533 beans::PropertyVetoException,
534 lang::IllegalArgumentException,
535 lang::WrappedTargetException,
536 uno::RuntimeException)
538 if( aPropertyName == rtl::OUString("IsRowCountFinal") ||
539 aPropertyName == rtl::OUString("RowCount") )
540 return;
542 throw beans::UnknownPropertyException();
546 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
547 const rtl::OUString& PropertyName )
548 throw( beans::UnknownPropertyException,
549 lang::WrappedTargetException,
550 uno::RuntimeException)
552 if( PropertyName == rtl::OUString("IsRowCountFinal") )
554 uno::Any aAny;
555 aAny <<= m_bRowCountFinal;
556 return aAny;
558 else if ( PropertyName == rtl::OUString("RowCount") )
560 uno::Any aAny;
561 sal_Int32 count = m_aItems.size();
562 aAny <<= count;
563 return aAny;
565 else
566 throw beans::UnknownPropertyException();
570 void SAL_CALL ResultSetBase::addPropertyChangeListener(
571 const rtl::OUString& aPropertyName,
572 const uno::Reference< beans::XPropertyChangeListener >& xListener )
573 throw( beans::UnknownPropertyException,
574 lang::WrappedTargetException,
575 uno::RuntimeException)
577 if( aPropertyName == rtl::OUString("IsRowCountFinal") )
579 osl::MutexGuard aGuard( m_aMutex );
580 if ( ! m_pIsFinalListeners )
581 m_pIsFinalListeners =
582 new cppu::OInterfaceContainerHelper( m_aMutex );
584 m_pIsFinalListeners->addInterface( xListener );
586 else if ( aPropertyName == rtl::OUString("RowCount") )
588 osl::MutexGuard aGuard( m_aMutex );
589 if ( ! m_pRowCountListeners )
590 m_pRowCountListeners =
591 new cppu::OInterfaceContainerHelper( m_aMutex );
592 m_pRowCountListeners->addInterface( xListener );
594 else
595 throw beans::UnknownPropertyException();
599 void SAL_CALL ResultSetBase::removePropertyChangeListener(
600 const rtl::OUString& aPropertyName,
601 const uno::Reference< beans::XPropertyChangeListener >& aListener )
602 throw( beans::UnknownPropertyException,
603 lang::WrappedTargetException,
604 uno::RuntimeException)
606 if( aPropertyName == rtl::OUString("IsRowCountFinal") &&
607 m_pIsFinalListeners )
609 osl::MutexGuard aGuard( m_aMutex );
610 m_pIsFinalListeners->removeInterface( aListener );
612 else if ( aPropertyName == rtl::OUString("RowCount") &&
613 m_pRowCountListeners )
615 osl::MutexGuard aGuard( m_aMutex );
616 m_pRowCountListeners->removeInterface( aListener );
618 else
619 throw beans::UnknownPropertyException();
623 void SAL_CALL ResultSetBase::addVetoableChangeListener(
624 const rtl::OUString& /*PropertyName*/,
625 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
626 throw( beans::UnknownPropertyException,
627 lang::WrappedTargetException,
628 uno::RuntimeException)
633 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
634 const rtl::OUString& /*PropertyName*/,
635 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
636 throw( beans::UnknownPropertyException,
637 lang::WrappedTargetException,
638 uno::RuntimeException)
644 // XResultSetMetaDataSupplier
645 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
646 ResultSetBase::getMetaData(
647 void )
648 throw( sdbc::SQLException,
649 uno::RuntimeException )
651 ::ucbhelper::ResultSetMetaData* p =
652 new ::ucbhelper::ResultSetMetaData(
653 m_xMSF, m_sProperty );
654 return uno::Reference< sdbc::XResultSetMetaData >( p );
660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */