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 ************************************************************************/
30 /**************************************************************************
32 **************************************************************************
34 - remove root storage access workaround
36 *************************************************************************/
38 #include "com/sun/star/lang/DisposedException.hpp"
39 #include "com/sun/star/reflection/XProxyFactory.hpp"
41 #include "tdoc_uri.hxx"
43 #include "tdoc_stgelems.hxx"
45 using namespace com::sun::star
;
46 using namespace tdoc_ucp
;
48 //=========================================================================
49 //=========================================================================
51 // ParentStorageHolder Implementation.
53 //=========================================================================
54 //=========================================================================
56 ParentStorageHolder::ParentStorageHolder(
57 const uno::Reference
< embed::XStorage
> & xParentStorage
,
58 const rtl::OUString
& rUri
)
59 : m_xParentStorage( xParentStorage
),
60 m_bParentIsRootStorage( false )
63 if ( aUri
.isDocument() )
64 m_bParentIsRootStorage
= true;
67 //=========================================================================
68 //=========================================================================
70 // Storage Implementation.
72 //=========================================================================
73 //=========================================================================
75 Storage::Storage( const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
76 const rtl::Reference
< StorageElementFactory
> & xFactory
,
77 const rtl::OUString
& rUri
,
78 const uno::Reference
< embed::XStorage
> & xParentStorage
,
79 const uno::Reference
< embed::XStorage
> & xStorageToWrap
)
80 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
81 m_xFactory( xFactory
),
82 m_xWrappedStorage( xStorageToWrap
),
83 m_xWrappedTransObj( xStorageToWrap
, uno::UNO_QUERY
), // optional interface
84 m_xWrappedComponent( xStorageToWrap
, uno::UNO_QUERY
),
85 m_xWrappedTypeProv( xStorageToWrap
, uno::UNO_QUERY
),
86 m_bIsDocumentStorage( Uri( rUri
).isDocument() )
88 OSL_ENSURE( m_xWrappedStorage
.is(),
89 "Storage::Storage: No storage to wrap!" );
91 OSL_ENSURE( m_xWrappedComponent
.is(),
92 "Storage::Storage: No component to wrap!" );
94 OSL_ENSURE( m_xWrappedTypeProv
.is(),
95 "Storage::Storage: No Type Provider!" );
97 // Use proxy factory service to create aggregatable proxy.
100 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
101 xSMgr
->createInstance(
102 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
103 "com.sun.star.reflection.ProxyFactory" ) ) ),
105 if ( xProxyFac
.is() )
107 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStorage
);
110 catch ( uno::Exception
const & )
112 OSL_FAIL( "Storage::Storage: Caught exception!" );
115 OSL_ENSURE( m_xAggProxy
.is(),
116 "Storage::Storage: Wrapped storage cannot be aggregated!" );
118 if ( m_xAggProxy
.is() )
120 osl_incrementInterlockedCount( &m_refCount
);
122 // Solaris compiler problem:
123 // Extra block to enforce destruction of temporary object created
124 // in next statement _before_ osl_decrementInterlockedCount is
125 // called. Otherwise 'this' will destroy itself even before ctor
126 // is completed (See impl. of XInterface::release())!
128 m_xAggProxy
->setDelegator(
129 static_cast< cppu::OWeakObject
* >( this ) );
131 osl_decrementInterlockedCount( &m_refCount
);
135 //=========================================================================
139 if ( m_xAggProxy
.is() )
140 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
142 // Never dispose a document storage. Not owner!
143 if ( !isDocumentStorage() )
145 if ( m_xWrappedComponent
.is() )
150 m_xWrappedComponent
->dispose();
152 catch ( lang::DisposedException
const & )
158 OSL_FAIL( "Storage::~Storage - Caught exception!" );
164 //=========================================================================
168 //=========================================================================
171 uno::Any SAL_CALL
Storage::queryInterface( const uno::Type
& aType
)
172 throw ( uno::RuntimeException
)
174 // First, try to use interfaces implemented by myself and base class(es)
175 uno::Any aRet
= StorageUNOBase::queryInterface( aType
);
177 if ( aRet
.hasValue() )
180 // Try to use requested interface from aggregated storage
181 return m_xAggProxy
->queryAggregation( aType
);
184 //=========================================================================
186 void SAL_CALL
Storage::acquire()
189 osl_incrementInterlockedCount( &m_refCount
);
192 //=========================================================================
194 void SAL_CALL
Storage::release()
197 if ( osl_decrementInterlockedCount( &m_refCount
) == 0 )
199 m_xFactory
->releaseElement( this );
204 //=========================================================================
206 // lang::XTypeProvider
208 //=========================================================================
211 uno::Sequence
< uno::Type
> SAL_CALL
Storage::getTypes()
212 throw ( uno::RuntimeException
)
214 return m_xWrappedTypeProv
->getTypes();
217 //=========================================================================
219 uno::Sequence
< sal_Int8
> SAL_CALL
Storage::getImplementationId()
220 throw ( uno::RuntimeException
)
222 return m_xWrappedTypeProv
->getImplementationId();
225 //=========================================================================
227 // lang::XComponent (base of embed::XStorage)
229 //=========================================================================
231 void SAL_CALL
Storage::dispose()
232 throw ( uno::RuntimeException
)
234 m_xWrappedStorage
->dispose();
237 //=========================================================================
239 void SAL_CALL
Storage::addEventListener(
240 const uno::Reference
< lang::XEventListener
>& xListener
)
241 throw ( uno::RuntimeException
)
243 m_xWrappedStorage
->addEventListener( xListener
);
245 //=========================================================================
247 void SAL_CALL
Storage::removeEventListener(
248 const uno::Reference
< lang::XEventListener
>& aListener
)
249 throw (uno::RuntimeException
)
251 m_xWrappedStorage
->removeEventListener( aListener
);
254 //=========================================================================
256 // container::XElementAccess (base of container::XNameAccess)
258 //=========================================================================
261 uno::Type SAL_CALL
Storage::getElementType()
262 throw ( uno::RuntimeException
)
264 return m_xWrappedStorage
->getElementType();
267 //=========================================================================
269 ::sal_Bool SAL_CALL
Storage::hasElements()
270 throw ( uno::RuntimeException
)
272 return m_xWrappedStorage
->hasElements();
275 //=========================================================================
277 // container::XNameAccess (base of embed::XStorage)
279 //=========================================================================
282 uno::Any SAL_CALL
Storage::getByName( const ::rtl::OUString
& aName
)
283 throw ( container::NoSuchElementException
,
284 lang::WrappedTargetException
,
285 uno::RuntimeException
)
287 return m_xWrappedStorage
->getByName( aName
);
290 //=========================================================================
292 uno::Sequence
< ::rtl::OUString
> SAL_CALL
Storage::getElementNames()
293 throw ( uno::RuntimeException
)
295 return m_xWrappedStorage
->getElementNames();
298 //=========================================================================
300 ::sal_Bool SAL_CALL
Storage::hasByName( const ::rtl::OUString
& aName
)
301 throw ( uno::RuntimeException
)
303 return m_xWrappedStorage
->hasByName( aName
);
306 //=========================================================================
310 //=========================================================================
313 void SAL_CALL
Storage::copyToStorage(
314 const uno::Reference
< embed::XStorage
>& xDest
)
315 throw ( embed::InvalidStorageException
,
316 lang::IllegalArgumentException
,
318 embed::StorageWrappedTargetException
,
319 uno::RuntimeException
)
321 m_xWrappedStorage
->copyToStorage( xDest
);
324 //=========================================================================
326 uno::Reference
< io::XStream
> SAL_CALL
Storage::openStreamElement(
327 const ::rtl::OUString
& aStreamName
, sal_Int32 nOpenMode
)
328 throw ( embed::InvalidStorageException
,
329 lang::IllegalArgumentException
,
330 packages::WrongPasswordException
,
332 embed::StorageWrappedTargetException
,
333 uno::RuntimeException
)
335 return m_xWrappedStorage
->openStreamElement( aStreamName
, nOpenMode
);
338 //=========================================================================
340 uno::Reference
< io::XStream
> SAL_CALL
Storage::openEncryptedStreamElement(
341 const ::rtl::OUString
& aStreamName
,
343 const ::rtl::OUString
& aPassword
)
344 throw ( embed::InvalidStorageException
,
345 lang::IllegalArgumentException
,
346 packages::NoEncryptionException
,
347 packages::WrongPasswordException
,
349 embed::StorageWrappedTargetException
,
350 uno::RuntimeException
)
352 return m_xWrappedStorage
->openEncryptedStreamElement(
353 aStreamName
, nOpenMode
, aPassword
);
356 //=========================================================================
358 uno::Reference
< embed::XStorage
> SAL_CALL
Storage::openStorageElement(
359 const ::rtl::OUString
& aStorName
, sal_Int32 nOpenMode
)
360 throw ( embed::InvalidStorageException
,
361 lang::IllegalArgumentException
,
363 embed::StorageWrappedTargetException
,
364 uno::RuntimeException
)
366 return m_xWrappedStorage
->openStorageElement( aStorName
, nOpenMode
);
369 //=========================================================================
371 uno::Reference
< io::XStream
> SAL_CALL
Storage::cloneStreamElement(
372 const ::rtl::OUString
& aStreamName
)
373 throw ( embed::InvalidStorageException
,
374 lang::IllegalArgumentException
,
375 packages::WrongPasswordException
,
377 embed::StorageWrappedTargetException
,
378 uno::RuntimeException
)
380 return m_xWrappedStorage
->cloneStreamElement( aStreamName
);
383 //=========================================================================
385 uno::Reference
< io::XStream
> SAL_CALL
Storage::cloneEncryptedStreamElement(
386 const ::rtl::OUString
& aStreamName
,
387 const ::rtl::OUString
& aPassword
)
388 throw ( embed::InvalidStorageException
,
389 lang::IllegalArgumentException
,
390 packages::NoEncryptionException
,
391 packages::WrongPasswordException
,
393 embed::StorageWrappedTargetException
,
394 uno::RuntimeException
)
396 return m_xWrappedStorage
->cloneEncryptedStreamElement( aStreamName
,
400 //=========================================================================
402 void SAL_CALL
Storage::copyLastCommitTo(
403 const uno::Reference
< embed::XStorage
>& xTargetStorage
)
404 throw ( embed::InvalidStorageException
,
405 lang::IllegalArgumentException
,
407 embed::StorageWrappedTargetException
,
408 uno::RuntimeException
)
410 m_xWrappedStorage
->copyLastCommitTo( xTargetStorage
);
413 //=========================================================================
415 void SAL_CALL
Storage::copyStorageElementLastCommitTo(
416 const ::rtl::OUString
& aStorName
,
417 const uno::Reference
< embed::XStorage
>& xTargetStorage
)
418 throw ( embed::InvalidStorageException
,
419 lang::IllegalArgumentException
,
421 embed::StorageWrappedTargetException
,
422 uno::RuntimeException
)
424 m_xWrappedStorage
->copyStorageElementLastCommitTo( aStorName
, xTargetStorage
);
427 //=========================================================================
429 sal_Bool SAL_CALL
Storage::isStreamElement(
430 const ::rtl::OUString
& aElementName
)
431 throw ( container::NoSuchElementException
,
432 lang::IllegalArgumentException
,
433 embed::InvalidStorageException
,
434 uno::RuntimeException
)
436 return m_xWrappedStorage
->isStreamElement( aElementName
);
439 //=========================================================================
441 sal_Bool SAL_CALL
Storage::isStorageElement(
442 const ::rtl::OUString
& aElementName
)
443 throw ( container::NoSuchElementException
,
444 lang::IllegalArgumentException
,
445 embed::InvalidStorageException
,
446 uno::RuntimeException
)
448 return m_xWrappedStorage
->isStorageElement( aElementName
);
451 //=========================================================================
453 void SAL_CALL
Storage::removeElement( const ::rtl::OUString
& aElementName
)
454 throw ( embed::InvalidStorageException
,
455 lang::IllegalArgumentException
,
456 container::NoSuchElementException
,
458 embed::StorageWrappedTargetException
,
459 uno::RuntimeException
)
461 m_xWrappedStorage
->removeElement( aElementName
);
464 //=========================================================================
466 void SAL_CALL
Storage::renameElement( const ::rtl::OUString
& aEleName
,
467 const ::rtl::OUString
& aNewName
)
468 throw ( embed::InvalidStorageException
,
469 lang::IllegalArgumentException
,
470 container::NoSuchElementException
,
471 container::ElementExistException
,
473 embed::StorageWrappedTargetException
,
474 uno::RuntimeException
)
476 m_xWrappedStorage
->renameElement( aEleName
, aNewName
);
479 //=========================================================================
481 void SAL_CALL
Storage::copyElementTo(
482 const ::rtl::OUString
& aElementName
,
483 const uno::Reference
< embed::XStorage
>& xDest
,
484 const ::rtl::OUString
& aNewName
)
485 throw ( embed::InvalidStorageException
,
486 lang::IllegalArgumentException
,
487 container::NoSuchElementException
,
488 container::ElementExistException
,
490 embed::StorageWrappedTargetException
,
491 uno::RuntimeException
)
493 m_xWrappedStorage
->copyElementTo( aElementName
, xDest
, aNewName
);
496 //=========================================================================
498 void SAL_CALL
Storage::moveElementTo(
499 const ::rtl::OUString
& aElementName
,
500 const uno::Reference
< embed::XStorage
>& xDest
,
501 const ::rtl::OUString
& rNewName
)
502 throw ( embed::InvalidStorageException
,
503 lang::IllegalArgumentException
,
504 container::NoSuchElementException
,
505 container::ElementExistException
,
507 embed::StorageWrappedTargetException
,
508 uno::RuntimeException
)
510 m_xWrappedStorage
->moveElementTo( aElementName
, xDest
, rNewName
);
513 //=========================================================================
515 // embed::XTransactedObject
517 //=========================================================================
520 void SAL_CALL
Storage::commit()
521 throw ( io::IOException
,
522 lang::WrappedTargetException
,
523 uno::RuntimeException
)
525 // Never commit a root storage (-> has no parent)!
526 // Would lead in writing the whole document to disk.
528 uno::Reference
< embed::XStorage
> xParentStorage
= getParentStorage();
529 if ( xParentStorage
.is() )
531 OSL_ENSURE( m_xWrappedTransObj
.is(), "No XTransactedObject interface!" );
533 if ( m_xWrappedTransObj
.is() )
535 m_xWrappedTransObj
->commit();
537 if ( !isParentARootStorage() )
539 uno::Reference
< embed::XTransactedObject
> xParentTA(
540 xParentStorage
, uno::UNO_QUERY
);
541 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
543 if ( xParentTA
.is() )
550 //=========================================================================
552 void SAL_CALL
Storage::revert()
553 throw ( io::IOException
,
554 lang::WrappedTargetException
,
555 uno::RuntimeException
)
557 uno::Reference
< embed::XStorage
> xParentStorage
= getParentStorage();
558 if ( xParentStorage
.is() )
560 OSL_ENSURE( m_xWrappedTransObj
.is(), "No XTransactedObject interface!" );
562 if ( m_xWrappedTransObj
.is() )
564 m_xWrappedTransObj
->revert();
566 if ( !isParentARootStorage() )
568 uno::Reference
< embed::XTransactedObject
> xParentTA(
569 xParentStorage
, uno::UNO_QUERY
);
570 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
572 if ( xParentTA
.is() )
579 //=========================================================================
580 //=========================================================================
582 // OutputStream Implementation.
584 //=========================================================================
585 //=========================================================================
587 OutputStream::OutputStream(
588 const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
589 const rtl::OUString
& rUri
,
590 const uno::Reference
< embed::XStorage
> & xParentStorage
,
591 const uno::Reference
< io::XOutputStream
> & xStreamToWrap
)
592 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
593 m_xWrappedStream( xStreamToWrap
),
594 m_xWrappedComponent( xStreamToWrap
, uno::UNO_QUERY
),
595 m_xWrappedTypeProv( xStreamToWrap
, uno::UNO_QUERY
)
597 OSL_ENSURE( m_xWrappedStream
.is(),
598 "OutputStream::OutputStream: No stream to wrap!" );
600 OSL_ENSURE( m_xWrappedComponent
.is(),
601 "OutputStream::OutputStream: No component to wrap!" );
603 OSL_ENSURE( m_xWrappedTypeProv
.is(),
604 "OutputStream::OutputStream: No Type Provider!" );
606 // Use proxy factory service to create aggregatable proxy.
609 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
610 xSMgr
->createInstance(
611 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
612 "com.sun.star.reflection.ProxyFactory" ) ) ),
614 if ( xProxyFac
.is() )
616 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStream
);
619 catch ( uno::Exception
const & )
621 OSL_FAIL( "OutputStream::OutputStream: Caught exception!" );
624 OSL_ENSURE( m_xAggProxy
.is(),
625 "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" );
627 if ( m_xAggProxy
.is() )
629 osl_incrementInterlockedCount( &m_refCount
);
631 // Solaris compiler problem:
632 // Extra block to enforce destruction of temporary object created
633 // in next statement _before_ osl_decrementInterlockedCount is
634 // called. Otherwise 'this' will destroy itself even before ctor
635 // is completed (See impl. of XInterface::release())!
637 m_xAggProxy
->setDelegator(
638 static_cast< cppu::OWeakObject
* >( this ) );
640 osl_decrementInterlockedCount( &m_refCount
);
644 //=========================================================================
646 OutputStream::~OutputStream()
648 if ( m_xAggProxy
.is() )
649 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
652 //=========================================================================
656 //=========================================================================
659 uno::Any SAL_CALL
OutputStream::queryInterface( const uno::Type
& aType
)
660 throw ( uno::RuntimeException
)
662 uno::Any aRet
= OutputStreamUNOBase::queryInterface( aType
);
664 if ( aRet
.hasValue() )
667 if ( m_xAggProxy
.is() )
668 return m_xAggProxy
->queryAggregation( aType
);
673 //=========================================================================
675 // lang::XTypeProvider
677 //=========================================================================
680 uno::Sequence
< uno::Type
> SAL_CALL
OutputStream::getTypes()
681 throw ( uno::RuntimeException
)
683 return m_xWrappedTypeProv
->getTypes();
686 //=========================================================================
688 uno::Sequence
< sal_Int8
> SAL_CALL
OutputStream::getImplementationId()
689 throw ( uno::RuntimeException
)
691 return m_xWrappedTypeProv
->getImplementationId();
694 //=========================================================================
698 //=========================================================================
702 OutputStream::writeBytes( const uno::Sequence
< sal_Int8
>& aData
)
703 throw ( io::NotConnectedException
,
704 io::BufferSizeExceededException
,
706 uno::RuntimeException
)
708 m_xWrappedStream
->writeBytes( aData
);
711 //=========================================================================
714 OutputStream::flush()
715 throw ( io::NotConnectedException
,
716 io::BufferSizeExceededException
,
718 uno::RuntimeException
)
720 m_xWrappedStream
->flush();
723 //=========================================================================
726 OutputStream::closeOutput( )
727 throw ( io::NotConnectedException
,
728 io::BufferSizeExceededException
,
730 uno::RuntimeException
)
732 m_xWrappedStream
->closeOutput();
734 // Release parent storage.
735 // Now, that the stream is closed/disposed it is not needed any longer.
736 setParentStorage( uno::Reference
< embed::XStorage
>() );
739 //=========================================================================
743 //=========================================================================
747 OutputStream::dispose()
748 throw ( uno::RuntimeException
)
750 m_xWrappedComponent
->dispose();
752 // Release parent storage.
753 // Now, that the stream is closed/disposed it is not needed any longer.
754 setParentStorage( uno::Reference
< embed::XStorage
>() );
757 //=========================================================================
760 OutputStream::addEventListener(
761 const uno::Reference
< lang::XEventListener
>& xListener
)
762 throw ( uno::RuntimeException
)
764 m_xWrappedComponent
->addEventListener( xListener
);
767 //=========================================================================
770 OutputStream::removeEventListener(
771 const uno::Reference
< lang::XEventListener
>& aListener
)
772 throw ( uno::RuntimeException
)
774 m_xWrappedComponent
->removeEventListener( aListener
);
777 //=========================================================================
778 //=========================================================================
780 // Stream Implementation.
782 //=========================================================================
783 //=========================================================================
786 const uno::Reference
< lang::XMultiServiceFactory
> & xSMgr
,
787 const rtl::OUString
& rUri
,
788 const uno::Reference
< embed::XStorage
> & xParentStorage
,
789 const uno::Reference
< io::XStream
> & xStreamToWrap
)
790 : ParentStorageHolder( xParentStorage
, Uri( rUri
).getParentUri() ),
791 m_xWrappedStream( xStreamToWrap
),
792 m_xWrappedOutputStream( xStreamToWrap
->getOutputStream() ), // might be empty
793 m_xWrappedTruncate( m_xWrappedOutputStream
, uno::UNO_QUERY
), // might be empty
794 m_xWrappedInputStream( xStreamToWrap
->getInputStream(), uno::UNO_QUERY
),
795 m_xWrappedComponent( xStreamToWrap
, uno::UNO_QUERY
),
796 m_xWrappedTypeProv( xStreamToWrap
, uno::UNO_QUERY
)
798 OSL_ENSURE( m_xWrappedStream
.is(),
799 "OutputStream::OutputStream: No stream to wrap!" );
801 OSL_ENSURE( m_xWrappedComponent
.is(),
802 "OutputStream::OutputStream: No component to wrap!" );
804 OSL_ENSURE( m_xWrappedTypeProv
.is(),
805 "OutputStream::OutputStream: No Type Provider!" );
807 // Use proxy factory service to create aggregatable proxy.
810 uno::Reference
< reflection::XProxyFactory
> xProxyFac(
811 xSMgr
->createInstance(
812 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
813 "com.sun.star.reflection.ProxyFactory" ) ) ),
815 if ( xProxyFac
.is() )
817 m_xAggProxy
= xProxyFac
->createProxy( m_xWrappedStream
);
820 catch ( uno::Exception
const & )
822 OSL_FAIL( "OutputStream::OutputStream: Caught exception!" );
825 OSL_ENSURE( m_xAggProxy
.is(),
826 "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" );
828 if ( m_xAggProxy
.is() )
830 osl_incrementInterlockedCount( &m_refCount
);
832 // Solaris compiler problem:
833 // Extra block to enforce destruction of temporary object created
834 // in next statement _before_ osl_decrementInterlockedCount is
835 // called. Otherwise 'this' will destroy itself even before ctor
836 // is completed (See impl. of XInterface::release())!
838 m_xAggProxy
->setDelegator(
839 static_cast< cppu::OWeakObject
* >( this ) );
841 osl_decrementInterlockedCount( &m_refCount
);
845 //=========================================================================
849 if ( m_xAggProxy
.is() )
850 m_xAggProxy
->setDelegator( uno::Reference
< uno::XInterface
>() );
853 //=========================================================================
857 //=========================================================================
860 uno::Any SAL_CALL
Stream::queryInterface( const uno::Type
& aType
)
861 throw ( uno::RuntimeException
)
863 uno::Any aRet
= StreamUNOBase::queryInterface( aType
);
865 if ( aRet
.hasValue() )
868 if ( m_xAggProxy
.is() )
869 return m_xAggProxy
->queryAggregation( aType
);
874 //=========================================================================
876 // lang::XTypeProvider
878 //=========================================================================
881 uno::Sequence
< uno::Type
> SAL_CALL
Stream::getTypes()
882 throw ( uno::RuntimeException
)
884 return m_xWrappedTypeProv
->getTypes();
887 //=========================================================================
889 uno::Sequence
< sal_Int8
> SAL_CALL
Stream::getImplementationId()
890 throw ( uno::RuntimeException
)
892 return m_xWrappedTypeProv
->getImplementationId();
895 //=========================================================================
899 //=========================================================================
902 uno::Reference
< io::XInputStream
> SAL_CALL
Stream::getInputStream()
903 throw( uno::RuntimeException
)
905 return uno::Reference
< io::XInputStream
>( this );
908 //=========================================================================
910 uno::Reference
< io::XOutputStream
> SAL_CALL
Stream::getOutputStream()
911 throw( uno::RuntimeException
)
913 return uno::Reference
< io::XOutputStream
>( this );
916 //=========================================================================
918 // io::XOutputStream.
920 //=========================================================================
923 void SAL_CALL
Stream::writeBytes( const uno::Sequence
< sal_Int8
>& aData
)
924 throw( io::NotConnectedException
,
925 io::BufferSizeExceededException
,
927 uno::RuntimeException
)
929 if ( m_xWrappedOutputStream
.is() )
931 m_xWrappedOutputStream
->writeBytes( aData
);
936 //=========================================================================
938 void SAL_CALL
Stream::flush()
939 throw( io::NotConnectedException
,
940 io::BufferSizeExceededException
,
942 uno::RuntimeException
)
944 if ( m_xWrappedOutputStream
.is() )
946 m_xWrappedOutputStream
->flush();
951 //=========================================================================
953 void SAL_CALL
Stream::closeOutput()
954 throw( io::NotConnectedException
,
956 uno::RuntimeException
)
958 if ( m_xWrappedOutputStream
.is() )
960 m_xWrappedOutputStream
->closeOutput();
964 // Release parent storage.
965 // Now, that the stream is closed/disposed it is not needed any longer.
966 setParentStorage( uno::Reference
< embed::XStorage
>() );
969 //=========================================================================
973 //=========================================================================
976 void SAL_CALL
Stream::truncate()
977 throw( io::IOException
,
978 uno::RuntimeException
)
980 if ( m_xWrappedTruncate
.is() )
982 m_xWrappedTruncate
->truncate();
987 //=========================================================================
991 //=========================================================================
994 sal_Int32 SAL_CALL
Stream::readBytes( uno::Sequence
< sal_Int8
>& aData
,
995 sal_Int32 nBytesToRead
)
996 throw( io::NotConnectedException
,
997 io::BufferSizeExceededException
,
999 uno::RuntimeException
)
1001 return m_xWrappedInputStream
->readBytes( aData
, nBytesToRead
);
1004 //=========================================================================
1006 sal_Int32 SAL_CALL
Stream::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
,
1007 sal_Int32 nMaxBytesToRead
)
1008 throw( io::NotConnectedException
,
1009 io::BufferSizeExceededException
,
1011 uno::RuntimeException
)
1013 return m_xWrappedInputStream
->readSomeBytes( aData
, nMaxBytesToRead
);
1016 //=========================================================================
1018 void SAL_CALL
Stream::skipBytes( sal_Int32 nBytesToSkip
)
1019 throw( io::NotConnectedException
,
1020 io::BufferSizeExceededException
,
1022 uno::RuntimeException
)
1024 m_xWrappedInputStream
->skipBytes( nBytesToSkip
);
1027 //=========================================================================
1029 sal_Int32 SAL_CALL
Stream::available()
1030 throw( io::NotConnectedException
,
1032 uno::RuntimeException
)
1034 return m_xWrappedInputStream
->available();
1037 //=========================================================================
1039 void SAL_CALL
Stream::closeInput()
1040 throw( io::NotConnectedException
,
1042 uno::RuntimeException
)
1044 m_xWrappedInputStream
->closeInput();
1047 //=========================================================================
1051 //=========================================================================
1054 void SAL_CALL
Stream::dispose()
1055 throw ( uno::RuntimeException
)
1057 m_xWrappedComponent
->dispose();
1059 // Release parent storage.
1060 // Now, that the stream is closed/disposed it is not needed any longer.
1061 setParentStorage( uno::Reference
< embed::XStorage
>() );
1064 //=========================================================================
1066 void SAL_CALL
Stream::addEventListener(
1067 const uno::Reference
< lang::XEventListener
>& xListener
)
1068 throw ( uno::RuntimeException
)
1070 m_xWrappedComponent
->addEventListener( xListener
);
1073 //=========================================================================
1075 void SAL_CALL
Stream::removeEventListener(
1076 const uno::Reference
< lang::XEventListener
>& aListener
)
1077 throw ( uno::RuntimeException
)
1079 m_xWrappedComponent
->removeEventListener( aListener
);
1082 //=========================================================================
1086 //=========================================================================
1088 void Stream::commitChanges()
1089 throw( io::IOException
)
1091 uno::Reference
< embed::XTransactedObject
>
1092 xParentTA( getParentStorage(), uno::UNO_QUERY
);
1093 OSL_ENSURE( xParentTA
.is(), "No XTransactedObject interface!" );
1095 if ( xParentTA
.is() )
1099 xParentTA
->commit();
1101 catch ( lang::WrappedTargetException
const & )
1103 throw io::IOException(); // @@@
1108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */