1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: otransactedfilestream.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
33 #include <osl/diagnose.h>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
36 #include <com/sun/star/embed/UseBackupException.hpp>
38 #include <comphelper/otransactedfilestream.hxx>
39 #include <comphelper/storagehelper.hxx>
40 #include <cppuhelper/implbase1.hxx>
42 using namespace ::com::sun::star
;
47 // ========================================================================
48 class OTransactionHelper
: public ::cppu::WeakImplHelper1
< embed::XTransactedObject
>
50 OTruncatedTransactedFileStream
* m_pFileStream
;
51 uno::Reference
< io::XStream
> m_xStreamHolder
;
54 OTransactionHelper( OTruncatedTransactedFileStream
* pStream
)
55 : m_pFileStream( pStream
)
57 m_xStreamHolder
= static_cast< io::XStream
* >( pStream
);
58 if ( !m_xStreamHolder
.is() )
59 throw uno::RuntimeException();
62 virtual void SAL_CALL
commit( ) throw (io::IOException
, lang::WrappedTargetException
, uno::RuntimeException
);
63 virtual void SAL_CALL
revert( ) throw (io::IOException
, lang::WrappedTargetException
, uno::RuntimeException
);
66 // ------------------------------------------------------------------------
67 void SAL_CALL
OTransactionHelper::commit( ) throw (io::IOException
, lang::WrappedTargetException
, uno::RuntimeException
)
69 m_pFileStream
->Commit_Impl();
72 // ------------------------------------------------------------------------
73 void SAL_CALL
OTransactionHelper::revert( ) throw (io::IOException
, lang::WrappedTargetException
, uno::RuntimeException
)
75 m_pFileStream
->Revert_Impl();
78 // ========================================================================
79 struct TTFileStreamData_Impl
81 uno::Reference
< ucb::XSimpleFileAccess
> m_xFileAccess
;
83 ::rtl::OUString m_aURL
;
85 // the streams below are not visible from outside so there is no need to remember position
87 // original stream related members
88 uno::Reference
< io::XStream
> m_xOrigStream
;
89 uno::Reference
< io::XTruncate
> m_xOrigTruncate
;
90 uno::Reference
< io::XSeekable
> m_xOrigSeekable
;
91 uno::Reference
< io::XInputStream
> m_xOrigInStream
;
92 uno::Reference
< io::XOutputStream
> m_xOrigOutStream
;
94 // temporary stream related members
95 uno::Reference
< io::XStream
> m_xTempStream
;
96 uno::Reference
< io::XTruncate
> m_xTempTruncate
;
97 uno::Reference
< io::XSeekable
> m_xTempSeekable
;
98 uno::Reference
< io::XInputStream
> m_xTempInStream
;
99 uno::Reference
< io::XOutputStream
> m_xTempOutStream
;
104 sal_Bool m_bTransacted
;
107 TTFileStreamData_Impl(
108 const uno::Reference
< ucb::XSimpleFileAccess
>& xFileAccess
,
110 const ::rtl::OUString
& aURL
,
111 const uno::Reference
< io::XStream
>& xOrigStream
,
112 const uno::Reference
< io::XTruncate
>& xOrigTruncate
,
113 const uno::Reference
< io::XSeekable
>& xOrigSeekable
,
114 const uno::Reference
< io::XInputStream
>& xOrigInStream
,
115 const uno::Reference
< io::XOutputStream
>& xOrigOutStream
,
116 const uno::Reference
< io::XStream
>& xTempStream
,
117 const uno::Reference
< io::XTruncate
>& xTempTruncate
,
118 const uno::Reference
< io::XSeekable
>& xTempSeekable
,
119 const uno::Reference
< io::XInputStream
>& xTempInStream
,
120 const uno::Reference
< io::XOutputStream
>& xTempOutStream
)
121 : m_xFileAccess( xFileAccess
)
122 , m_bDelete( bDelete
)
124 , m_xOrigStream( xOrigStream
)
125 , m_xOrigTruncate( xOrigTruncate
)
126 , m_xOrigSeekable( xOrigSeekable
)
127 , m_xOrigInStream( xOrigInStream
)
128 , m_xOrigOutStream( xOrigOutStream
)
129 , m_xTempStream( xTempStream
)
130 , m_xTempTruncate( xTempTruncate
)
131 , m_xTempSeekable( xTempSeekable
)
132 , m_xTempInStream( xTempInStream
)
133 , m_xTempOutStream( xTempOutStream
)
134 , m_bInOpen( sal_False
)
135 , m_bOutOpen( sal_False
)
136 , m_bTransacted( sal_True
)
141 m_bDelete
= sal_False
;
142 m_bTransacted
= sal_False
;
143 m_xTempStream
= uno::Reference
< io::XStream
>();
144 m_xTempTruncate
= uno::Reference
< io::XTruncate
>();
145 m_xTempSeekable
= uno::Reference
< io::XSeekable
>();
146 m_xTempInStream
= uno::Reference
< io::XInputStream
>();
147 m_xTempOutStream
= uno::Reference
< io::XOutputStream
>();
152 m_bDelete
= sal_False
;
153 m_bTransacted
= sal_False
;
155 m_xOrigStream
= m_xTempStream
;
156 m_xTempStream
= uno::Reference
< io::XStream
>();
158 m_xOrigTruncate
= m_xTempTruncate
;
159 m_xTempTruncate
= uno::Reference
< io::XTruncate
>();
161 m_xOrigSeekable
= m_xTempSeekable
;
162 m_xTempSeekable
= uno::Reference
< io::XSeekable
>();
164 m_xOrigInStream
= m_xTempInStream
;
165 m_xTempInStream
= uno::Reference
< io::XInputStream
>();
167 m_xOrigOutStream
= m_xTempOutStream
;
168 m_xTempOutStream
= uno::Reference
< io::XOutputStream
>();
172 // ========================================================================
173 // ------------------------------------------------------------------------
174 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
175 const ::rtl::OUString
& aURL
,
176 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
)
177 : m_pStreamData( NULL
)
179 uno::Reference
< ucb::XSimpleFileAccess
> xSimpleFileAccess(
180 xFactory
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
181 uno::UNO_QUERY_THROW
);
183 CommonInit_Impl( aURL
, xSimpleFileAccess
, xFactory
, sal_False
);
186 // ------------------------------------------------------------------------
187 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
188 const ::rtl::OUString
& aURL
,
189 const uno::Reference
< ucb::XSimpleFileAccess
>& xFileAccess
,
190 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
)
191 : m_pStreamData( NULL
)
193 CommonInit_Impl( aURL
, xFileAccess
, xFactory
, sal_False
);
196 // ------------------------------------------------------------------------
197 OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
198 const ::rtl::OUString
& aURL
,
199 const uno::Reference
< ucb::XSimpleFileAccess
>& xFileAccess
,
200 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
201 sal_Bool bDeleteIfNotCommited
)
202 : m_pStreamData( NULL
)
204 CommonInit_Impl( aURL
, xFileAccess
, xFactory
, sal_True
);
206 m_pStreamData
->m_bDelete
= bDeleteIfNotCommited
;
209 // ------------------------------------------------------------------------
210 OTruncatedTransactedFileStream::~OTruncatedTransactedFileStream()
215 // ------------------------------------------------------------------------
216 void OTruncatedTransactedFileStream::CloseAll_Impl()
218 ::osl::MutexGuard
aGuard( m_aMutex
);
222 sal_Bool bDelete
= m_pStreamData
->m_bDelete
;
223 ::rtl::OUString aURL
= m_pStreamData
->m_aURL
;
224 uno::Reference
< ucb::XSimpleFileAccess
> xFileAccess
= m_pStreamData
->m_xFileAccess
;
226 delete m_pStreamData
;
227 m_pStreamData
= NULL
;
229 if ( bDelete
&& xFileAccess
.is() && aURL
.getLength() )
234 xFileAccess
->kill( aURL
);
235 } catch( uno::Exception
& )
237 OSL_ENSURE( sal_False
, "Could not remove the file!" );
243 // ------------------------------------------------------------------------
244 void OTruncatedTransactedFileStream::CommonInit_Impl(
245 const ::rtl::OUString
& aURL
,
246 const uno::Reference
< ucb::XSimpleFileAccess
>& xFileAccess
,
247 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
248 sal_Bool bDeleteOptionIsProvided
)
250 sal_Bool bDelete
= sal_False
;
251 if ( !bDeleteOptionIsProvided
)
252 bDelete
= !xFileAccess
->exists( aURL
);
254 uno::Reference
< io::XStream
> xOrigStream
= xFileAccess
->openFileReadWrite( aURL
);
255 uno::Reference
< io::XTruncate
> xOrigTruncate( xOrigStream
, uno::UNO_QUERY_THROW
);
256 uno::Reference
< io::XSeekable
> xOrigSeekable( xOrigStream
, uno::UNO_QUERY_THROW
);
257 uno::Reference
< io::XInputStream
> xOrigInStream
= xOrigStream
->getInputStream();
258 uno::Reference
< io::XOutputStream
> xOrigOutStream
= xOrigStream
->getOutputStream();
259 if ( !xOrigInStream
.is() || !xOrigOutStream
.is() )
260 throw uno::RuntimeException();
262 // temporary stream related members
263 uno::Reference
< io::XStream
> xTempStream( xFactory
->createInstance(
264 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
265 uno::UNO_QUERY_THROW
);
266 uno::Reference
< io::XTruncate
> xTempTruncate( xTempStream
, uno::UNO_QUERY_THROW
);
267 uno::Reference
< io::XSeekable
> xTempSeekable( xTempStream
, uno::UNO_QUERY_THROW
);
268 uno::Reference
< io::XInputStream
> xTempInStream
= xTempStream
->getInputStream();
269 uno::Reference
< io::XOutputStream
> xTempOutStream
= xTempStream
->getOutputStream();
270 if ( !xTempInStream
.is() || !xTempOutStream
.is() )
271 throw uno::RuntimeException();
273 m_pStreamData
= new TTFileStreamData_Impl( xFileAccess
, bDelete
, aURL
,
274 xOrigStream
, xOrigTruncate
, xOrigSeekable
, xOrigInStream
, xOrigOutStream
,
275 xTempStream
, xTempTruncate
, xTempSeekable
, xTempInStream
, xTempOutStream
);
278 // ------------------------------------------------------------------------
279 void OTruncatedTransactedFileStream::Commit_Impl()
281 ::osl::MutexGuard
aGuard( m_aMutex
);
283 if ( !m_pStreamData
)
284 throw io::NotConnectedException();
286 if ( m_pStreamData
->m_bTransacted
)
288 sal_Int64 nPos
= m_pStreamData
->m_xTempSeekable
->getPosition();
289 m_pStreamData
->m_xTempSeekable
->seek( 0 );
291 // after the following step fails the information might be lost, throw an exception with URL of temporary file
294 m_pStreamData
->m_xOrigTruncate
->truncate();
295 OStorageHelper::CopyInputToOutput( m_pStreamData
->m_xTempInStream
, m_pStreamData
->m_xOrigOutStream
);
296 m_pStreamData
->m_xOrigOutStream
->flush();
298 // in case the stream is based on a file it will implement the following interface
299 // the call should be used to be sure that the contents are written to the file system
300 uno::Reference
< io::XAsyncOutputMonitor
> asyncOutputMonitor( m_pStreamData
->m_xOrigOutStream
, uno::UNO_QUERY
);
301 if ( asyncOutputMonitor
.is() )
302 asyncOutputMonitor
->waitForCompletion();
304 catch( uno::Exception
& )
306 ::rtl::OUString aTempURL
;
308 uno::Reference
< beans::XPropertySet
> xTempFile( m_pStreamData
->m_xTempStream
, uno::UNO_QUERY_THROW
);
309 uno::Any aUrl
= xTempFile
->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
311 xTempFile
->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),
312 uno::makeAny( sal_False
) );
314 m_pStreamData
->m_xTempSeekable
->seek( nPos
);
316 catch( uno::Exception
& )
318 OSL_ENSURE( sal_False
, "These calls are pretty simple, they should not fail!\n" );
321 m_pStreamData
->FreeOriginal();
323 ::rtl::OUString
aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( "Writing file failed!" ) );
324 embed::UseBackupException
aException( aErrTxt
, uno::Reference
< uno::XInterface
>(), aTempURL
);
325 throw lang::WrappedTargetException( aErrTxt
,
326 static_cast < OWeakObject
* > ( this ),
327 uno::makeAny ( aException
) );
330 m_pStreamData
->m_xOrigSeekable
->seek( nPos
);
331 m_pStreamData
->NoTransaction();
334 throw io::NotConnectedException();
337 // ------------------------------------------------------------------------
338 void OTruncatedTransactedFileStream::Revert_Impl()
340 ::osl::MutexGuard
aGuard( m_aMutex
);
342 if ( !m_pStreamData
)
343 throw io::NotConnectedException();
345 if ( m_pStreamData
->m_bTransacted
)
346 m_pStreamData
->m_xTempTruncate
->truncate();
348 throw io::NotConnectedException();
351 // com::sun::star::io::XStream
352 // ------------------------------------------------------------------------
353 uno::Reference
< io::XInputStream
> SAL_CALL
OTruncatedTransactedFileStream::getInputStream( )
354 throw (uno::RuntimeException
)
356 ::osl::MutexGuard
aGuard( m_aMutex
);
359 m_pStreamData
->m_bInOpen
= sal_True
;
360 return static_cast< io::XInputStream
* >( this );
364 // ------------------------------------------------------------------------
365 uno::Reference
< io::XOutputStream
> SAL_CALL
OTruncatedTransactedFileStream::getOutputStream( )
366 throw (uno::RuntimeException
)
368 ::osl::MutexGuard
aGuard( m_aMutex
);
371 m_pStreamData
->m_bOutOpen
= sal_True
;
372 return static_cast< io::XOutputStream
* >( this );
377 // com::sun::star::io::XInputStream
378 // ------------------------------------------------------------------------
379 ::sal_Int32 SAL_CALL
OTruncatedTransactedFileStream::readBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nBytesToRead
)
380 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
382 ::osl::MutexGuard
aGuard( m_aMutex
);
384 if ( !m_pStreamData
)
385 throw io::NotConnectedException();
387 if ( m_pStreamData
->m_bTransacted
)
389 // temporary stream data should be provided
390 if ( !m_pStreamData
->m_xTempInStream
.is() )
391 throw uno::RuntimeException();
393 return m_pStreamData
->m_xTempInStream
->readBytes( aData
, nBytesToRead
);
397 // the original stream data should be provided
398 if ( !m_pStreamData
->m_xOrigInStream
.is() )
399 throw uno::RuntimeException();
401 return m_pStreamData
->m_xOrigInStream
->readBytes( aData
, nBytesToRead
);
406 // ------------------------------------------------------------------------
407 ::sal_Int32 SAL_CALL
OTruncatedTransactedFileStream::readSomeBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nMaxBytesToRead
)
408 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
410 ::osl::MutexGuard
aGuard( m_aMutex
);
412 if ( !m_pStreamData
)
413 throw io::NotConnectedException();
415 if ( m_pStreamData
->m_bTransacted
)
417 // temporary stream data should be provided
418 if ( !m_pStreamData
->m_xTempInStream
.is() )
419 throw uno::RuntimeException();
421 return m_pStreamData
->m_xTempInStream
->readSomeBytes( aData
, nMaxBytesToRead
);
425 // the original stream data should be provided
426 if ( !m_pStreamData
->m_xOrigInStream
.is() )
427 throw uno::RuntimeException();
429 return m_pStreamData
->m_xOrigInStream
->readSomeBytes( aData
, nMaxBytesToRead
);
433 // ------------------------------------------------------------------------
434 void SAL_CALL
OTruncatedTransactedFileStream::skipBytes( ::sal_Int32 nBytesToSkip
)
435 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
437 ::osl::MutexGuard
aGuard( m_aMutex
);
439 if ( !m_pStreamData
)
440 throw io::NotConnectedException();
442 if ( m_pStreamData
->m_bTransacted
)
444 // temporary stream data should be provided
445 if ( !m_pStreamData
->m_xTempInStream
.is() )
446 throw uno::RuntimeException();
448 m_pStreamData
->m_xTempInStream
->skipBytes( nBytesToSkip
);
452 // the original stream data should be provided
453 if ( !m_pStreamData
->m_xOrigInStream
.is() )
454 throw uno::RuntimeException();
456 m_pStreamData
->m_xOrigInStream
->skipBytes( nBytesToSkip
);
461 // ------------------------------------------------------------------------
462 ::sal_Int32 SAL_CALL
OTruncatedTransactedFileStream::available( )
463 throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
465 ::osl::MutexGuard
aGuard( m_aMutex
);
467 if ( !m_pStreamData
)
468 throw io::NotConnectedException();
470 if ( m_pStreamData
->m_bTransacted
)
472 // temporary stream data should be provided
473 if ( !m_pStreamData
->m_xTempInStream
.is() )
474 throw uno::RuntimeException();
476 return m_pStreamData
->m_xTempInStream
->available();
480 // the original stream data should be provided
481 if ( !m_pStreamData
->m_xOrigInStream
.is() )
482 throw uno::RuntimeException();
484 return m_pStreamData
->m_xOrigInStream
->available();
489 // ------------------------------------------------------------------------
490 void SAL_CALL
OTruncatedTransactedFileStream::closeInput()
491 throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
493 ::osl::MutexGuard
aGuard( m_aMutex
);
495 if ( !m_pStreamData
)
496 throw io::NotConnectedException();
498 m_pStreamData
->m_bInOpen
= sal_False
;
499 if ( !m_pStreamData
->m_bOutOpen
)
505 // com::sun::star::io::XOutputStream
506 // ------------------------------------------------------------------------
507 void SAL_CALL
OTruncatedTransactedFileStream::writeBytes( const uno::Sequence
< ::sal_Int8
>& aData
)
508 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
510 ::osl::MutexGuard
aGuard( m_aMutex
);
512 if ( !m_pStreamData
)
513 throw io::NotConnectedException();
515 if ( m_pStreamData
->m_bTransacted
)
517 // temporary stream data should be provided
518 if ( !m_pStreamData
->m_xTempOutStream
.is() )
519 throw uno::RuntimeException();
521 m_pStreamData
->m_xTempOutStream
->writeBytes( aData
);
525 // the original stream data should be provided
526 if ( !m_pStreamData
->m_xOrigOutStream
.is() )
527 throw uno::RuntimeException();
529 m_pStreamData
->m_xOrigOutStream
->writeBytes( aData
);
534 // ------------------------------------------------------------------------
535 void SAL_CALL
OTruncatedTransactedFileStream::flush( )
536 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
538 ::osl::MutexGuard
aGuard( m_aMutex
);
540 if ( !m_pStreamData
)
542 OSL_ENSURE( sal_False
, "flush() call on closed stream!\n" );
544 // in future throw exception, for now some code might call flush() on closed stream
545 // since file ucp implementation allows it
546 // throw io::NotConnectedException();
549 if ( m_pStreamData
->m_bTransacted
)
551 // temporary stream data should be provided
552 if ( !m_pStreamData
->m_xTempOutStream
.is() )
553 throw uno::RuntimeException();
555 m_pStreamData
->m_xTempOutStream
->flush();
559 // the original stream data should be provided
560 if ( !m_pStreamData
->m_xOrigOutStream
.is() )
561 throw uno::RuntimeException();
563 m_pStreamData
->m_xOrigOutStream
->flush();
568 // ------------------------------------------------------------------------
569 void SAL_CALL
OTruncatedTransactedFileStream::closeOutput( )
570 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
572 ::osl::MutexGuard
aGuard( m_aMutex
);
574 if ( !m_pStreamData
)
575 throw io::NotConnectedException();
577 m_pStreamData
->m_bOutOpen
= sal_False
;
578 if ( !m_pStreamData
->m_bInOpen
)
584 // com::sun::star::io::XTruncate
585 // ------------------------------------------------------------------------
586 void SAL_CALL
OTruncatedTransactedFileStream::truncate( )
587 throw (io::IOException
, uno::RuntimeException
)
589 ::osl::MutexGuard
aGuard( m_aMutex
);
591 if ( !m_pStreamData
)
592 throw io::NotConnectedException();
594 if ( m_pStreamData
->m_bTransacted
)
596 // temporary stream data should be provided
597 if ( !m_pStreamData
->m_xTempTruncate
.is() )
598 throw uno::RuntimeException();
600 m_pStreamData
->m_xTempTruncate
->truncate();
604 // the original stream data should be provided
605 if ( !m_pStreamData
->m_xOrigTruncate
.is() )
606 throw uno::RuntimeException();
608 m_pStreamData
->m_xOrigTruncate
->truncate();
614 // com::sun::star::io::XSeekable
615 // ------------------------------------------------------------------------
616 void SAL_CALL
OTruncatedTransactedFileStream::seek( ::sal_Int64 location
)
617 throw (lang::IllegalArgumentException
, io::IOException
, uno::RuntimeException
)
619 ::osl::MutexGuard
aGuard( m_aMutex
);
621 if ( !m_pStreamData
)
622 throw io::NotConnectedException();
624 if ( m_pStreamData
->m_bTransacted
)
626 // temporary stream data should be provided
627 if ( !m_pStreamData
->m_xTempSeekable
.is() )
628 throw uno::RuntimeException();
630 m_pStreamData
->m_xTempSeekable
->seek( location
);
634 // the original stream data should be provided
635 if ( !m_pStreamData
->m_xOrigSeekable
.is() )
636 throw uno::RuntimeException();
638 m_pStreamData
->m_xOrigSeekable
->seek( location
);
643 // ------------------------------------------------------------------------
644 ::sal_Int64 SAL_CALL
OTruncatedTransactedFileStream::getPosition( )
645 throw (io::IOException
, uno::RuntimeException
)
647 ::osl::MutexGuard
aGuard( m_aMutex
);
649 if ( !m_pStreamData
)
650 throw io::NotConnectedException();
652 if ( m_pStreamData
->m_bTransacted
)
654 // temporary stream data should be provided
655 if ( !m_pStreamData
->m_xTempSeekable
.is() )
656 throw uno::RuntimeException();
658 return m_pStreamData
->m_xTempSeekable
->getPosition();
662 // the original stream data should be provided
663 if ( !m_pStreamData
->m_xOrigSeekable
.is() )
664 throw uno::RuntimeException();
666 return m_pStreamData
->m_xOrigSeekable
->getPosition();
671 // ------------------------------------------------------------------------
672 ::sal_Int64 SAL_CALL
OTruncatedTransactedFileStream::getLength( )
673 throw (io::IOException
, uno::RuntimeException
)
675 ::osl::MutexGuard
aGuard( m_aMutex
);
677 if ( !m_pStreamData
)
678 throw io::NotConnectedException();
680 if ( m_pStreamData
->m_bTransacted
)
682 // temporary stream data should be provided
683 if ( !m_pStreamData
->m_xTempSeekable
.is() )
684 throw uno::RuntimeException();
686 return m_pStreamData
->m_xTempSeekable
->getLength();
690 // the original stream data should be provided
691 if ( !m_pStreamData
->m_xOrigSeekable
.is() )
692 throw uno::RuntimeException();
694 return m_pStreamData
->m_xOrigSeekable
->getLength();
698 // com::sun::star::beans::XPropertySetInfo
699 // ------------------------------------------------------------------------
700 uno::Sequence
< beans::Property
> SAL_CALL
OTruncatedTransactedFileStream::getProperties()
701 throw (uno::RuntimeException
)
703 ::osl::MutexGuard
aGuard( m_aMutex
);
705 uno::Sequence
< beans::Property
> aProps( 1 );
706 aProps
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
707 aProps
[0].Type
= getCppuType( static_cast< uno::Reference
< beans::XPropertySet
>* >( NULL
) );
708 aProps
[0].Attributes
= beans::PropertyAttribute::TRANSIENT
| beans::PropertyAttribute::READONLY
;
714 // ------------------------------------------------------------------------
715 beans::Property SAL_CALL
OTruncatedTransactedFileStream::getPropertyByName( const ::rtl::OUString
& aName
)
716 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
718 ::osl::MutexGuard
aGuard( m_aMutex
);
720 ::rtl::OUString
aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
722 if ( !aName
.equals( aTransactionPropName
) )
723 throw beans::UnknownPropertyException();
725 beans::Property aProp
;
726 aProp
.Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
727 aProp
.Type
= getCppuType( static_cast< uno::Reference
< beans::XPropertySet
>* >( NULL
) );
728 aProp
.Attributes
= beans::PropertyAttribute::TRANSIENT
| beans::PropertyAttribute::READONLY
;
734 // ------------------------------------------------------------------------
735 ::sal_Bool SAL_CALL
OTruncatedTransactedFileStream::hasPropertyByName( const ::rtl::OUString
& Name
)
736 throw (uno::RuntimeException
)
738 ::osl::MutexGuard
aGuard( m_aMutex
);
740 ::rtl::OUString
aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
741 return ( Name
.equals( aTransactionPropName
) );
746 // com::sun::star::beans::XPropertySet
747 // ------------------------------------------------------------------------
748 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
OTruncatedTransactedFileStream::getPropertySetInfo()
749 throw (uno::RuntimeException
)
751 ::osl::MutexGuard
aGuard( m_aMutex
);
753 return static_cast< beans::XPropertySetInfo
* >( this );
757 // ------------------------------------------------------------------------
758 void SAL_CALL
OTruncatedTransactedFileStream::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const uno::Any
& )
759 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
761 ::osl::MutexGuard
aGuard( m_aMutex
);
763 ::rtl::OUString
aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
764 if ( aPropertyName
.equals( aTransactionPropName
) )
765 throw beans::PropertyVetoException();
767 throw beans::UnknownPropertyException();
771 // ------------------------------------------------------------------------
772 uno::Any SAL_CALL
OTruncatedTransactedFileStream::getPropertyValue( const ::rtl::OUString
& PropertyName
)
773 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
775 ::osl::MutexGuard
aGuard( m_aMutex
);
777 if ( !m_pStreamData
)
778 throw io::NotConnectedException();
780 ::rtl::OUString
aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
781 if ( PropertyName
.equals( aTransactionPropName
) )
783 uno::Reference
< embed::XTransactedObject
> xObj
;
784 if ( m_pStreamData
->m_bTransacted
)
785 xObj
= static_cast< embed::XTransactedObject
* >( new OTransactionHelper( this ) );
787 return uno::makeAny( xObj
);
790 throw beans::UnknownPropertyException();
794 // ------------------------------------------------------------------------
795 void SAL_CALL
OTruncatedTransactedFileStream::addPropertyChangeListener( const ::rtl::OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& )
796 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
802 // ------------------------------------------------------------------------
803 void SAL_CALL
OTruncatedTransactedFileStream::removePropertyChangeListener( const ::rtl::OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& )
804 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
810 // ------------------------------------------------------------------------
811 void SAL_CALL
OTruncatedTransactedFileStream::addVetoableChangeListener( const ::rtl::OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& )
812 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
818 // ------------------------------------------------------------------------
819 void SAL_CALL
OTruncatedTransactedFileStream::removeVetoableChangeListener( const ::rtl::OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& )
820 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
826 } // namespace comphelper