1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdoc_stgelems.cxx,v $
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"
34 /**************************************************************************
36 **************************************************************************
38 - remove root storage access workaround
40 *************************************************************************/
42 #include "com/sun/star/lang/DisposedException.hpp"
43 #include "com/sun/star/reflection/XProxyFactory.hpp"
45 #include "tdoc_uri.hxx"
47 #include "tdoc_stgelems.hxx"
49 using namespace com::sun::star
;
50 using namespace tdoc_ucp
;
52 //=========================================================================
53 //=========================================================================
55 // ParentStorageHolder Implementation.
57 //=========================================================================
58 //=========================================================================
60 ParentStorageHolder::ParentStorageHolder(
61 const uno::Reference
< embed::XStorage
> & xParentStorage
,
62 const rtl::OUString
& rUri
)
63 : m_xParentStorage( xParentStorage
),
64 m_bParentIsRootStorage( false )
67 if ( aUri
.isDocument() )
68 m_bParentIsRootStorage
= true;
71 //=========================================================================
72 //=========================================================================
74 // Storage Implementation.
76 //=========================================================================
77 //=========================================================================
79 Storage::Storage( const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
80 const rtl::Reference
< StorageElementFactory
> & xFactory
,
81 const rtl::OUString
& rUri
,
82 const uno::Reference
< embed::XStorage
> & xParentStorage
,
83 const uno::Reference
< embed::XStorage
> & xStorageToWrap
)
84 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
85 m_xFactory( xFactory
),
86 m_xWrappedStorage( xStorageToWrap
),
87 m_xWrappedTransObj( xStorageToWrap
, uno::UNO_QUERY
), // optional interface
88 m_xWrappedComponent( xStorageToWrap
, uno::UNO_QUERY
),
89 m_xWrappedTypeProv( xStorageToWrap
, uno::UNO_QUERY
),
90 m_bIsDocumentStorage( Uri( rUri
).isDocument() )
92 OSL_ENSURE( m_xWrappedStorage
.is(),
93 "Storage::Storage: No storage to wrap!" );
95 OSL_ENSURE( m_xWrappedComponent
.is(),
96 "Storage::Storage: No component to wrap!" );
98 OSL_ENSURE( m_xWrappedTypeProv
.is(),
99 "Storage::Storage: No Type Provider!" );
101 // Use proxy factory service to create aggregatable proxy.
104 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
105 xSMgr
->createInstance(
106 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
107 "com.sun.star.reflection.ProxyFactory" ) ) ),
109 if ( xProxyFac
.is() )
111 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStorage
);
114 catch ( uno::Exception
const & )
116 OSL_ENSURE( false, "Storage::Storage: Caught exception!" );
119 OSL_ENSURE( m_xAggProxy
.is(),
120 "Storage::Storage: Wrapped storage cannot be aggregated!" );
122 if ( m_xAggProxy
.is() )
124 osl_incrementInterlockedCount( &m_refCount
);
126 // Solaris compiler problem:
127 // Extra block to enforce destruction of temporary object created
128 // in next statement _before_ osl_decrementInterlockedCount is
129 // called. Otherwise 'this' will destroy itself even before ctor
130 // is completed (See impl. of XInterface::release())!
132 m_xAggProxy
->setDelegator(
133 static_cast< cppu::OWeakObject
* >( this ) );
135 osl_decrementInterlockedCount( &m_refCount
);
139 //=========================================================================
143 if ( m_xAggProxy
.is() )
144 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
146 // Never dispose a document storage. Not owner!
147 if ( !isDocumentStorage() )
149 if ( m_xWrappedComponent
.is() )
154 m_xWrappedComponent
->dispose();
156 catch ( lang::DisposedException
const & )
162 OSL_ENSURE( false, "Storage::~Storage - Caught exception!" );
168 //=========================================================================
172 //=========================================================================
175 uno::Any SAL_CALL
Storage::queryInterface( const uno::Type
& aType
)
176 throw ( uno::RuntimeException
)
178 // First, try to use interfaces implemented by myself and base class(es)
179 uno::Any aRet
= StorageUNOBase::queryInterface( aType
);
181 if ( aRet
.hasValue() )
184 // Try to use requested interface from aggregated storage
185 return m_xAggProxy
->queryAggregation( aType
);
188 //=========================================================================
190 void SAL_CALL
Storage::acquire()
193 osl_incrementInterlockedCount( &m_refCount
);
196 //=========================================================================
198 void SAL_CALL
Storage::release()
201 if ( osl_decrementInterlockedCount( &m_refCount
) == 0 )
203 m_xFactory
->releaseElement( this );
208 //=========================================================================
210 // lang::XTypeProvider
212 //=========================================================================
215 uno::Sequence
< uno::Type
> SAL_CALL
Storage::getTypes()
216 throw ( uno::RuntimeException
)
218 return m_xWrappedTypeProv
->getTypes();
221 //=========================================================================
223 uno::Sequence
< sal_Int8
> SAL_CALL
Storage::getImplementationId()
224 throw ( uno::RuntimeException
)
226 return m_xWrappedTypeProv
->getImplementationId();
229 //=========================================================================
231 // lang::XComponent (base of embed::XStorage)
233 //=========================================================================
235 void SAL_CALL
Storage::dispose()
236 throw ( uno::RuntimeException
)
238 m_xWrappedStorage
->dispose();
241 //=========================================================================
243 void SAL_CALL
Storage::addEventListener(
244 const uno::Reference
< lang::XEventListener
>& xListener
)
245 throw ( uno::RuntimeException
)
247 m_xWrappedStorage
->addEventListener( xListener
);
249 //=========================================================================
251 void SAL_CALL
Storage::removeEventListener(
252 const uno::Reference
< lang::XEventListener
>& aListener
)
253 throw (uno::RuntimeException
)
255 m_xWrappedStorage
->removeEventListener( aListener
);
258 //=========================================================================
260 // container::XElementAccess (base of container::XNameAccess)
262 //=========================================================================
265 uno::Type SAL_CALL
Storage::getElementType()
266 throw ( uno::RuntimeException
)
268 return m_xWrappedStorage
->getElementType();
271 //=========================================================================
273 ::sal_Bool SAL_CALL
Storage::hasElements()
274 throw ( uno::RuntimeException
)
276 return m_xWrappedStorage
->hasElements();
279 //=========================================================================
281 // container::XNameAccess (base of embed::XStorage)
283 //=========================================================================
286 uno::Any SAL_CALL
Storage::getByName( const ::rtl::OUString
& aName
)
287 throw ( container::NoSuchElementException
,
288 lang::WrappedTargetException
,
289 uno::RuntimeException
)
291 return m_xWrappedStorage
->getByName( aName
);
294 //=========================================================================
296 uno::Sequence
< ::rtl::OUString
> SAL_CALL
Storage::getElementNames()
297 throw ( uno::RuntimeException
)
299 return m_xWrappedStorage
->getElementNames();
302 //=========================================================================
304 ::sal_Bool SAL_CALL
Storage::hasByName( const ::rtl::OUString
& aName
)
305 throw ( uno::RuntimeException
)
307 return m_xWrappedStorage
->hasByName( aName
);
310 //=========================================================================
314 //=========================================================================
317 void SAL_CALL
Storage::copyToStorage(
318 const uno::Reference
< embed::XStorage
>& xDest
)
319 throw ( embed::InvalidStorageException
,
320 lang::IllegalArgumentException
,
322 embed::StorageWrappedTargetException
,
323 uno::RuntimeException
)
325 m_xWrappedStorage
->copyToStorage( xDest
);
328 //=========================================================================
330 uno::Reference
< io::XStream
> SAL_CALL
Storage::openStreamElement(
331 const ::rtl::OUString
& aStreamName
, sal_Int32 nOpenMode
)
332 throw ( embed::InvalidStorageException
,
333 lang::IllegalArgumentException
,
334 packages::WrongPasswordException
,
336 embed::StorageWrappedTargetException
,
337 uno::RuntimeException
)
339 return m_xWrappedStorage
->openStreamElement( aStreamName
, nOpenMode
);
342 //=========================================================================
344 uno::Reference
< io::XStream
> SAL_CALL
Storage::openEncryptedStreamElement(
345 const ::rtl::OUString
& aStreamName
,
347 const ::rtl::OUString
& aPassword
)
348 throw ( embed::InvalidStorageException
,
349 lang::IllegalArgumentException
,
350 packages::NoEncryptionException
,
351 packages::WrongPasswordException
,
353 embed::StorageWrappedTargetException
,
354 uno::RuntimeException
)
356 return m_xWrappedStorage
->openEncryptedStreamElement(
357 aStreamName
, nOpenMode
, aPassword
);
360 //=========================================================================
362 uno::Reference
< embed::XStorage
> SAL_CALL
Storage::openStorageElement(
363 const ::rtl::OUString
& aStorName
, sal_Int32 nOpenMode
)
364 throw ( embed::InvalidStorageException
,
365 lang::IllegalArgumentException
,
367 embed::StorageWrappedTargetException
,
368 uno::RuntimeException
)
370 return m_xWrappedStorage
->openStorageElement( aStorName
, nOpenMode
);
373 //=========================================================================
375 uno::Reference
< io::XStream
> SAL_CALL
Storage::cloneStreamElement(
376 const ::rtl::OUString
& aStreamName
)
377 throw ( embed::InvalidStorageException
,
378 lang::IllegalArgumentException
,
379 packages::WrongPasswordException
,
381 embed::StorageWrappedTargetException
,
382 uno::RuntimeException
)
384 return m_xWrappedStorage
->cloneStreamElement( aStreamName
);
387 //=========================================================================
389 uno::Reference
< io::XStream
> SAL_CALL
Storage::cloneEncryptedStreamElement(
390 const ::rtl::OUString
& aStreamName
,
391 const ::rtl::OUString
& aPassword
)
392 throw ( embed::InvalidStorageException
,
393 lang::IllegalArgumentException
,
394 packages::NoEncryptionException
,
395 packages::WrongPasswordException
,
397 embed::StorageWrappedTargetException
,
398 uno::RuntimeException
)
400 return m_xWrappedStorage
->cloneEncryptedStreamElement( aStreamName
,
404 //=========================================================================
406 void SAL_CALL
Storage::copyLastCommitTo(
407 const uno::Reference
< embed::XStorage
>& xTargetStorage
)
408 throw ( embed::InvalidStorageException
,
409 lang::IllegalArgumentException
,
411 embed::StorageWrappedTargetException
,
412 uno::RuntimeException
)
414 m_xWrappedStorage
->copyLastCommitTo( xTargetStorage
);
417 //=========================================================================
419 void SAL_CALL
Storage::copyStorageElementLastCommitTo(
420 const ::rtl::OUString
& aStorName
,
421 const uno::Reference
< embed::XStorage
>& xTargetStorage
)
422 throw ( embed::InvalidStorageException
,
423 lang::IllegalArgumentException
,
425 embed::StorageWrappedTargetException
,
426 uno::RuntimeException
)
428 m_xWrappedStorage
->copyStorageElementLastCommitTo( aStorName
, xTargetStorage
);
431 //=========================================================================
433 sal_Bool SAL_CALL
Storage::isStreamElement(
434 const ::rtl::OUString
& aElementName
)
435 throw ( container::NoSuchElementException
,
436 lang::IllegalArgumentException
,
437 embed::InvalidStorageException
,
438 uno::RuntimeException
)
440 return m_xWrappedStorage
->isStreamElement( aElementName
);
443 //=========================================================================
445 sal_Bool SAL_CALL
Storage::isStorageElement(
446 const ::rtl::OUString
& aElementName
)
447 throw ( container::NoSuchElementException
,
448 lang::IllegalArgumentException
,
449 embed::InvalidStorageException
,
450 uno::RuntimeException
)
452 return m_xWrappedStorage
->isStorageElement( aElementName
);
455 //=========================================================================
457 void SAL_CALL
Storage::removeElement( const ::rtl::OUString
& aElementName
)
458 throw ( embed::InvalidStorageException
,
459 lang::IllegalArgumentException
,
460 container::NoSuchElementException
,
462 embed::StorageWrappedTargetException
,
463 uno::RuntimeException
)
465 m_xWrappedStorage
->removeElement( aElementName
);
468 //=========================================================================
470 void SAL_CALL
Storage::renameElement( const ::rtl::OUString
& aEleName
,
471 const ::rtl::OUString
& aNewName
)
472 throw ( embed::InvalidStorageException
,
473 lang::IllegalArgumentException
,
474 container::NoSuchElementException
,
475 container::ElementExistException
,
477 embed::StorageWrappedTargetException
,
478 uno::RuntimeException
)
480 m_xWrappedStorage
->renameElement( aEleName
, aNewName
);
483 //=========================================================================
485 void SAL_CALL
Storage::copyElementTo(
486 const ::rtl::OUString
& aElementName
,
487 const uno::Reference
< embed::XStorage
>& xDest
,
488 const ::rtl::OUString
& aNewName
)
489 throw ( embed::InvalidStorageException
,
490 lang::IllegalArgumentException
,
491 container::NoSuchElementException
,
492 container::ElementExistException
,
494 embed::StorageWrappedTargetException
,
495 uno::RuntimeException
)
497 m_xWrappedStorage
->copyElementTo( aElementName
, xDest
, aNewName
);
500 //=========================================================================
502 void SAL_CALL
Storage::moveElementTo(
503 const ::rtl::OUString
& aElementName
,
504 const uno::Reference
< embed::XStorage
>& xDest
,
505 const ::rtl::OUString
& rNewName
)
506 throw ( embed::InvalidStorageException
,
507 lang::IllegalArgumentException
,
508 container::NoSuchElementException
,
509 container::ElementExistException
,
511 embed::StorageWrappedTargetException
,
512 uno::RuntimeException
)
514 m_xWrappedStorage
->moveElementTo( aElementName
, xDest
, rNewName
);
517 //=========================================================================
519 // embed::XTransactedObject
521 //=========================================================================
524 void SAL_CALL
Storage::commit()
525 throw ( io::IOException
,
526 lang::WrappedTargetException
,
527 uno::RuntimeException
)
529 // Never commit a root storage (-> has no parent)!
530 // Would lead in writing the whole document to disk.
532 uno::Reference
< embed::XStorage
> xParentStorage
= getParentStorage();
533 if ( xParentStorage
.is() )
535 OSL_ENSURE( m_xWrappedTransObj
.is(), "No XTransactedObject interface!" );
537 if ( m_xWrappedTransObj
.is() )
539 m_xWrappedTransObj
->commit();
541 if ( !isParentARootStorage() )
543 uno::Reference
< embed::XTransactedObject
> xParentTA(
544 xParentStorage
, uno::UNO_QUERY
);
545 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
547 if ( xParentTA
.is() )
554 //=========================================================================
556 void SAL_CALL
Storage::revert()
557 throw ( io::IOException
,
558 lang::WrappedTargetException
,
559 uno::RuntimeException
)
561 uno::Reference
< embed::XStorage
> xParentStorage
= getParentStorage();
562 if ( xParentStorage
.is() )
564 OSL_ENSURE( m_xWrappedTransObj
.is(), "No XTransactedObject interface!" );
566 if ( m_xWrappedTransObj
.is() )
568 m_xWrappedTransObj
->revert();
570 if ( !isParentARootStorage() )
572 uno::Reference
< embed::XTransactedObject
> xParentTA(
573 xParentStorage
, uno::UNO_QUERY
);
574 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
576 if ( xParentTA
.is() )
583 //=========================================================================
584 //=========================================================================
586 // OutputStream Implementation.
588 //=========================================================================
589 //=========================================================================
591 OutputStream::OutputStream(
592 const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
593 const rtl::OUString
& rUri
,
594 const uno::Reference
< embed::XStorage
> & xParentStorage
,
595 const uno::Reference
< io::XOutputStream
> & xStreamToWrap
)
596 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
597 m_xWrappedStream( xStreamToWrap
),
598 m_xWrappedComponent( xStreamToWrap
, uno::UNO_QUERY
),
599 m_xWrappedTypeProv( xStreamToWrap
, uno::UNO_QUERY
)
601 OSL_ENSURE( m_xWrappedStream
.is(),
602 "OutputStream::OutputStream: No stream to wrap!" );
604 OSL_ENSURE( m_xWrappedComponent
.is(),
605 "OutputStream::OutputStream: No component to wrap!" );
607 OSL_ENSURE( m_xWrappedTypeProv
.is(),
608 "OutputStream::OutputStream: No Type Provider!" );
610 // Use proxy factory service to create aggregatable proxy.
613 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
614 xSMgr
->createInstance(
615 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
616 "com.sun.star.reflection.ProxyFactory" ) ) ),
618 if ( xProxyFac
.is() )
620 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStream
);
623 catch ( uno::Exception
const & )
625 OSL_ENSURE( false, "OutputStream::OutputStream: Caught exception!" );
628 OSL_ENSURE( m_xAggProxy
.is(),
629 "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" );
631 if ( m_xAggProxy
.is() )
633 osl_incrementInterlockedCount( &m_refCount
);
635 // Solaris compiler problem:
636 // Extra block to enforce destruction of temporary object created
637 // in next statement _before_ osl_decrementInterlockedCount is
638 // called. Otherwise 'this' will destroy itself even before ctor
639 // is completed (See impl. of XInterface::release())!
641 m_xAggProxy
->setDelegator(
642 static_cast< cppu::OWeakObject
* >( this ) );
644 osl_decrementInterlockedCount( &m_refCount
);
648 //=========================================================================
650 OutputStream::~OutputStream()
652 if ( m_xAggProxy
.is() )
653 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
656 //=========================================================================
660 //=========================================================================
663 uno::Any SAL_CALL
OutputStream::queryInterface( const uno::Type
& aType
)
664 throw ( uno::RuntimeException
)
666 uno::Any aRet
= OutputStreamUNOBase::queryInterface( aType
);
668 if ( aRet
.hasValue() )
671 if ( m_xAggProxy
.is() )
672 return m_xAggProxy
->queryAggregation( aType
);
677 //=========================================================================
679 // lang::XTypeProvider
681 //=========================================================================
684 uno::Sequence
< uno::Type
> SAL_CALL
OutputStream::getTypes()
685 throw ( uno::RuntimeException
)
687 return m_xWrappedTypeProv
->getTypes();
690 //=========================================================================
692 uno::Sequence
< sal_Int8
> SAL_CALL
OutputStream::getImplementationId()
693 throw ( uno::RuntimeException
)
695 return m_xWrappedTypeProv
->getImplementationId();
698 //=========================================================================
702 //=========================================================================
706 OutputStream::writeBytes( const uno::Sequence
< sal_Int8
>& aData
)
707 throw ( io::NotConnectedException
,
708 io::BufferSizeExceededException
,
710 uno::RuntimeException
)
712 m_xWrappedStream
->writeBytes( aData
);
715 //=========================================================================
718 OutputStream::flush()
719 throw ( io::NotConnectedException
,
720 io::BufferSizeExceededException
,
722 uno::RuntimeException
)
724 m_xWrappedStream
->flush();
727 //=========================================================================
730 OutputStream::closeOutput( )
731 throw ( io::NotConnectedException
,
732 io::BufferSizeExceededException
,
734 uno::RuntimeException
)
736 m_xWrappedStream
->closeOutput();
738 // Release parent storage.
739 // Now, that the stream is closed/disposed it is not needed any longer.
740 setParentStorage( uno::Reference
< embed::XStorage
>() );
743 //=========================================================================
747 //=========================================================================
751 OutputStream::dispose()
752 throw ( uno::RuntimeException
)
754 m_xWrappedComponent
->dispose();
756 // Release parent storage.
757 // Now, that the stream is closed/disposed it is not needed any longer.
758 setParentStorage( uno::Reference
< embed::XStorage
>() );
761 //=========================================================================
764 OutputStream::addEventListener(
765 const uno::Reference
< lang::XEventListener
>& xListener
)
766 throw ( uno::RuntimeException
)
768 m_xWrappedComponent
->addEventListener( xListener
);
771 //=========================================================================
774 OutputStream::removeEventListener(
775 const uno::Reference
< lang::XEventListener
>& aListener
)
776 throw ( uno::RuntimeException
)
778 m_xWrappedComponent
->removeEventListener( aListener
);
781 //=========================================================================
782 //=========================================================================
784 // Stream Implementation.
786 //=========================================================================
787 //=========================================================================
790 const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
791 const rtl::OUString
& rUri
,
792 const uno::Reference
< embed::XStorage
> & xParentStorage
,
793 const uno::Reference
< io::XStream
> & xStreamToWrap
)
794 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
795 m_xWrappedStream( xStreamToWrap
),
796 m_xWrappedOutputStream( xStreamToWrap
->getOutputStream() ), // might be empty
797 m_xWrappedTruncate( m_xWrappedOutputStream
, uno::UNO_QUERY
), // might be empty
798 m_xWrappedInputStream( xStreamToWrap
->getInputStream(), uno::UNO_QUERY
),
799 m_xWrappedComponent( xStreamToWrap
, uno::UNO_QUERY
),
800 m_xWrappedTypeProv( xStreamToWrap
, uno::UNO_QUERY
)
802 OSL_ENSURE( m_xWrappedStream
.is(),
803 "OutputStream::OutputStream: No stream to wrap!" );
805 OSL_ENSURE( m_xWrappedComponent
.is(),
806 "OutputStream::OutputStream: No component to wrap!" );
808 OSL_ENSURE( m_xWrappedTypeProv
.is(),
809 "OutputStream::OutputStream: No Type Provider!" );
811 // Use proxy factory service to create aggregatable proxy.
814 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
815 xSMgr
->createInstance(
816 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
817 "com.sun.star.reflection.ProxyFactory" ) ) ),
819 if ( xProxyFac
.is() )
821 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStream
);
824 catch ( uno::Exception
const & )
826 OSL_ENSURE( false, "OutputStream::OutputStream: Caught exception!" );
829 OSL_ENSURE( m_xAggProxy
.is(),
830 "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" );
832 if ( m_xAggProxy
.is() )
834 osl_incrementInterlockedCount( &m_refCount
);
836 // Solaris compiler problem:
837 // Extra block to enforce destruction of temporary object created
838 // in next statement _before_ osl_decrementInterlockedCount is
839 // called. Otherwise 'this' will destroy itself even before ctor
840 // is completed (See impl. of XInterface::release())!
842 m_xAggProxy
->setDelegator(
843 static_cast< cppu::OWeakObject
* >( this ) );
845 osl_decrementInterlockedCount( &m_refCount
);
849 //=========================================================================
853 if ( m_xAggProxy
.is() )
854 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
857 //=========================================================================
861 //=========================================================================
864 uno::Any SAL_CALL
Stream::queryInterface( const uno::Type
& aType
)
865 throw ( uno::RuntimeException
)
867 uno::Any aRet
= StreamUNOBase::queryInterface( aType
);
869 if ( aRet
.hasValue() )
872 if ( m_xAggProxy
.is() )
873 return m_xAggProxy
->queryAggregation( aType
);
878 //=========================================================================
880 // lang::XTypeProvider
882 //=========================================================================
885 uno::Sequence
< uno::Type
> SAL_CALL
Stream::getTypes()
886 throw ( uno::RuntimeException
)
888 return m_xWrappedTypeProv
->getTypes();
891 //=========================================================================
893 uno::Sequence
< sal_Int8
> SAL_CALL
Stream::getImplementationId()
894 throw ( uno::RuntimeException
)
896 return m_xWrappedTypeProv
->getImplementationId();
899 //=========================================================================
903 //=========================================================================
906 uno::Reference
< io::XInputStream
> SAL_CALL
Stream::getInputStream()
907 throw( uno::RuntimeException
)
909 return uno::Reference
< io::XInputStream
>( this );
912 //=========================================================================
914 uno::Reference
< io::XOutputStream
> SAL_CALL
Stream::getOutputStream()
915 throw( uno::RuntimeException
)
917 return uno::Reference
< io::XOutputStream
>( this );
920 //=========================================================================
922 // io::XOutputStream.
924 //=========================================================================
927 void SAL_CALL
Stream::writeBytes( const uno::Sequence
< sal_Int8
>& aData
)
928 throw( io::NotConnectedException
,
929 io::BufferSizeExceededException
,
931 uno::RuntimeException
)
933 if ( m_xWrappedOutputStream
.is() )
935 m_xWrappedOutputStream
->writeBytes( aData
);
940 //=========================================================================
942 void SAL_CALL
Stream::flush()
943 throw( io::NotConnectedException
,
944 io::BufferSizeExceededException
,
946 uno::RuntimeException
)
948 if ( m_xWrappedOutputStream
.is() )
950 m_xWrappedOutputStream
->flush();
955 //=========================================================================
957 void SAL_CALL
Stream::closeOutput()
958 throw( io::NotConnectedException
,
960 uno::RuntimeException
)
962 if ( m_xWrappedOutputStream
.is() )
964 m_xWrappedOutputStream
->closeOutput();
968 // Release parent storage.
969 // Now, that the stream is closed/disposed it is not needed any longer.
970 setParentStorage( uno::Reference
< embed::XStorage
>() );
973 //=========================================================================
977 //=========================================================================
980 void SAL_CALL
Stream::truncate()
981 throw( io::IOException
,
982 uno::RuntimeException
)
984 if ( m_xWrappedTruncate
.is() )
986 m_xWrappedTruncate
->truncate();
991 //=========================================================================
995 //=========================================================================
998 sal_Int32 SAL_CALL
Stream::readBytes( uno::Sequence
< sal_Int8
>& aData
,
999 sal_Int32 nBytesToRead
)
1000 throw( io::NotConnectedException
,
1001 io::BufferSizeExceededException
,
1003 uno::RuntimeException
)
1005 return m_xWrappedInputStream
->readBytes( aData
, nBytesToRead
);
1008 //=========================================================================
1010 sal_Int32 SAL_CALL
Stream::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
,
1011 sal_Int32 nMaxBytesToRead
)
1012 throw( io::NotConnectedException
,
1013 io::BufferSizeExceededException
,
1015 uno::RuntimeException
)
1017 return m_xWrappedInputStream
->readSomeBytes( aData
, nMaxBytesToRead
);
1020 //=========================================================================
1022 void SAL_CALL
Stream::skipBytes( sal_Int32 nBytesToSkip
)
1023 throw( io::NotConnectedException
,
1024 io::BufferSizeExceededException
,
1026 uno::RuntimeException
)
1028 m_xWrappedInputStream
->skipBytes( nBytesToSkip
);
1031 //=========================================================================
1033 sal_Int32 SAL_CALL
Stream::available()
1034 throw( io::NotConnectedException
,
1036 uno::RuntimeException
)
1038 return m_xWrappedInputStream
->available();
1041 //=========================================================================
1043 void SAL_CALL
Stream::closeInput()
1044 throw( io::NotConnectedException
,
1046 uno::RuntimeException
)
1048 m_xWrappedInputStream
->closeInput();
1051 //=========================================================================
1055 //=========================================================================
1058 void SAL_CALL
Stream::dispose()
1059 throw ( uno::RuntimeException
)
1061 m_xWrappedComponent
->dispose();
1063 // Release parent storage.
1064 // Now, that the stream is closed/disposed it is not needed any longer.
1065 setParentStorage( uno::Reference
< embed::XStorage
>() );
1068 //=========================================================================
1070 void SAL_CALL
Stream::addEventListener(
1071 const uno::Reference
< lang::XEventListener
>& xListener
)
1072 throw ( uno::RuntimeException
)
1074 m_xWrappedComponent
->addEventListener( xListener
);
1077 //=========================================================================
1079 void SAL_CALL
Stream::removeEventListener(
1080 const uno::Reference
< lang::XEventListener
>& aListener
)
1081 throw ( uno::RuntimeException
)
1083 m_xWrappedComponent
->removeEventListener( aListener
);
1086 //=========================================================================
1090 //=========================================================================
1092 void Stream::commitChanges()
1093 throw( io::IOException
)
1095 uno::Reference
< embed::XTransactedObject
>
1096 xParentTA( getParentStorage(), uno::UNO_QUERY
);
1097 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
1099 if ( xParentTA
.is() )
1103 xParentTA
->commit();
1105 catch ( lang::WrappedTargetException
const & )
1107 throw io::IOException(); // @@@