bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
blobba9f331c7150d81174472f58d389bfeff5e19917
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>
28 #include "ftpresultsetbase.hxx"
30 using namespace ftp;
31 using namespace com::sun::star;
33 ResultSetBase::ResultSetBase(
34 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, std::exception )
87 uno::Any aRet = cppu::queryInterface(
88 rType,
89 (static_cast< lang::XComponent* >(this)),
90 (static_cast< sdbc::XRow* >(this)),
91 (static_cast< sdbc::XResultSet* >(this)),
92 (static_cast< sdbc::XResultSetMetaDataSupplier* >(this)),
93 (static_cast< beans::XPropertySet* >(this)),
94 (static_cast< ucb::XContentAccess* >(this)) );
95 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
100 // XComponent
103 void SAL_CALL
104 ResultSetBase::addEventListener(
105 const uno::Reference< lang::XEventListener >& Listener )
106 throw( uno::RuntimeException, std::exception )
108 osl::MutexGuard aGuard( m_aMutex );
110 if ( ! m_pDisposeEventListeners )
111 m_pDisposeEventListeners =
112 new cppu::OInterfaceContainerHelper( m_aMutex );
114 m_pDisposeEventListeners->addInterface( Listener );
118 void SAL_CALL
119 ResultSetBase::removeEventListener(
120 const uno::Reference< lang::XEventListener >& Listener )
121 throw( uno::RuntimeException, std::exception )
123 osl::MutexGuard aGuard( m_aMutex );
125 if ( m_pDisposeEventListeners )
126 m_pDisposeEventListeners->removeInterface( Listener );
131 void SAL_CALL
132 ResultSetBase::dispose()
133 throw( uno::RuntimeException, std::exception )
135 osl::MutexGuard aGuard( m_aMutex );
137 lang::EventObject aEvt;
138 aEvt.Source = static_cast< lang::XComponent * >( this );
140 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
142 m_pDisposeEventListeners->disposeAndClear( aEvt );
144 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
146 m_pRowCountListeners->disposeAndClear( aEvt );
148 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
150 m_pIsFinalListeners->disposeAndClear( aEvt );
156 // XResultSet
158 sal_Bool SAL_CALL
159 ResultSetBase::next(
160 void )
161 throw( sdbc::SQLException,
162 uno::RuntimeException, std::exception )
164 bool test;
165 if( ++m_nRow < sal::static_int_cast<sal_Int32>(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, std::exception )
179 return m_nRow == -1;
183 sal_Bool SAL_CALL
184 ResultSetBase::isAfterLast(
185 void )
186 throw( sdbc::SQLException,
187 uno::RuntimeException, std::exception )
189 return m_nRow >= sal::static_int_cast<sal_Int32>(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, std::exception )
199 return m_nRow == 0;
203 sal_Bool SAL_CALL
204 ResultSetBase::isLast(
205 void )
206 throw( sdbc::SQLException,
207 uno::RuntimeException, std::exception)
209 if( m_nRow == sal::static_int_cast<sal_Int32>(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, std::exception)
222 m_nRow = -1;
226 void SAL_CALL
227 ResultSetBase::afterLast(
228 void )
229 throw( sdbc::SQLException,
230 uno::RuntimeException, std::exception )
232 m_nRow = m_aItems.size();
236 sal_Bool SAL_CALL
237 ResultSetBase::first(
238 void )
239 throw( sdbc::SQLException,
240 uno::RuntimeException, std::exception)
242 m_nRow = -1;
243 return next();
247 sal_Bool SAL_CALL
248 ResultSetBase::last(
249 void )
250 throw( sdbc::SQLException,
251 uno::RuntimeException, std::exception )
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, std::exception)
264 // Test, whether behind last row
265 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(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, std::exception)
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 && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
291 sal_Bool SAL_CALL
292 ResultSetBase::relative(
293 sal_Int32 row )
294 throw( sdbc::SQLException,
295 uno::RuntimeException, std::exception)
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 && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
312 sal_Bool SAL_CALL
313 ResultSetBase::previous(
314 void )
315 throw( sdbc::SQLException,
316 uno::RuntimeException, std::exception)
318 if( m_nRow > sal::static_int_cast<sal_Int32>(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 && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
326 void SAL_CALL
327 ResultSetBase::refreshRow(
328 void )
329 throw( sdbc::SQLException,
330 uno::RuntimeException, std::exception)
335 sal_Bool SAL_CALL
336 ResultSetBase::rowUpdated(
337 void )
338 throw( sdbc::SQLException,
339 uno::RuntimeException, std::exception )
341 return false;
344 sal_Bool SAL_CALL
345 ResultSetBase::rowInserted(
346 void )
347 throw( sdbc::SQLException,
348 uno::RuntimeException, std::exception )
350 return false;
353 sal_Bool SAL_CALL
354 ResultSetBase::rowDeleted(
355 void )
356 throw( sdbc::SQLException,
357 uno::RuntimeException, std::exception )
359 return false;
363 uno::Reference< uno::XInterface > SAL_CALL
364 ResultSetBase::getStatement(
365 void )
366 throw( sdbc::SQLException,
367 uno::RuntimeException, std::exception )
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, std::exception)
385 OUString SAL_CALL
386 ResultSetBase::queryContentIdentifierString(
387 void )
388 throw( uno::RuntimeException, std::exception )
390 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(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
401 throw(
402 uno::RuntimeException, std::exception
405 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
407 if(!m_aIdents[m_nRow].is()) {
408 OUString url = queryContentIdentifierString();
409 if(!url.isEmpty() )
410 m_aIdents[m_nRow] =
411 uno::Reference< ucb::XContentIdentifier >(
412 new ::ucbhelper::ContentIdentifier(url) );
414 return m_aIdents[m_nRow];
417 return uno::Reference<ucb::XContentIdentifier>();
421 uno::Reference< ucb::XContent > SAL_CALL
422 ResultSetBase::queryContent(
423 void )
424 throw( uno::RuntimeException, std::exception )
426 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
427 return m_xProvider->queryContent(queryContentIdentifier());
428 else
429 return uno::Reference< ucb::XContent >();
434 class XPropertySetInfoImpl
435 : public cppu::OWeakObject,
436 public beans::XPropertySetInfo
438 public:
440 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
441 : m_aSeq( aSeq )
445 void SAL_CALL acquire()
446 throw() SAL_OVERRIDE
448 OWeakObject::acquire();
452 void SAL_CALL release()
453 throw() SAL_OVERRIDE
455 OWeakObject::release();
458 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
459 throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
461 uno::Any aRet = cppu::queryInterface(
462 rType,
463 (static_cast< beans::XPropertySetInfo* >(this)) );
464 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
467 uno::Sequence< beans::Property > SAL_CALL getProperties()
468 throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
470 return m_aSeq;
473 beans::Property SAL_CALL getPropertyByName( const OUString& aName )
474 throw( beans::UnknownPropertyException,
475 uno::RuntimeException, std::exception) SAL_OVERRIDE
477 for( int i = 0; i < m_aSeq.getLength(); ++i )
478 if( aName == m_aSeq[i].Name )
479 return m_aSeq[i];
480 throw beans::UnknownPropertyException();
483 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
484 throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
486 for( int i = 0; i < m_aSeq.getLength(); ++i )
487 if( Name == m_aSeq[i].Name )
488 return true;
489 return false;
492 private:
494 uno::Sequence< beans::Property > m_aSeq;
499 // XPropertySet
500 uno::Reference< beans::XPropertySetInfo > SAL_CALL
501 ResultSetBase::getPropertySetInfo()
502 throw( uno::RuntimeException, std::exception)
504 uno::Sequence< beans::Property > seq(2);
505 seq[0].Name = "RowCount";
506 seq[0].Handle = -1;
507 seq[0].Type = cppu::UnoType<sal_Int32>::get();
508 seq[0].Attributes = beans::PropertyAttribute::READONLY;
510 seq[1].Name = "IsRowCountFinal";
511 seq[1].Handle = -1;
512 seq[1].Type = cppu::UnoType<sal_Bool>::get();
513 seq[1].Attributes = beans::PropertyAttribute::READONLY;
516 return uno::Reference< beans::XPropertySetInfo > (
517 new XPropertySetInfoImpl( seq ) );
522 void SAL_CALL ResultSetBase::setPropertyValue(
523 const OUString& aPropertyName, const uno::Any& /*aValue*/ )
524 throw( beans::UnknownPropertyException,
525 beans::PropertyVetoException,
526 lang::IllegalArgumentException,
527 lang::WrappedTargetException,
528 uno::RuntimeException, std::exception)
530 if( aPropertyName == "IsRowCountFinal" ||
531 aPropertyName == "RowCount" )
532 return;
534 throw beans::UnknownPropertyException();
538 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
539 const OUString& PropertyName )
540 throw( beans::UnknownPropertyException,
541 lang::WrappedTargetException,
542 uno::RuntimeException, std::exception)
544 if( PropertyName == "IsRowCountFinal" )
546 uno::Any aAny;
547 aAny <<= m_bRowCountFinal;
548 return aAny;
550 else if ( PropertyName == "RowCount" )
552 uno::Any aAny;
553 sal_Int32 count = m_aItems.size();
554 aAny <<= count;
555 return aAny;
557 else
558 throw beans::UnknownPropertyException();
562 void SAL_CALL ResultSetBase::addPropertyChangeListener(
563 const OUString& aPropertyName,
564 const uno::Reference< beans::XPropertyChangeListener >& xListener )
565 throw( beans::UnknownPropertyException,
566 lang::WrappedTargetException,
567 uno::RuntimeException, std::exception)
569 if( aPropertyName == "IsRowCountFinal" )
571 osl::MutexGuard aGuard( m_aMutex );
572 if ( ! m_pIsFinalListeners )
573 m_pIsFinalListeners =
574 new cppu::OInterfaceContainerHelper( m_aMutex );
576 m_pIsFinalListeners->addInterface( xListener );
578 else if ( aPropertyName == "RowCount" )
580 osl::MutexGuard aGuard( m_aMutex );
581 if ( ! m_pRowCountListeners )
582 m_pRowCountListeners =
583 new cppu::OInterfaceContainerHelper( m_aMutex );
584 m_pRowCountListeners->addInterface( xListener );
586 else
587 throw beans::UnknownPropertyException();
591 void SAL_CALL ResultSetBase::removePropertyChangeListener(
592 const OUString& aPropertyName,
593 const uno::Reference< beans::XPropertyChangeListener >& aListener )
594 throw( beans::UnknownPropertyException,
595 lang::WrappedTargetException,
596 uno::RuntimeException, std::exception)
598 if( aPropertyName == "IsRowCountFinal" &&
599 m_pIsFinalListeners )
601 osl::MutexGuard aGuard( m_aMutex );
602 m_pIsFinalListeners->removeInterface( aListener );
604 else if ( aPropertyName == "RowCount" &&
605 m_pRowCountListeners )
607 osl::MutexGuard aGuard( m_aMutex );
608 m_pRowCountListeners->removeInterface( aListener );
610 else
611 throw beans::UnknownPropertyException();
615 void SAL_CALL ResultSetBase::addVetoableChangeListener(
616 const OUString& /*PropertyName*/,
617 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
618 throw( beans::UnknownPropertyException,
619 lang::WrappedTargetException,
620 uno::RuntimeException, std::exception)
625 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
626 const OUString& /*PropertyName*/,
627 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
628 throw( beans::UnknownPropertyException,
629 lang::WrappedTargetException,
630 uno::RuntimeException, std::exception)
636 // XResultSetMetaDataSupplier
637 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
638 ResultSetBase::getMetaData(
639 void )
640 throw( sdbc::SQLException,
641 uno::RuntimeException, std::exception )
643 ::ucbhelper::ResultSetMetaData* p =
644 new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
645 return uno::Reference< sdbc::XResultSetMetaData >( p );
651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */