merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / tdoc / tdoc_stgelems.cxx
blob6e0e32717433ba64d7c67d276b07c4110b502ddb
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: tdoc_stgelems.cxx,v $
10 * $Revision: 1.9 $
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 /**************************************************************************
35 TODO
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 )
66 Uri aUri( rUri );
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" ) ) ),
108 uno::UNO_QUERY );
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 //=========================================================================
140 // virtual
141 Storage::~Storage()
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() )
151 // "Auto-dispose"...
154 m_xWrappedComponent->dispose();
156 catch ( lang::DisposedException const & )
158 // might happen.
160 catch ( ... )
162 OSL_ENSURE( false, "Storage::~Storage - Caught exception!" );
168 //=========================================================================
170 // uno::XInterface
172 //=========================================================================
174 // virtual
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() )
182 return aRet;
184 // Try to use requested interface from aggregated storage
185 return m_xAggProxy->queryAggregation( aType );
188 //=========================================================================
189 // virtual
190 void SAL_CALL Storage::acquire()
191 throw ()
193 osl_incrementInterlockedCount( &m_refCount );
196 //=========================================================================
197 // virtual
198 void SAL_CALL Storage::release()
199 throw ()
201 if ( osl_decrementInterlockedCount( &m_refCount ) == 0 )
203 m_xFactory->releaseElement( this );
204 delete this;
208 //=========================================================================
210 // lang::XTypeProvider
212 //=========================================================================
214 // virtual
215 uno::Sequence< uno::Type > SAL_CALL Storage::getTypes()
216 throw ( uno::RuntimeException )
218 return m_xWrappedTypeProv->getTypes();
221 //=========================================================================
222 // virtual
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 //=========================================================================
234 // virtual
235 void SAL_CALL Storage::dispose()
236 throw ( uno::RuntimeException )
238 m_xWrappedStorage->dispose();
241 //=========================================================================
242 // virtual
243 void SAL_CALL Storage::addEventListener(
244 const uno::Reference< lang::XEventListener >& xListener )
245 throw ( uno::RuntimeException )
247 m_xWrappedStorage->addEventListener( xListener );
249 //=========================================================================
250 // virtual
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 //=========================================================================
264 // virtual
265 uno::Type SAL_CALL Storage::getElementType()
266 throw ( uno::RuntimeException )
268 return m_xWrappedStorage->getElementType();
271 //=========================================================================
272 // virtual
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 //=========================================================================
285 // virtual
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 //=========================================================================
295 // virtual
296 uno::Sequence< ::rtl::OUString > SAL_CALL Storage::getElementNames()
297 throw ( uno::RuntimeException )
299 return m_xWrappedStorage->getElementNames();
302 //=========================================================================
303 // virtual
304 ::sal_Bool SAL_CALL Storage::hasByName( const ::rtl::OUString& aName )
305 throw ( uno::RuntimeException )
307 return m_xWrappedStorage->hasByName( aName );
310 //=========================================================================
312 // embed::XStorage
314 //=========================================================================
316 // virtual
317 void SAL_CALL Storage::copyToStorage(
318 const uno::Reference< embed::XStorage >& xDest )
319 throw ( embed::InvalidStorageException,
320 lang::IllegalArgumentException,
321 io::IOException,
322 embed::StorageWrappedTargetException,
323 uno::RuntimeException )
325 m_xWrappedStorage->copyToStorage( xDest );
328 //=========================================================================
329 // virtual
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,
335 io::IOException,
336 embed::StorageWrappedTargetException,
337 uno::RuntimeException )
339 return m_xWrappedStorage->openStreamElement( aStreamName, nOpenMode );
342 //=========================================================================
343 // virtual
344 uno::Reference< io::XStream > SAL_CALL Storage::openEncryptedStreamElement(
345 const ::rtl::OUString& aStreamName,
346 sal_Int32 nOpenMode,
347 const ::rtl::OUString& aPassword )
348 throw ( embed::InvalidStorageException,
349 lang::IllegalArgumentException,
350 packages::NoEncryptionException,
351 packages::WrongPasswordException,
352 io::IOException,
353 embed::StorageWrappedTargetException,
354 uno::RuntimeException )
356 return m_xWrappedStorage->openEncryptedStreamElement(
357 aStreamName, nOpenMode, aPassword );
360 //=========================================================================
361 // virtual
362 uno::Reference< embed::XStorage > SAL_CALL Storage::openStorageElement(
363 const ::rtl::OUString& aStorName, sal_Int32 nOpenMode )
364 throw ( embed::InvalidStorageException,
365 lang::IllegalArgumentException,
366 io::IOException,
367 embed::StorageWrappedTargetException,
368 uno::RuntimeException )
370 return m_xWrappedStorage->openStorageElement( aStorName, nOpenMode );
373 //=========================================================================
374 // virtual
375 uno::Reference< io::XStream > SAL_CALL Storage::cloneStreamElement(
376 const ::rtl::OUString& aStreamName )
377 throw ( embed::InvalidStorageException,
378 lang::IllegalArgumentException,
379 packages::WrongPasswordException,
380 io::IOException,
381 embed::StorageWrappedTargetException,
382 uno::RuntimeException )
384 return m_xWrappedStorage->cloneStreamElement( aStreamName );
387 //=========================================================================
388 // virtual
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,
396 io::IOException,
397 embed::StorageWrappedTargetException,
398 uno::RuntimeException )
400 return m_xWrappedStorage->cloneEncryptedStreamElement( aStreamName,
401 aPassword );
404 //=========================================================================
405 // virtual
406 void SAL_CALL Storage::copyLastCommitTo(
407 const uno::Reference< embed::XStorage >& xTargetStorage )
408 throw ( embed::InvalidStorageException,
409 lang::IllegalArgumentException,
410 io::IOException,
411 embed::StorageWrappedTargetException,
412 uno::RuntimeException)
414 m_xWrappedStorage->copyLastCommitTo( xTargetStorage );
417 //=========================================================================
418 // virtual
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,
424 io::IOException,
425 embed::StorageWrappedTargetException,
426 uno::RuntimeException)
428 m_xWrappedStorage->copyStorageElementLastCommitTo( aStorName, xTargetStorage );
431 //=========================================================================
432 // virtual
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 //=========================================================================
444 // virtual
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 //=========================================================================
456 // virtual
457 void SAL_CALL Storage::removeElement( const ::rtl::OUString& aElementName )
458 throw ( embed::InvalidStorageException,
459 lang::IllegalArgumentException,
460 container::NoSuchElementException,
461 io::IOException,
462 embed::StorageWrappedTargetException,
463 uno::RuntimeException )
465 m_xWrappedStorage->removeElement( aElementName );
468 //=========================================================================
469 // virtual
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,
476 io::IOException,
477 embed::StorageWrappedTargetException,
478 uno::RuntimeException )
480 m_xWrappedStorage->renameElement( aEleName, aNewName );
483 //=========================================================================
484 // virtual
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,
493 io::IOException,
494 embed::StorageWrappedTargetException,
495 uno::RuntimeException )
497 m_xWrappedStorage->copyElementTo( aElementName, xDest, aNewName );
500 //=========================================================================
501 // virtual
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,
510 io::IOException,
511 embed::StorageWrappedTargetException,
512 uno::RuntimeException )
514 m_xWrappedStorage->moveElementTo( aElementName, xDest, rNewName );
517 //=========================================================================
519 // embed::XTransactedObject
521 //=========================================================================
523 // virtual
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() )
548 xParentTA->commit();
554 //=========================================================================
555 // virtual
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() )
577 xParentTA->revert();
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" ) ) ),
617 uno::UNO_QUERY );
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 //=========================================================================
649 // virtual
650 OutputStream::~OutputStream()
652 if ( m_xAggProxy.is() )
653 m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() );
656 //=========================================================================
658 // uno::XInterface
660 //=========================================================================
662 // virtual
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() )
669 return aRet;
671 if ( m_xAggProxy.is() )
672 return m_xAggProxy->queryAggregation( aType );
673 else
674 return uno::Any();
677 //=========================================================================
679 // lang::XTypeProvider
681 //=========================================================================
683 // virtual
684 uno::Sequence< uno::Type > SAL_CALL OutputStream::getTypes()
685 throw ( uno::RuntimeException )
687 return m_xWrappedTypeProv->getTypes();
690 //=========================================================================
691 // virtual
692 uno::Sequence< sal_Int8 > SAL_CALL OutputStream::getImplementationId()
693 throw ( uno::RuntimeException )
695 return m_xWrappedTypeProv->getImplementationId();
698 //=========================================================================
700 // io::XOutputStream
702 //=========================================================================
704 // virtual
705 void SAL_CALL
706 OutputStream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
707 throw ( io::NotConnectedException,
708 io::BufferSizeExceededException,
709 io::IOException,
710 uno::RuntimeException )
712 m_xWrappedStream->writeBytes( aData );
715 //=========================================================================
716 // virtual
717 void SAL_CALL
718 OutputStream::flush()
719 throw ( io::NotConnectedException,
720 io::BufferSizeExceededException,
721 io::IOException,
722 uno::RuntimeException )
724 m_xWrappedStream->flush();
727 //=========================================================================
728 // virtual
729 void SAL_CALL
730 OutputStream::closeOutput( )
731 throw ( io::NotConnectedException,
732 io::BufferSizeExceededException,
733 io::IOException,
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 //=========================================================================
745 // lang::XComponent
747 //=========================================================================
749 // virtual
750 void SAL_CALL
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 //=========================================================================
762 // virtual
763 void SAL_CALL
764 OutputStream::addEventListener(
765 const uno::Reference< lang::XEventListener >& xListener )
766 throw ( uno::RuntimeException )
768 m_xWrappedComponent->addEventListener( xListener );
771 //=========================================================================
772 // virtual
773 void SAL_CALL
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 //=========================================================================
789 Stream::Stream(
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" ) ) ),
818 uno::UNO_QUERY );
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 //=========================================================================
850 // virtual
851 Stream::~Stream()
853 if ( m_xAggProxy.is() )
854 m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() );
857 //=========================================================================
859 // uno::XInterface
861 //=========================================================================
863 // virtual
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() )
870 return aRet;
872 if ( m_xAggProxy.is() )
873 return m_xAggProxy->queryAggregation( aType );
874 else
875 return uno::Any();
878 //=========================================================================
880 // lang::XTypeProvider
882 //=========================================================================
884 // virtual
885 uno::Sequence< uno::Type > SAL_CALL Stream::getTypes()
886 throw ( uno::RuntimeException )
888 return m_xWrappedTypeProv->getTypes();
891 //=========================================================================
892 // virtual
893 uno::Sequence< sal_Int8 > SAL_CALL Stream::getImplementationId()
894 throw ( uno::RuntimeException )
896 return m_xWrappedTypeProv->getImplementationId();
899 //=========================================================================
901 // io::XStream.
903 //=========================================================================
905 // virtual
906 uno::Reference< io::XInputStream > SAL_CALL Stream::getInputStream()
907 throw( uno::RuntimeException )
909 return uno::Reference< io::XInputStream >( this );
912 //=========================================================================
913 // virtual
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 //=========================================================================
926 // virtual
927 void SAL_CALL Stream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
928 throw( io::NotConnectedException,
929 io::BufferSizeExceededException,
930 io::IOException,
931 uno::RuntimeException )
933 if ( m_xWrappedOutputStream.is() )
935 m_xWrappedOutputStream->writeBytes( aData );
936 commitChanges();
940 //=========================================================================
941 // virtual
942 void SAL_CALL Stream::flush()
943 throw( io::NotConnectedException,
944 io::BufferSizeExceededException,
945 io::IOException,
946 uno::RuntimeException )
948 if ( m_xWrappedOutputStream.is() )
950 m_xWrappedOutputStream->flush();
951 commitChanges();
955 //=========================================================================
956 // virtual
957 void SAL_CALL Stream::closeOutput()
958 throw( io::NotConnectedException,
959 io::IOException,
960 uno::RuntimeException )
962 if ( m_xWrappedOutputStream.is() )
964 m_xWrappedOutputStream->closeOutput();
965 commitChanges();
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 //=========================================================================
975 // io::XTruncate.
977 //=========================================================================
979 // virtual
980 void SAL_CALL Stream::truncate()
981 throw( io::IOException,
982 uno::RuntimeException )
984 if ( m_xWrappedTruncate.is() )
986 m_xWrappedTruncate->truncate();
987 commitChanges();
991 //=========================================================================
993 // io::XInputStream.
995 //=========================================================================
997 // virtual
998 sal_Int32 SAL_CALL Stream::readBytes( uno::Sequence< sal_Int8 >& aData,
999 sal_Int32 nBytesToRead )
1000 throw( io::NotConnectedException,
1001 io::BufferSizeExceededException,
1002 io::IOException,
1003 uno::RuntimeException )
1005 return m_xWrappedInputStream->readBytes( aData, nBytesToRead );
1008 //=========================================================================
1009 // virtual
1010 sal_Int32 SAL_CALL Stream::readSomeBytes( uno::Sequence< sal_Int8 >& aData,
1011 sal_Int32 nMaxBytesToRead )
1012 throw( io::NotConnectedException,
1013 io::BufferSizeExceededException,
1014 io::IOException,
1015 uno::RuntimeException )
1017 return m_xWrappedInputStream->readSomeBytes( aData, nMaxBytesToRead );
1020 //=========================================================================
1021 // virtual
1022 void SAL_CALL Stream::skipBytes( sal_Int32 nBytesToSkip )
1023 throw( io::NotConnectedException,
1024 io::BufferSizeExceededException,
1025 io::IOException,
1026 uno::RuntimeException )
1028 m_xWrappedInputStream->skipBytes( nBytesToSkip );
1031 //=========================================================================
1032 // virtual
1033 sal_Int32 SAL_CALL Stream::available()
1034 throw( io::NotConnectedException,
1035 io::IOException,
1036 uno::RuntimeException )
1038 return m_xWrappedInputStream->available();
1041 //=========================================================================
1042 // virtual
1043 void SAL_CALL Stream::closeInput()
1044 throw( io::NotConnectedException,
1045 io::IOException,
1046 uno::RuntimeException )
1048 m_xWrappedInputStream->closeInput();
1051 //=========================================================================
1053 // lang::XComponent
1055 //=========================================================================
1057 // virtual
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 //=========================================================================
1069 // virtual
1070 void SAL_CALL Stream::addEventListener(
1071 const uno::Reference< lang::XEventListener >& xListener )
1072 throw ( uno::RuntimeException )
1074 m_xWrappedComponent->addEventListener( xListener );
1077 //=========================================================================
1078 // virtual
1079 void SAL_CALL Stream::removeEventListener(
1080 const uno::Reference< lang::XEventListener >& aListener )
1081 throw ( uno::RuntimeException )
1083 m_xWrappedComponent->removeEventListener( aListener );
1086 //=========================================================================
1088 // Non-UNO
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(); // @@@