merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / streaming / otransactedfilestream.cxx
blob03539a12305b0abf225468f787298aca5e2f3950
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <osl/diagnose.h>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
33 #include <com/sun/star/embed/UseBackupException.hpp>
35 #include <comphelper/otransactedfilestream.hxx>
36 #include <comphelper/storagehelper.hxx>
37 #include <cppuhelper/implbase1.hxx>
39 using namespace ::com::sun::star;
41 namespace comphelper
44 // ========================================================================
45 class OTransactionHelper : public ::cppu::WeakImplHelper1 < embed::XTransactedObject >
47 OTruncatedTransactedFileStream* m_pFileStream;
48 uno::Reference< io::XStream > m_xStreamHolder;
50 public:
51 OTransactionHelper( OTruncatedTransactedFileStream* pStream )
52 : m_pFileStream( pStream )
54 m_xStreamHolder = static_cast< io::XStream* >( pStream );
55 if ( !m_xStreamHolder.is() )
56 throw uno::RuntimeException();
59 virtual void SAL_CALL commit( ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
60 virtual void SAL_CALL revert( ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
63 // ------------------------------------------------------------------------
64 void SAL_CALL OTransactionHelper::commit( ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
66 m_pFileStream->Commit_Impl();
69 // ------------------------------------------------------------------------
70 void SAL_CALL OTransactionHelper::revert( ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
72 m_pFileStream->Revert_Impl();
75 // ========================================================================
76 struct TTFileStreamData_Impl
78 uno::Reference< ucb::XSimpleFileAccess > m_xFileAccess;
79 sal_Bool m_bDelete;
80 ::rtl::OUString m_aURL;
82 // the streams below are not visible from outside so there is no need to remember position
84 // original stream related members
85 uno::Reference< io::XStream > m_xOrigStream;
86 uno::Reference< io::XTruncate > m_xOrigTruncate;
87 uno::Reference< io::XSeekable > m_xOrigSeekable;
88 uno::Reference< io::XInputStream > m_xOrigInStream;
89 uno::Reference< io::XOutputStream > m_xOrigOutStream;
91 // temporary stream related members
92 uno::Reference< io::XStream > m_xTempStream;
93 uno::Reference< io::XTruncate > m_xTempTruncate;
94 uno::Reference< io::XSeekable > m_xTempSeekable;
95 uno::Reference< io::XInputStream > m_xTempInStream;
96 uno::Reference< io::XOutputStream > m_xTempOutStream;
98 sal_Bool m_bInOpen;
99 sal_Bool m_bOutOpen;
101 sal_Bool m_bTransacted;
104 TTFileStreamData_Impl(
105 const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
106 sal_Bool bDelete,
107 const ::rtl::OUString& aURL,
108 const uno::Reference< io::XStream >& xOrigStream,
109 const uno::Reference< io::XTruncate >& xOrigTruncate,
110 const uno::Reference< io::XSeekable >& xOrigSeekable,
111 const uno::Reference< io::XInputStream >& xOrigInStream,
112 const uno::Reference< io::XOutputStream >& xOrigOutStream,
113 const uno::Reference< io::XStream >& xTempStream,
114 const uno::Reference< io::XTruncate >& xTempTruncate,
115 const uno::Reference< io::XSeekable >& xTempSeekable,
116 const uno::Reference< io::XInputStream >& xTempInStream,
117 const uno::Reference< io::XOutputStream >& xTempOutStream )
118 : m_xFileAccess( xFileAccess )
119 , m_bDelete( bDelete )
120 , m_aURL( aURL )
121 , m_xOrigStream( xOrigStream )
122 , m_xOrigTruncate( xOrigTruncate )
123 , m_xOrigSeekable( xOrigSeekable )
124 , m_xOrigInStream( xOrigInStream )
125 , m_xOrigOutStream( xOrigOutStream )
126 , m_xTempStream( xTempStream )
127 , m_xTempTruncate( xTempTruncate )
128 , m_xTempSeekable( xTempSeekable )
129 , m_xTempInStream( xTempInStream )
130 , m_xTempOutStream( xTempOutStream )
131 , m_bInOpen( sal_False )
132 , m_bOutOpen( sal_False )
133 , m_bTransacted( sal_True )
136 void NoTransaction()
138 m_bDelete = sal_False;
139 m_bTransacted = sal_False;
140 m_xTempStream = uno::Reference< io::XStream >();
141 m_xTempTruncate = uno::Reference< io::XTruncate >();
142 m_xTempSeekable = uno::Reference< io::XSeekable >();
143 m_xTempInStream = uno::Reference< io::XInputStream >();
144 m_xTempOutStream = uno::Reference< io::XOutputStream >();
147 void FreeOriginal()
149 m_bDelete = sal_False;
150 m_bTransacted = sal_False;
152 m_xOrigStream = m_xTempStream;
153 m_xTempStream = uno::Reference< io::XStream >();
155 m_xOrigTruncate = m_xTempTruncate;
156 m_xTempTruncate = uno::Reference< io::XTruncate >();
158 m_xOrigSeekable = m_xTempSeekable;
159 m_xTempSeekable = uno::Reference< io::XSeekable >();
161 m_xOrigInStream = m_xTempInStream;
162 m_xTempInStream = uno::Reference< io::XInputStream >();
164 m_xOrigOutStream = m_xTempOutStream;
165 m_xTempOutStream = uno::Reference< io::XOutputStream >();
169 // ========================================================================
170 // ------------------------------------------------------------------------
171 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
172 const ::rtl::OUString& aURL,
173 const uno::Reference< lang::XMultiServiceFactory >& xFactory )
174 : m_pStreamData( NULL )
176 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
177 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
178 uno::UNO_QUERY_THROW );
180 CommonInit_Impl( aURL, xSimpleFileAccess, xFactory, sal_False );
183 // ------------------------------------------------------------------------
184 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
185 const ::rtl::OUString& aURL,
186 const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
187 const uno::Reference< lang::XMultiServiceFactory >& xFactory )
188 : m_pStreamData( NULL )
190 CommonInit_Impl( aURL, xFileAccess, xFactory, sal_False );
193 // ------------------------------------------------------------------------
194 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
195 const ::rtl::OUString& aURL,
196 const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
197 const uno::Reference< lang::XMultiServiceFactory >& xFactory,
198 sal_Bool bDeleteIfNotCommited )
199 : m_pStreamData( NULL )
201 CommonInit_Impl( aURL, xFileAccess, xFactory, sal_True );
202 if ( m_pStreamData )
203 m_pStreamData->m_bDelete = bDeleteIfNotCommited;
206 // ------------------------------------------------------------------------
207 OTruncatedTransactedFileStream::~OTruncatedTransactedFileStream()
209 CloseAll_Impl();
212 // ------------------------------------------------------------------------
213 void OTruncatedTransactedFileStream::CloseAll_Impl()
215 ::osl::MutexGuard aGuard( m_aMutex );
217 if ( m_pStreamData )
219 sal_Bool bDelete = m_pStreamData->m_bDelete;
220 ::rtl::OUString aURL = m_pStreamData->m_aURL;
221 uno::Reference< ucb::XSimpleFileAccess > xFileAccess = m_pStreamData->m_xFileAccess;
223 delete m_pStreamData;
224 m_pStreamData = NULL;
226 if ( bDelete && xFileAccess.is() && aURL.getLength() )
228 // delete the file
231 xFileAccess->kill( aURL );
232 } catch( uno::Exception& )
234 OSL_ENSURE( sal_False, "Could not remove the file!" );
240 // ------------------------------------------------------------------------
241 void OTruncatedTransactedFileStream::CommonInit_Impl(
242 const ::rtl::OUString& aURL,
243 const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
244 const uno::Reference< lang::XMultiServiceFactory >& xFactory,
245 sal_Bool bDeleteOptionIsProvided )
247 sal_Bool bDelete = sal_False;
248 if ( !bDeleteOptionIsProvided )
249 bDelete = !xFileAccess->exists( aURL );
251 uno::Reference< io::XStream > xOrigStream = xFileAccess->openFileReadWrite( aURL );
252 uno::Reference< io::XTruncate > xOrigTruncate( xOrigStream, uno::UNO_QUERY_THROW );
253 uno::Reference< io::XSeekable > xOrigSeekable( xOrigStream, uno::UNO_QUERY_THROW );
254 uno::Reference< io::XInputStream > xOrigInStream = xOrigStream->getInputStream();
255 uno::Reference< io::XOutputStream > xOrigOutStream = xOrigStream->getOutputStream();
256 if ( !xOrigInStream.is() || !xOrigOutStream.is() )
257 throw uno::RuntimeException();
259 // temporary stream related members
260 uno::Reference< io::XStream > xTempStream( xFactory->createInstance(
261 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
262 uno::UNO_QUERY_THROW );
263 uno::Reference< io::XTruncate > xTempTruncate( xTempStream, uno::UNO_QUERY_THROW );
264 uno::Reference< io::XSeekable > xTempSeekable( xTempStream, uno::UNO_QUERY_THROW );
265 uno::Reference< io::XInputStream > xTempInStream = xTempStream->getInputStream();
266 uno::Reference< io::XOutputStream > xTempOutStream = xTempStream->getOutputStream();
267 if ( !xTempInStream.is() || !xTempOutStream.is() )
268 throw uno::RuntimeException();
270 m_pStreamData = new TTFileStreamData_Impl( xFileAccess, bDelete, aURL,
271 xOrigStream, xOrigTruncate, xOrigSeekable, xOrigInStream, xOrigOutStream,
272 xTempStream, xTempTruncate, xTempSeekable, xTempInStream, xTempOutStream );
275 // ------------------------------------------------------------------------
276 void OTruncatedTransactedFileStream::Commit_Impl()
278 ::osl::MutexGuard aGuard( m_aMutex );
280 if ( !m_pStreamData )
281 throw io::NotConnectedException();
283 if ( m_pStreamData->m_bTransacted )
285 sal_Int64 nPos = m_pStreamData->m_xTempSeekable->getPosition();
286 m_pStreamData->m_xTempSeekable->seek( 0 );
288 // after the following step fails the information might be lost, throw an exception with URL of temporary file
291 m_pStreamData->m_xOrigTruncate->truncate();
292 OStorageHelper::CopyInputToOutput( m_pStreamData->m_xTempInStream, m_pStreamData->m_xOrigOutStream );
293 m_pStreamData->m_xOrigOutStream->flush();
295 // in case the stream is based on a file it will implement the following interface
296 // the call should be used to be sure that the contents are written to the file system
297 uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY );
298 if ( asyncOutputMonitor.is() )
299 asyncOutputMonitor->waitForCompletion();
301 catch( uno::Exception& )
303 ::rtl::OUString aTempURL;
304 try {
305 uno::Reference< beans::XPropertySet > xTempFile( m_pStreamData->m_xTempStream, uno::UNO_QUERY_THROW );
306 uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
307 aUrl >>= aTempURL;
308 xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),
309 uno::makeAny( sal_False ) );
311 m_pStreamData->m_xTempSeekable->seek( nPos );
313 catch( uno::Exception& )
315 OSL_ENSURE( sal_False, "These calls are pretty simple, they should not fail!\n" );
318 m_pStreamData->FreeOriginal();
320 ::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( "Writing file failed!" ) );
321 embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), aTempURL );
322 throw lang::WrappedTargetException( aErrTxt,
323 static_cast < OWeakObject * > ( this ),
324 uno::makeAny ( aException ) );
327 m_pStreamData->m_xOrigSeekable->seek( nPos );
328 m_pStreamData->NoTransaction();
330 else
331 throw io::NotConnectedException();
334 // ------------------------------------------------------------------------
335 void OTruncatedTransactedFileStream::Revert_Impl()
337 ::osl::MutexGuard aGuard( m_aMutex );
339 if ( !m_pStreamData )
340 throw io::NotConnectedException();
342 if ( m_pStreamData->m_bTransacted )
343 m_pStreamData->m_xTempTruncate->truncate();
344 else
345 throw io::NotConnectedException();
348 // com::sun::star::io::XStream
349 // ------------------------------------------------------------------------
350 uno::Reference< io::XInputStream > SAL_CALL OTruncatedTransactedFileStream::getInputStream( )
351 throw (uno::RuntimeException)
353 ::osl::MutexGuard aGuard( m_aMutex );
355 if ( m_pStreamData )
356 m_pStreamData->m_bInOpen = sal_True;
357 return static_cast< io::XInputStream* >( this );
361 // ------------------------------------------------------------------------
362 uno::Reference< io::XOutputStream > SAL_CALL OTruncatedTransactedFileStream::getOutputStream( )
363 throw (uno::RuntimeException)
365 ::osl::MutexGuard aGuard( m_aMutex );
367 if ( m_pStreamData )
368 m_pStreamData->m_bOutOpen = sal_True;
369 return static_cast< io::XOutputStream* >( this );
374 // com::sun::star::io::XInputStream
375 // ------------------------------------------------------------------------
376 ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
377 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
379 ::osl::MutexGuard aGuard( m_aMutex );
381 if ( !m_pStreamData )
382 throw io::NotConnectedException();
384 if ( m_pStreamData->m_bTransacted )
386 // temporary stream data should be provided
387 if ( !m_pStreamData->m_xTempInStream.is() )
388 throw uno::RuntimeException();
390 return m_pStreamData->m_xTempInStream->readBytes( aData, nBytesToRead );
392 else
394 // the original stream data should be provided
395 if ( !m_pStreamData->m_xOrigInStream.is() )
396 throw uno::RuntimeException();
398 return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead );
403 // ------------------------------------------------------------------------
404 ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
405 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
407 ::osl::MutexGuard aGuard( m_aMutex );
409 if ( !m_pStreamData )
410 throw io::NotConnectedException();
412 if ( m_pStreamData->m_bTransacted )
414 // temporary stream data should be provided
415 if ( !m_pStreamData->m_xTempInStream.is() )
416 throw uno::RuntimeException();
418 return m_pStreamData->m_xTempInStream->readSomeBytes( aData, nMaxBytesToRead );
420 else
422 // the original stream data should be provided
423 if ( !m_pStreamData->m_xOrigInStream.is() )
424 throw uno::RuntimeException();
426 return m_pStreamData->m_xOrigInStream->readSomeBytes( aData, nMaxBytesToRead );
430 // ------------------------------------------------------------------------
431 void SAL_CALL OTruncatedTransactedFileStream::skipBytes( ::sal_Int32 nBytesToSkip )
432 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
434 ::osl::MutexGuard aGuard( m_aMutex );
436 if ( !m_pStreamData )
437 throw io::NotConnectedException();
439 if ( m_pStreamData->m_bTransacted )
441 // temporary stream data should be provided
442 if ( !m_pStreamData->m_xTempInStream.is() )
443 throw uno::RuntimeException();
445 m_pStreamData->m_xTempInStream->skipBytes( nBytesToSkip );
447 else
449 // the original stream data should be provided
450 if ( !m_pStreamData->m_xOrigInStream.is() )
451 throw uno::RuntimeException();
453 m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip );
458 // ------------------------------------------------------------------------
459 ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::available( )
460 throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
462 ::osl::MutexGuard aGuard( m_aMutex );
464 if ( !m_pStreamData )
465 throw io::NotConnectedException();
467 if ( m_pStreamData->m_bTransacted )
469 // temporary stream data should be provided
470 if ( !m_pStreamData->m_xTempInStream.is() )
471 throw uno::RuntimeException();
473 return m_pStreamData->m_xTempInStream->available();
475 else
477 // the original stream data should be provided
478 if ( !m_pStreamData->m_xOrigInStream.is() )
479 throw uno::RuntimeException();
481 return m_pStreamData->m_xOrigInStream->available();
486 // ------------------------------------------------------------------------
487 void SAL_CALL OTruncatedTransactedFileStream::closeInput()
488 throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
490 ::osl::MutexGuard aGuard( m_aMutex );
492 if ( !m_pStreamData )
493 throw io::NotConnectedException();
495 m_pStreamData->m_bInOpen = sal_False;
496 if ( !m_pStreamData->m_bOutOpen )
497 CloseAll_Impl();
502 // com::sun::star::io::XOutputStream
503 // ------------------------------------------------------------------------
504 void SAL_CALL OTruncatedTransactedFileStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData )
505 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
507 ::osl::MutexGuard aGuard( m_aMutex );
509 if ( !m_pStreamData )
510 throw io::NotConnectedException();
512 if ( m_pStreamData->m_bTransacted )
514 // temporary stream data should be provided
515 if ( !m_pStreamData->m_xTempOutStream.is() )
516 throw uno::RuntimeException();
518 m_pStreamData->m_xTempOutStream->writeBytes( aData );
520 else
522 // the original stream data should be provided
523 if ( !m_pStreamData->m_xOrigOutStream.is() )
524 throw uno::RuntimeException();
526 m_pStreamData->m_xOrigOutStream->writeBytes( aData );
531 // ------------------------------------------------------------------------
532 void SAL_CALL OTruncatedTransactedFileStream::flush( )
533 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
535 ::osl::MutexGuard aGuard( m_aMutex );
537 if ( !m_pStreamData )
539 OSL_ENSURE( sal_False, "flush() call on closed stream!\n" );
540 return;
541 // in future throw exception, for now some code might call flush() on closed stream
542 // since file ucp implementation allows it
543 // throw io::NotConnectedException();
546 if ( m_pStreamData->m_bTransacted )
548 // temporary stream data should be provided
549 if ( !m_pStreamData->m_xTempOutStream.is() )
550 throw uno::RuntimeException();
552 m_pStreamData->m_xTempOutStream->flush();
554 else
556 // the original stream data should be provided
557 if ( !m_pStreamData->m_xOrigOutStream.is() )
558 throw uno::RuntimeException();
560 m_pStreamData->m_xOrigOutStream->flush();
565 // ------------------------------------------------------------------------
566 void SAL_CALL OTruncatedTransactedFileStream::closeOutput( )
567 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
569 ::osl::MutexGuard aGuard( m_aMutex );
571 if ( !m_pStreamData )
572 throw io::NotConnectedException();
574 m_pStreamData->m_bOutOpen = sal_False;
575 if ( !m_pStreamData->m_bInOpen )
576 CloseAll_Impl();
581 // com::sun::star::io::XTruncate
582 // ------------------------------------------------------------------------
583 void SAL_CALL OTruncatedTransactedFileStream::truncate( )
584 throw (io::IOException, uno::RuntimeException)
586 ::osl::MutexGuard aGuard( m_aMutex );
588 if ( !m_pStreamData )
589 throw io::NotConnectedException();
591 if ( m_pStreamData->m_bTransacted )
593 // temporary stream data should be provided
594 if ( !m_pStreamData->m_xTempTruncate.is() )
595 throw uno::RuntimeException();
597 m_pStreamData->m_xTempTruncate->truncate();
599 else
601 // the original stream data should be provided
602 if ( !m_pStreamData->m_xOrigTruncate.is() )
603 throw uno::RuntimeException();
605 m_pStreamData->m_xOrigTruncate->truncate();
611 // com::sun::star::io::XSeekable
612 // ------------------------------------------------------------------------
613 void SAL_CALL OTruncatedTransactedFileStream::seek( ::sal_Int64 location )
614 throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
616 ::osl::MutexGuard aGuard( m_aMutex );
618 if ( !m_pStreamData )
619 throw io::NotConnectedException();
621 if ( m_pStreamData->m_bTransacted )
623 // temporary stream data should be provided
624 if ( !m_pStreamData->m_xTempSeekable.is() )
625 throw uno::RuntimeException();
627 m_pStreamData->m_xTempSeekable->seek( location );
629 else
631 // the original stream data should be provided
632 if ( !m_pStreamData->m_xOrigSeekable.is() )
633 throw uno::RuntimeException();
635 m_pStreamData->m_xOrigSeekable->seek( location );
640 // ------------------------------------------------------------------------
641 ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getPosition( )
642 throw (io::IOException, uno::RuntimeException)
644 ::osl::MutexGuard aGuard( m_aMutex );
646 if ( !m_pStreamData )
647 throw io::NotConnectedException();
649 if ( m_pStreamData->m_bTransacted )
651 // temporary stream data should be provided
652 if ( !m_pStreamData->m_xTempSeekable.is() )
653 throw uno::RuntimeException();
655 return m_pStreamData->m_xTempSeekable->getPosition();
657 else
659 // the original stream data should be provided
660 if ( !m_pStreamData->m_xOrigSeekable.is() )
661 throw uno::RuntimeException();
663 return m_pStreamData->m_xOrigSeekable->getPosition();
668 // ------------------------------------------------------------------------
669 ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getLength( )
670 throw (io::IOException, uno::RuntimeException)
672 ::osl::MutexGuard aGuard( m_aMutex );
674 if ( !m_pStreamData )
675 throw io::NotConnectedException();
677 if ( m_pStreamData->m_bTransacted )
679 // temporary stream data should be provided
680 if ( !m_pStreamData->m_xTempSeekable.is() )
681 throw uno::RuntimeException();
683 return m_pStreamData->m_xTempSeekable->getLength();
685 else
687 // the original stream data should be provided
688 if ( !m_pStreamData->m_xOrigSeekable.is() )
689 throw uno::RuntimeException();
691 return m_pStreamData->m_xOrigSeekable->getLength();
695 // com::sun::star::beans::XPropertySetInfo
696 // ------------------------------------------------------------------------
697 uno::Sequence< beans::Property > SAL_CALL OTruncatedTransactedFileStream::getProperties()
698 throw (uno::RuntimeException)
700 ::osl::MutexGuard aGuard( m_aMutex );
702 uno::Sequence< beans::Property > aProps( 1 );
703 aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
704 aProps[0].Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
705 aProps[0].Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
707 return aProps;
711 // ------------------------------------------------------------------------
712 beans::Property SAL_CALL OTruncatedTransactedFileStream::getPropertyByName( const ::rtl::OUString& aName )
713 throw (beans::UnknownPropertyException, uno::RuntimeException)
715 ::osl::MutexGuard aGuard( m_aMutex );
717 ::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
719 if ( !aName.equals( aTransactionPropName ) )
720 throw beans::UnknownPropertyException();
722 beans::Property aProp;
723 aProp.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
724 aProp.Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
725 aProp.Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
727 return aProp;
731 // ------------------------------------------------------------------------
732 ::sal_Bool SAL_CALL OTruncatedTransactedFileStream::hasPropertyByName( const ::rtl::OUString& Name )
733 throw (uno::RuntimeException)
735 ::osl::MutexGuard aGuard( m_aMutex );
737 ::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
738 return ( Name.equals( aTransactionPropName ) );
743 // com::sun::star::beans::XPropertySet
744 // ------------------------------------------------------------------------
745 uno::Reference< beans::XPropertySetInfo > SAL_CALL OTruncatedTransactedFileStream::getPropertySetInfo()
746 throw (uno::RuntimeException)
748 ::osl::MutexGuard aGuard( m_aMutex );
750 return static_cast< beans::XPropertySetInfo* >( this );
754 // ------------------------------------------------------------------------
755 void SAL_CALL OTruncatedTransactedFileStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& )
756 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
758 ::osl::MutexGuard aGuard( m_aMutex );
760 ::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
761 if ( aPropertyName.equals( aTransactionPropName ) )
762 throw beans::PropertyVetoException();
764 throw beans::UnknownPropertyException();
768 // ------------------------------------------------------------------------
769 uno::Any SAL_CALL OTruncatedTransactedFileStream::getPropertyValue( const ::rtl::OUString& PropertyName )
770 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
772 ::osl::MutexGuard aGuard( m_aMutex );
774 if ( !m_pStreamData )
775 throw io::NotConnectedException();
777 ::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
778 if ( PropertyName.equals( aTransactionPropName ) )
780 uno::Reference< embed::XTransactedObject > xObj;
781 if ( m_pStreamData->m_bTransacted )
782 xObj = static_cast< embed::XTransactedObject* >( new OTransactionHelper( this ) );
784 return uno::makeAny( xObj );
787 throw beans::UnknownPropertyException();
791 // ------------------------------------------------------------------------
792 void SAL_CALL OTruncatedTransactedFileStream::addPropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
793 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
795 // not implemented
799 // ------------------------------------------------------------------------
800 void SAL_CALL OTruncatedTransactedFileStream::removePropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
801 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
803 // not implemented
807 // ------------------------------------------------------------------------
808 void SAL_CALL OTruncatedTransactedFileStream::addVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
809 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
811 // not implemented
815 // ------------------------------------------------------------------------
816 void SAL_CALL OTruncatedTransactedFileStream::removeVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
817 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
819 // not implemented
823 } // namespace comphelper