Update ooo320-m1
[ooovba.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
blob12ef1cb18072ef30f9232ff36db8126973850c13
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ftpresultsetbase.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <ucbhelper/contentidentifier.hxx>
34 #include <com/sun/star/ucb/OpenMode.hpp>
35 #include <com/sun/star/uno/Reference.h>
36 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #endif
39 #include <com/sun/star/ucb/ListActionType.hpp>
40 #include <com/sun/star/ucb/XSourceInitialization.hpp>
41 #include <ucbhelper/resultsetmetadata.hxx>
42 #include "ftpresultsetbase.hxx"
44 using namespace ftp;
45 using namespace com::sun::star;
47 ResultSetBase::ResultSetBase(
48 const uno::Reference< lang::XMultiServiceFactory >& xMSF,
49 const uno::Reference< ucb::XContentProvider >& xProvider,
50 sal_Int32 nOpenMode,
51 const uno::Sequence< beans::Property >& seq,
52 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort )
53 : m_xMSF( xMSF ),
54 m_xProvider( xProvider ),
55 m_nRow( -1 ),
56 m_nWasNull( true ),
57 m_nOpenMode( nOpenMode ),
58 m_bRowCountFinal( true ),
59 m_sProperty( seq ),
60 m_sSortingInfo( seqSort ),
61 m_pDisposeEventListeners( 0 ),
62 m_pRowCountListeners( 0 ),
63 m_pIsFinalListeners( 0 )
67 ResultSetBase::~ResultSetBase()
69 delete m_pIsFinalListeners;
70 delete m_pRowCountListeners;
71 delete m_pDisposeEventListeners;
75 // XInterface
77 void SAL_CALL
78 ResultSetBase::acquire(
79 void )
80 throw()
82 OWeakObject::acquire();
86 void SAL_CALL
87 ResultSetBase::release(
88 void )
89 throw()
91 OWeakObject::release();
96 uno::Any SAL_CALL
97 ResultSetBase::queryInterface(
98 const uno::Type& rType )
99 throw( uno::RuntimeException )
101 uno::Any aRet = cppu::queryInterface(
102 rType,
103 SAL_STATIC_CAST( lang::XComponent*, this),
104 SAL_STATIC_CAST( sdbc::XRow*, this),
105 SAL_STATIC_CAST( sdbc::XResultSet*, this),
106 SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier*, this),
107 SAL_STATIC_CAST( beans::XPropertySet*, this ),
108 SAL_STATIC_CAST( ucb::XContentAccess*, this) );
109 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
114 // XComponent
117 void SAL_CALL
118 ResultSetBase::addEventListener(
119 const uno::Reference< lang::XEventListener >& Listener )
120 throw( uno::RuntimeException )
122 osl::MutexGuard aGuard( m_aMutex );
124 if ( ! m_pDisposeEventListeners )
125 m_pDisposeEventListeners =
126 new cppu::OInterfaceContainerHelper( m_aMutex );
128 m_pDisposeEventListeners->addInterface( Listener );
132 void SAL_CALL
133 ResultSetBase::removeEventListener(
134 const uno::Reference< lang::XEventListener >& Listener )
135 throw( uno::RuntimeException )
137 osl::MutexGuard aGuard( m_aMutex );
139 if ( m_pDisposeEventListeners )
140 m_pDisposeEventListeners->removeInterface( Listener );
145 void SAL_CALL
146 ResultSetBase::dispose()
147 throw( uno::RuntimeException )
149 osl::MutexGuard aGuard( m_aMutex );
151 lang::EventObject aEvt;
152 aEvt.Source = static_cast< lang::XComponent * >( this );
154 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
156 m_pDisposeEventListeners->disposeAndClear( aEvt );
158 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
160 m_pRowCountListeners->disposeAndClear( aEvt );
162 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
164 m_pIsFinalListeners->disposeAndClear( aEvt );
170 // XResultSet
172 sal_Bool SAL_CALL
173 ResultSetBase::next(
174 void )
175 throw( sdbc::SQLException,
176 uno::RuntimeException )
178 sal_Bool test;
179 if( ++m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
180 test = true;
181 else
182 test = false;
183 return test;
187 sal_Bool SAL_CALL
188 ResultSetBase::isBeforeFirst(
189 void )
190 throw( sdbc::SQLException,
191 uno::RuntimeException )
193 return m_nRow == -1;
197 sal_Bool SAL_CALL
198 ResultSetBase::isAfterLast(
199 void )
200 throw( sdbc::SQLException,
201 uno::RuntimeException )
203 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
207 sal_Bool SAL_CALL
208 ResultSetBase::isFirst(
209 void )
210 throw( sdbc::SQLException,
211 uno::RuntimeException )
213 return m_nRow == 0;
217 sal_Bool SAL_CALL
218 ResultSetBase::isLast(
219 void )
220 throw( sdbc::SQLException,
221 uno::RuntimeException)
223 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
224 return true;
225 else
226 return false;
230 void SAL_CALL
231 ResultSetBase::beforeFirst(
232 void )
233 throw( sdbc::SQLException,
234 uno::RuntimeException)
236 m_nRow = -1;
240 void SAL_CALL
241 ResultSetBase::afterLast(
242 void )
243 throw( sdbc::SQLException,
244 uno::RuntimeException )
246 m_nRow = m_aItems.size();
250 sal_Bool SAL_CALL
251 ResultSetBase::first(
252 void )
253 throw( sdbc::SQLException,
254 uno::RuntimeException)
256 m_nRow = -1;
257 return next();
261 sal_Bool SAL_CALL
262 ResultSetBase::last(
263 void )
264 throw( sdbc::SQLException,
265 uno::RuntimeException )
267 m_nRow = m_aItems.size() - 1;
268 return true;
272 sal_Int32 SAL_CALL
273 ResultSetBase::getRow(
274 void )
275 throw( sdbc::SQLException,
276 uno::RuntimeException)
278 // Test, whether behind last row
279 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
280 return 0;
281 else
282 return m_nRow+1;
286 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
287 throw( sdbc::SQLException, uno::RuntimeException)
289 if( row >= 0 )
290 m_nRow = row - 1;
291 else
293 last();
294 m_nRow += ( row + 1 );
295 if( m_nRow < -1 )
296 m_nRow = -1;
299 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
305 sal_Bool SAL_CALL
306 ResultSetBase::relative(
307 sal_Int32 row )
308 throw( sdbc::SQLException,
309 uno::RuntimeException)
311 if( isAfterLast() || isBeforeFirst() )
312 throw sdbc::SQLException();
314 if( row > 0 )
315 while( row-- )
316 next();
317 else if( row < 0 )
318 while( row++ && m_nRow > - 1 )
319 previous();
321 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
326 sal_Bool SAL_CALL
327 ResultSetBase::previous(
328 void )
329 throw( sdbc::SQLException,
330 uno::RuntimeException)
332 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
333 m_nRow = m_aItems.size(); // Correct Handling of afterLast
334 if( 0 <= m_nRow ) -- m_nRow;
336 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
340 void SAL_CALL
341 ResultSetBase::refreshRow(
342 void )
343 throw( sdbc::SQLException,
344 uno::RuntimeException)
349 sal_Bool SAL_CALL
350 ResultSetBase::rowUpdated(
351 void )
352 throw( sdbc::SQLException,
353 uno::RuntimeException )
355 return false;
358 sal_Bool SAL_CALL
359 ResultSetBase::rowInserted(
360 void )
361 throw( sdbc::SQLException,
362 uno::RuntimeException )
364 return false;
367 sal_Bool SAL_CALL
368 ResultSetBase::rowDeleted(
369 void )
370 throw( sdbc::SQLException,
371 uno::RuntimeException )
373 return false;
377 uno::Reference< uno::XInterface > SAL_CALL
378 ResultSetBase::getStatement(
379 void )
380 throw( sdbc::SQLException,
381 uno::RuntimeException )
383 uno::Reference< uno::XInterface > test( 0 );
384 return test;
388 // XCloseable
390 void SAL_CALL
391 ResultSetBase::close(
392 void )
393 throw( sdbc::SQLException,
394 uno::RuntimeException)
399 rtl::OUString SAL_CALL
400 ResultSetBase::queryContentIdentifierString(
401 void )
402 throw( uno::RuntimeException )
404 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
405 return m_aPath[m_nRow];
406 else
407 return rtl::OUString();
411 uno::Reference< ucb::XContentIdentifier > SAL_CALL
412 ResultSetBase::queryContentIdentifier(
413 void
415 throw(
416 uno::RuntimeException
419 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
421 if(!m_aIdents[m_nRow].is()) {
422 rtl::OUString url = queryContentIdentifierString();
423 if(url.getLength() )
424 m_aIdents[m_nRow] =
425 uno::Reference< ucb::XContentIdentifier >(
426 new ::ucbhelper::ContentIdentifier(m_xMSF,url) );
428 return m_aIdents[m_nRow];
431 return uno::Reference<ucb::XContentIdentifier>();
435 uno::Reference< ucb::XContent > SAL_CALL
436 ResultSetBase::queryContent(
437 void )
438 throw( uno::RuntimeException )
440 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
441 return m_xProvider->queryContent(queryContentIdentifier());
442 else
443 return uno::Reference< ucb::XContent >();
448 class XPropertySetInfoImpl
449 : public cppu::OWeakObject,
450 public beans::XPropertySetInfo
452 public:
454 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
455 : m_aSeq( aSeq )
459 void SAL_CALL acquire( void )
460 throw()
462 OWeakObject::acquire();
466 void SAL_CALL release( void )
467 throw()
469 OWeakObject::release();
472 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
473 throw( uno::RuntimeException )
475 uno::Any aRet = cppu::queryInterface(
476 rType,
477 SAL_STATIC_CAST( beans::XPropertySetInfo*, this ) );
478 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
481 uno::Sequence< beans::Property > SAL_CALL getProperties()
482 throw( uno::RuntimeException )
484 return m_aSeq;
487 beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName )
488 throw( beans::UnknownPropertyException,
489 uno::RuntimeException)
491 for( int i = 0; i < m_aSeq.getLength(); ++i )
492 if( aName == m_aSeq[i].Name )
493 return m_aSeq[i];
494 throw beans::UnknownPropertyException();
497 sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name )
498 throw( uno::RuntimeException )
500 for( int i = 0; i < m_aSeq.getLength(); ++i )
501 if( Name == m_aSeq[i].Name )
502 return true;
503 return false;
506 private:
508 uno::Sequence< beans::Property > m_aSeq;
513 // XPropertySet
514 uno::Reference< beans::XPropertySetInfo > SAL_CALL
515 ResultSetBase::getPropertySetInfo()
516 throw( uno::RuntimeException)
518 uno::Sequence< beans::Property > seq(2);
519 seq[0].Name = rtl::OUString::createFromAscii( "RowCount" );
520 seq[0].Handle = -1;
521 seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) );
522 seq[0].Attributes = beans::PropertyAttribute::READONLY;
524 seq[1].Name = rtl::OUString::createFromAscii( "IsRowCountFinal" );
525 seq[1].Handle = -1;
526 seq[1].Type = getCppuType( static_cast< sal_Bool* >(0) );
527 seq[1].Attributes = beans::PropertyAttribute::READONLY;
530 return uno::Reference< beans::XPropertySetInfo > (
531 new XPropertySetInfoImpl( seq ) );
536 void SAL_CALL ResultSetBase::setPropertyValue(
537 const rtl::OUString& aPropertyName, const uno::Any& /*aValue*/ )
538 throw( beans::UnknownPropertyException,
539 beans::PropertyVetoException,
540 lang::IllegalArgumentException,
541 lang::WrappedTargetException,
542 uno::RuntimeException)
544 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ||
545 aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
546 return;
548 throw beans::UnknownPropertyException();
552 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
553 const rtl::OUString& PropertyName )
554 throw( beans::UnknownPropertyException,
555 lang::WrappedTargetException,
556 uno::RuntimeException)
558 if( PropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
560 uno::Any aAny;
561 aAny <<= m_bRowCountFinal;
562 return aAny;
564 else if ( PropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
566 uno::Any aAny;
567 sal_Int32 count = m_aItems.size();
568 aAny <<= count;
569 return aAny;
571 else
572 throw beans::UnknownPropertyException();
576 void SAL_CALL ResultSetBase::addPropertyChangeListener(
577 const rtl::OUString& aPropertyName,
578 const uno::Reference< beans::XPropertyChangeListener >& xListener )
579 throw( beans::UnknownPropertyException,
580 lang::WrappedTargetException,
581 uno::RuntimeException)
583 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
585 osl::MutexGuard aGuard( m_aMutex );
586 if ( ! m_pIsFinalListeners )
587 m_pIsFinalListeners =
588 new cppu::OInterfaceContainerHelper( m_aMutex );
590 m_pIsFinalListeners->addInterface( xListener );
592 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
594 osl::MutexGuard aGuard( m_aMutex );
595 if ( ! m_pRowCountListeners )
596 m_pRowCountListeners =
597 new cppu::OInterfaceContainerHelper( m_aMutex );
598 m_pRowCountListeners->addInterface( xListener );
600 else
601 throw beans::UnknownPropertyException();
605 void SAL_CALL ResultSetBase::removePropertyChangeListener(
606 const rtl::OUString& aPropertyName,
607 const uno::Reference< beans::XPropertyChangeListener >& aListener )
608 throw( beans::UnknownPropertyException,
609 lang::WrappedTargetException,
610 uno::RuntimeException)
612 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) &&
613 m_pIsFinalListeners )
615 osl::MutexGuard aGuard( m_aMutex );
616 m_pIsFinalListeners->removeInterface( aListener );
618 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) &&
619 m_pRowCountListeners )
621 osl::MutexGuard aGuard( m_aMutex );
622 m_pRowCountListeners->removeInterface( aListener );
624 else
625 throw beans::UnknownPropertyException();
629 void SAL_CALL ResultSetBase::addVetoableChangeListener(
630 const rtl::OUString& /*PropertyName*/,
631 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
632 throw( beans::UnknownPropertyException,
633 lang::WrappedTargetException,
634 uno::RuntimeException)
639 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
640 const rtl::OUString& /*PropertyName*/,
641 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
642 throw( beans::UnknownPropertyException,
643 lang::WrappedTargetException,
644 uno::RuntimeException)
650 // XResultSetMetaDataSupplier
651 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
652 ResultSetBase::getMetaData(
653 void )
654 throw( sdbc::SQLException,
655 uno::RuntimeException )
657 ::ucbhelper::ResultSetMetaData* p =
658 new ::ucbhelper::ResultSetMetaData(
659 m_xMSF, m_sProperty );
660 return uno::Reference< sdbc::XResultSetMetaData >( p );