1dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5dde7d3faSAndrew Rist  * distributed with this work for additional information
6dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10dde7d3faSAndrew Rist  *
11dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12dde7d3faSAndrew Rist  *
13dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18dde7d3faSAndrew Rist  * under the License.
19dde7d3faSAndrew Rist  *
20dde7d3faSAndrew Rist  *************************************************************/
21dde7d3faSAndrew Rist 
22dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #include <osl/diagnose.h>
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
28cdf0e10cSrcweir #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <comphelper/otransactedfilestream.hxx>
32cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
33cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace comphelper
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // ========================================================================
41cdf0e10cSrcweir class OTransactionHelper : public ::cppu::WeakImplHelper1 < embed::XTransactedObject >
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	OTruncatedTransactedFileStream* m_pFileStream;
44cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xStreamHolder;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir public:
OTransactionHelper(OTruncatedTransactedFileStream * pStream)47cdf0e10cSrcweir 	OTransactionHelper( OTruncatedTransactedFileStream* pStream )
48cdf0e10cSrcweir 	: m_pFileStream( pStream )
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		m_xStreamHolder = static_cast< io::XStream* >( pStream );
51cdf0e10cSrcweir 		if ( !m_xStreamHolder.is() )
52cdf0e10cSrcweir 			throw uno::RuntimeException();
53cdf0e10cSrcweir 	}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     virtual void SAL_CALL commit(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
56cdf0e10cSrcweir     virtual void SAL_CALL revert(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // ------------------------------------------------------------------------
commit()60cdf0e10cSrcweir void SAL_CALL OTransactionHelper::commit(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	m_pFileStream->Commit_Impl();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // ------------------------------------------------------------------------
revert()66cdf0e10cSrcweir void SAL_CALL OTransactionHelper::revert(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	m_pFileStream->Revert_Impl();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // ========================================================================
72cdf0e10cSrcweir struct TTFileStreamData_Impl
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	uno::Reference< ucb::XSimpleFileAccess > m_xFileAccess;
75cdf0e10cSrcweir 	sal_Bool m_bDelete;
76cdf0e10cSrcweir 	::rtl::OUString m_aURL;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	// the streams below are not visible from outside so there is no need to remember position
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	// original stream related members
81cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xOrigStream;
82cdf0e10cSrcweir 	uno::Reference< io::XTruncate > m_xOrigTruncate;
83cdf0e10cSrcweir 	uno::Reference< io::XSeekable > m_xOrigSeekable;
84cdf0e10cSrcweir 	uno::Reference< io::XInputStream > m_xOrigInStream;
85cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > m_xOrigOutStream;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	// temporary stream related members
88cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xTempStream;
89cdf0e10cSrcweir 	uno::Reference< io::XTruncate > m_xTempTruncate;
90cdf0e10cSrcweir 	uno::Reference< io::XSeekable > m_xTempSeekable;
91cdf0e10cSrcweir 	uno::Reference< io::XInputStream > m_xTempInStream;
92cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > m_xTempOutStream;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	sal_Bool m_bInOpen;
95cdf0e10cSrcweir 	sal_Bool m_bOutOpen;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	sal_Bool m_bTransacted;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
TTFileStreamData_Implcomphelper::TTFileStreamData_Impl100cdf0e10cSrcweir 	TTFileStreamData_Impl(
101cdf0e10cSrcweir 			const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
102cdf0e10cSrcweir 			sal_Bool bDelete,
103cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
104cdf0e10cSrcweir 			const uno::Reference< io::XStream >& xOrigStream,
105cdf0e10cSrcweir 			const uno::Reference< io::XTruncate >& xOrigTruncate,
106cdf0e10cSrcweir 			const uno::Reference< io::XSeekable >& xOrigSeekable,
107cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& xOrigInStream,
108cdf0e10cSrcweir 			const uno::Reference< io::XOutputStream >& xOrigOutStream,
109cdf0e10cSrcweir 			const uno::Reference< io::XStream >& xTempStream,
110cdf0e10cSrcweir 			const uno::Reference< io::XTruncate >& xTempTruncate,
111cdf0e10cSrcweir 			const uno::Reference< io::XSeekable >& xTempSeekable,
112cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& xTempInStream,
113cdf0e10cSrcweir 			const uno::Reference< io::XOutputStream >& xTempOutStream )
114cdf0e10cSrcweir 	: m_xFileAccess( xFileAccess )
115cdf0e10cSrcweir 	, m_bDelete( bDelete )
116cdf0e10cSrcweir 	, m_aURL( aURL )
117cdf0e10cSrcweir 	, m_xOrigStream( xOrigStream )
118cdf0e10cSrcweir 	, m_xOrigTruncate( xOrigTruncate )
119cdf0e10cSrcweir 	, m_xOrigSeekable( xOrigSeekable )
120cdf0e10cSrcweir 	, m_xOrigInStream( xOrigInStream )
121cdf0e10cSrcweir 	, m_xOrigOutStream( xOrigOutStream )
122cdf0e10cSrcweir 	, m_xTempStream( xTempStream )
123cdf0e10cSrcweir 	, m_xTempTruncate( xTempTruncate )
124cdf0e10cSrcweir 	, m_xTempSeekable( xTempSeekable )
125cdf0e10cSrcweir 	, m_xTempInStream( xTempInStream )
126cdf0e10cSrcweir 	, m_xTempOutStream( xTempOutStream )
127cdf0e10cSrcweir 	, m_bInOpen( sal_False )
128cdf0e10cSrcweir 	, m_bOutOpen( sal_False )
129cdf0e10cSrcweir 	, m_bTransacted( sal_True )
130cdf0e10cSrcweir 	{}
131cdf0e10cSrcweir 
NoTransactioncomphelper::TTFileStreamData_Impl132cdf0e10cSrcweir 	void NoTransaction()
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		m_bDelete = sal_False;
135cdf0e10cSrcweir 		m_bTransacted = sal_False;
136cdf0e10cSrcweir 		m_xTempStream = uno::Reference< io::XStream >();
137cdf0e10cSrcweir 		m_xTempTruncate = uno::Reference< io::XTruncate >();
138cdf0e10cSrcweir 		m_xTempSeekable = uno::Reference< io::XSeekable >();
139cdf0e10cSrcweir 		m_xTempInStream = uno::Reference< io::XInputStream >();
140cdf0e10cSrcweir 		m_xTempOutStream = uno::Reference< io::XOutputStream >();
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
FreeOriginalcomphelper::TTFileStreamData_Impl143cdf0e10cSrcweir 	void FreeOriginal()
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		m_bDelete = sal_False;
146cdf0e10cSrcweir 		m_bTransacted = sal_False;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 		m_xOrigStream = m_xTempStream;
149cdf0e10cSrcweir 		m_xTempStream = uno::Reference< io::XStream >();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		m_xOrigTruncate = m_xTempTruncate;
152cdf0e10cSrcweir 		m_xTempTruncate = uno::Reference< io::XTruncate >();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 		m_xOrigSeekable = m_xTempSeekable;
155cdf0e10cSrcweir 		m_xTempSeekable = uno::Reference< io::XSeekable >();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		m_xOrigInStream = m_xTempInStream;
158cdf0e10cSrcweir 		m_xTempInStream = uno::Reference< io::XInputStream >();
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		m_xOrigOutStream = m_xTempOutStream;
161cdf0e10cSrcweir 		m_xTempOutStream = uno::Reference< io::XOutputStream >();
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // ========================================================================
166cdf0e10cSrcweir // ------------------------------------------------------------------------
OTruncatedTransactedFileStream(const::rtl::OUString & aURL,const uno::Reference<lang::XMultiServiceFactory> & xFactory)167cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
168cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
169cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory )
170cdf0e10cSrcweir : m_pStreamData( NULL )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
173cdf0e10cSrcweir 		xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
174cdf0e10cSrcweir 		uno::UNO_QUERY_THROW );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	CommonInit_Impl( aURL, xSimpleFileAccess, xFactory, sal_False );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir // ------------------------------------------------------------------------
OTruncatedTransactedFileStream(const::rtl::OUString & aURL,const uno::Reference<ucb::XSimpleFileAccess> & xFileAccess,const uno::Reference<lang::XMultiServiceFactory> & xFactory)180cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
181cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
182cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
183cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory )
184cdf0e10cSrcweir : m_pStreamData( NULL )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	CommonInit_Impl( aURL, xFileAccess, xFactory, sal_False );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir // ------------------------------------------------------------------------
OTruncatedTransactedFileStream(const::rtl::OUString & aURL,const uno::Reference<ucb::XSimpleFileAccess> & xFileAccess,const uno::Reference<lang::XMultiServiceFactory> & xFactory,sal_Bool bDeleteIfNotCommited)190cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
191cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
192cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
193cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory,
194cdf0e10cSrcweir 		sal_Bool bDeleteIfNotCommited )
195cdf0e10cSrcweir : m_pStreamData( NULL )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	CommonInit_Impl( aURL, xFileAccess, xFactory, sal_True );
198cdf0e10cSrcweir 	if ( m_pStreamData )
199cdf0e10cSrcweir 		m_pStreamData->m_bDelete = bDeleteIfNotCommited;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // ------------------------------------------------------------------------
~OTruncatedTransactedFileStream()203cdf0e10cSrcweir OTruncatedTransactedFileStream::~OTruncatedTransactedFileStream()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	CloseAll_Impl();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // ------------------------------------------------------------------------
CloseAll_Impl()209cdf0e10cSrcweir void OTruncatedTransactedFileStream::CloseAll_Impl()
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	if ( m_pStreamData )
214cdf0e10cSrcweir 	{
215cdf0e10cSrcweir 		sal_Bool bDelete = m_pStreamData->m_bDelete;
216cdf0e10cSrcweir 		::rtl::OUString aURL = m_pStreamData->m_aURL;
217cdf0e10cSrcweir 		uno::Reference< ucb::XSimpleFileAccess > xFileAccess = m_pStreamData->m_xFileAccess;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		delete m_pStreamData;
220cdf0e10cSrcweir 		m_pStreamData = NULL;
221cdf0e10cSrcweir 
222*49b34792SHerbert Dürr 		if ( bDelete && xFileAccess.is() && !aURL.isEmpty() )
223cdf0e10cSrcweir 		{
224cdf0e10cSrcweir 			// delete the file
225cdf0e10cSrcweir 			try
226cdf0e10cSrcweir 			{
227cdf0e10cSrcweir 				xFileAccess->kill( aURL );
228cdf0e10cSrcweir 			} catch( uno::Exception& )
229cdf0e10cSrcweir 			{
230cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "Could not remove the file!" );
231cdf0e10cSrcweir 			}
232cdf0e10cSrcweir 		}
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir // ------------------------------------------------------------------------
CommonInit_Impl(const::rtl::OUString & aURL,const uno::Reference<ucb::XSimpleFileAccess> & xFileAccess,const uno::Reference<lang::XMultiServiceFactory> & xFactory,sal_Bool bDeleteOptionIsProvided)237cdf0e10cSrcweir void OTruncatedTransactedFileStream::CommonInit_Impl(
238cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
239cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
240cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory,
241cdf0e10cSrcweir 		sal_Bool bDeleteOptionIsProvided )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	sal_Bool bDelete = sal_False;
244cdf0e10cSrcweir 	if ( !bDeleteOptionIsProvided )
245cdf0e10cSrcweir 		bDelete = !xFileAccess->exists( aURL );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	uno::Reference< io::XStream > xOrigStream = xFileAccess->openFileReadWrite( aURL );
248cdf0e10cSrcweir 	uno::Reference< io::XTruncate > xOrigTruncate( xOrigStream, uno::UNO_QUERY_THROW );
249cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xOrigSeekable( xOrigStream, uno::UNO_QUERY_THROW );
250cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xOrigInStream = xOrigStream->getInputStream();
251cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > xOrigOutStream = xOrigStream->getOutputStream();
252cdf0e10cSrcweir 	if ( !xOrigInStream.is() || !xOrigOutStream.is() )
253cdf0e10cSrcweir 		throw uno::RuntimeException();
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	// temporary stream related members
256cdf0e10cSrcweir 	uno::Reference< io::XStream > xTempStream( xFactory->createInstance(
257cdf0e10cSrcweir 		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
258cdf0e10cSrcweir 		uno::UNO_QUERY_THROW );
259cdf0e10cSrcweir 	uno::Reference< io::XTruncate > xTempTruncate( xTempStream, uno::UNO_QUERY_THROW );
260cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xTempSeekable( xTempStream, uno::UNO_QUERY_THROW );
261cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xTempInStream = xTempStream->getInputStream();
262cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > xTempOutStream = xTempStream->getOutputStream();
263cdf0e10cSrcweir 	if ( !xTempInStream.is() || !xTempOutStream.is() )
264cdf0e10cSrcweir 		throw uno::RuntimeException();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	m_pStreamData = new TTFileStreamData_Impl( xFileAccess, bDelete, aURL,
267cdf0e10cSrcweir 											xOrigStream, xOrigTruncate, xOrigSeekable, xOrigInStream, xOrigOutStream,
268cdf0e10cSrcweir 											xTempStream, xTempTruncate, xTempSeekable, xTempInStream, xTempOutStream );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir // ------------------------------------------------------------------------
Commit_Impl()272cdf0e10cSrcweir void OTruncatedTransactedFileStream::Commit_Impl()
273cdf0e10cSrcweir {
274cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	if ( !m_pStreamData )
277cdf0e10cSrcweir 		throw io::NotConnectedException();
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
280cdf0e10cSrcweir 	{
281cdf0e10cSrcweir 		sal_Int64 nPos = m_pStreamData->m_xTempSeekable->getPosition();
282cdf0e10cSrcweir 		m_pStreamData->m_xTempSeekable->seek( 0 );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 		// after the following step fails the information might be lost, throw an exception with URL of temporary file
285cdf0e10cSrcweir 		try
286cdf0e10cSrcweir 		{
287cdf0e10cSrcweir 			m_pStreamData->m_xOrigTruncate->truncate();
288cdf0e10cSrcweir 			OStorageHelper::CopyInputToOutput( m_pStreamData->m_xTempInStream, m_pStreamData->m_xOrigOutStream );
289cdf0e10cSrcweir 			m_pStreamData->m_xOrigOutStream->flush();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 			// in case the stream is based on a file it will implement the following interface
292cdf0e10cSrcweir 			// the call should be used to be sure that the contents are written to the file system
293cdf0e10cSrcweir 			uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY );
294cdf0e10cSrcweir 			if ( asyncOutputMonitor.is() )
295cdf0e10cSrcweir 				asyncOutputMonitor->waitForCompletion();
296cdf0e10cSrcweir 		}
297cdf0e10cSrcweir 		catch( uno::Exception& )
298cdf0e10cSrcweir 		{
299cdf0e10cSrcweir 			::rtl::OUString aTempURL;
300cdf0e10cSrcweir 			try {
301cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xTempFile( m_pStreamData->m_xTempStream, uno::UNO_QUERY_THROW );
302cdf0e10cSrcweir 				uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
303cdf0e10cSrcweir 				aUrl >>= aTempURL;
304cdf0e10cSrcweir 				xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),
305cdf0e10cSrcweir 									 		uno::makeAny( sal_False ) );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 				m_pStreamData->m_xTempSeekable->seek( nPos );
308cdf0e10cSrcweir 			}
309cdf0e10cSrcweir 			catch( uno::Exception& )
310cdf0e10cSrcweir 			{
311cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "These calls are pretty simple, they should not fail!\n" );
312cdf0e10cSrcweir 			}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 			m_pStreamData->FreeOriginal();
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 			::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( "Writing file failed!" ) );
317cdf0e10cSrcweir 			embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), aTempURL );
318cdf0e10cSrcweir 			throw lang::WrappedTargetException( aErrTxt,
319cdf0e10cSrcweir 												static_cast < OWeakObject * > ( this ),
320cdf0e10cSrcweir 												uno::makeAny ( aException ) );
321cdf0e10cSrcweir 		}
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 		m_pStreamData->m_xOrigSeekable->seek( nPos );
324cdf0e10cSrcweir 		m_pStreamData->NoTransaction();
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 	else
327cdf0e10cSrcweir 		throw io::NotConnectedException();
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir // ------------------------------------------------------------------------
Revert_Impl()331cdf0e10cSrcweir void OTruncatedTransactedFileStream::Revert_Impl()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	if ( !m_pStreamData )
336cdf0e10cSrcweir 		throw io::NotConnectedException();
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
339cdf0e10cSrcweir 		m_pStreamData->m_xTempTruncate->truncate();
340cdf0e10cSrcweir 	else
341cdf0e10cSrcweir 		throw io::NotConnectedException();
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir // com::sun::star::io::XStream
345cdf0e10cSrcweir // ------------------------------------------------------------------------
getInputStream()346cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OTruncatedTransactedFileStream::getInputStream(  )
347cdf0e10cSrcweir 	throw (uno::RuntimeException)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     if ( m_pStreamData )
352cdf0e10cSrcweir         m_pStreamData->m_bInOpen = sal_True;
353cdf0e10cSrcweir 	return static_cast< io::XInputStream* >( this );
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 
357cdf0e10cSrcweir // ------------------------------------------------------------------------
getOutputStream()358cdf0e10cSrcweir uno::Reference< io::XOutputStream > SAL_CALL OTruncatedTransactedFileStream::getOutputStream(  )
359cdf0e10cSrcweir 	throw (uno::RuntimeException)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     if ( m_pStreamData )
364cdf0e10cSrcweir         m_pStreamData->m_bOutOpen = sal_True;
365cdf0e10cSrcweir 	return static_cast< io::XOutputStream* >( this );
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 
370cdf0e10cSrcweir // com::sun::star::io::XInputStream
371cdf0e10cSrcweir // ------------------------------------------------------------------------
readBytes(uno::Sequence<::sal_Int8> & aData,::sal_Int32 nBytesToRead)372cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
373cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	if ( !m_pStreamData )
378cdf0e10cSrcweir 		throw io::NotConnectedException();
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
381cdf0e10cSrcweir 	{
382cdf0e10cSrcweir 		// temporary stream data should be provided
383cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
384cdf0e10cSrcweir 			throw uno::RuntimeException();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->readBytes( aData, nBytesToRead );
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir 	else
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		// the original stream data should be provided
391cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
392cdf0e10cSrcweir 			throw uno::RuntimeException();
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead );
395cdf0e10cSrcweir 	}
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
399cdf0e10cSrcweir // ------------------------------------------------------------------------
readSomeBytes(uno::Sequence<::sal_Int8> & aData,::sal_Int32 nMaxBytesToRead)400cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
401cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
402cdf0e10cSrcweir {
403cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 	if ( !m_pStreamData )
406cdf0e10cSrcweir 		throw io::NotConnectedException();
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		// temporary stream data should be provided
411cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
412cdf0e10cSrcweir 			throw uno::RuntimeException();
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->readSomeBytes( aData, nMaxBytesToRead );
415cdf0e10cSrcweir 	}
416cdf0e10cSrcweir 	else
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		// the original stream data should be provided
419cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
420cdf0e10cSrcweir 			throw uno::RuntimeException();
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->readSomeBytes( aData, nMaxBytesToRead );
423cdf0e10cSrcweir 	}
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir // ------------------------------------------------------------------------
skipBytes(::sal_Int32 nBytesToSkip)427cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::skipBytes( ::sal_Int32 nBytesToSkip )
428cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
429cdf0e10cSrcweir {
430cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	if ( !m_pStreamData )
433cdf0e10cSrcweir 		throw io::NotConnectedException();
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		// temporary stream data should be provided
438cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
439cdf0e10cSrcweir 			throw uno::RuntimeException();
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 		m_pStreamData->m_xTempInStream->skipBytes( nBytesToSkip );
442cdf0e10cSrcweir 	}
443cdf0e10cSrcweir 	else
444cdf0e10cSrcweir 	{
445cdf0e10cSrcweir 		// the original stream data should be provided
446cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
447cdf0e10cSrcweir 			throw uno::RuntimeException();
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 		m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip );
450cdf0e10cSrcweir 	}
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 
454cdf0e10cSrcweir // ------------------------------------------------------------------------
available()455cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::available(  )
456cdf0e10cSrcweir 	throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	if ( !m_pStreamData )
461cdf0e10cSrcweir 		throw io::NotConnectedException();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
464cdf0e10cSrcweir 	{
465cdf0e10cSrcweir 		// temporary stream data should be provided
466cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
467cdf0e10cSrcweir 			throw uno::RuntimeException();
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->available();
470cdf0e10cSrcweir 	}
471cdf0e10cSrcweir 	else
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		// the original stream data should be provided
474cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
475cdf0e10cSrcweir 			throw uno::RuntimeException();
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->available();
478cdf0e10cSrcweir 	}
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 
482cdf0e10cSrcweir // ------------------------------------------------------------------------
closeInput()483cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::closeInput()
484cdf0e10cSrcweir 	throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
485cdf0e10cSrcweir {
486cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	if ( !m_pStreamData )
489cdf0e10cSrcweir 		throw io::NotConnectedException();
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	m_pStreamData->m_bInOpen = sal_False;
492cdf0e10cSrcweir 	if ( !m_pStreamData->m_bOutOpen )
493cdf0e10cSrcweir 		CloseAll_Impl();
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 
498cdf0e10cSrcweir // com::sun::star::io::XOutputStream
499cdf0e10cSrcweir // ------------------------------------------------------------------------
writeBytes(const uno::Sequence<::sal_Int8> & aData)500cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData )
501cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	if ( !m_pStreamData )
506cdf0e10cSrcweir 		throw io::NotConnectedException();
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		// temporary stream data should be provided
511cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempOutStream.is() )
512cdf0e10cSrcweir 			throw uno::RuntimeException();
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 		m_pStreamData->m_xTempOutStream->writeBytes( aData );
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir 	else
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir 		// the original stream data should be provided
519cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigOutStream.is() )
520cdf0e10cSrcweir 			throw uno::RuntimeException();
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 		m_pStreamData->m_xOrigOutStream->writeBytes( aData );
523cdf0e10cSrcweir 	}
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 
527cdf0e10cSrcweir // ------------------------------------------------------------------------
flush()528cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::flush(  )
529cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
530cdf0e10cSrcweir {
531cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 	if ( !m_pStreamData )
534cdf0e10cSrcweir 	{
535cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "flush() call on closed stream!\n" );
536cdf0e10cSrcweir 		return;
537cdf0e10cSrcweir 		// in future throw exception, for now some code might call flush() on closed stream
538cdf0e10cSrcweir 		// since file ucp implementation allows it
539cdf0e10cSrcweir 		// throw io::NotConnectedException();
540cdf0e10cSrcweir 	}
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
543cdf0e10cSrcweir 	{
544cdf0e10cSrcweir 		// temporary stream data should be provided
545cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempOutStream.is() )
546cdf0e10cSrcweir 			throw uno::RuntimeException();
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		m_pStreamData->m_xTempOutStream->flush();
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir 	else
551cdf0e10cSrcweir 	{
552cdf0e10cSrcweir 		// the original stream data should be provided
553cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigOutStream.is() )
554cdf0e10cSrcweir 			throw uno::RuntimeException();
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 		m_pStreamData->m_xOrigOutStream->flush();
557cdf0e10cSrcweir 	}
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // ------------------------------------------------------------------------
closeOutput()562cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::closeOutput(  )
563cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	if ( !m_pStreamData )
568cdf0e10cSrcweir 		throw io::NotConnectedException();
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	m_pStreamData->m_bOutOpen = sal_False;
571cdf0e10cSrcweir 	if ( !m_pStreamData->m_bInOpen )
572cdf0e10cSrcweir 		CloseAll_Impl();
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 
577cdf0e10cSrcweir // com::sun::star::io::XTruncate
578cdf0e10cSrcweir // ------------------------------------------------------------------------
truncate()579cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::truncate(  )
580cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
581cdf0e10cSrcweir {
582cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	if ( !m_pStreamData )
585cdf0e10cSrcweir 		throw io::NotConnectedException();
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
588cdf0e10cSrcweir 	{
589cdf0e10cSrcweir 		// temporary stream data should be provided
590cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempTruncate.is() )
591cdf0e10cSrcweir 			throw uno::RuntimeException();
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 		m_pStreamData->m_xTempTruncate->truncate();
594cdf0e10cSrcweir 	}
595cdf0e10cSrcweir 	else
596cdf0e10cSrcweir 	{
597cdf0e10cSrcweir 		// the original stream data should be provided
598cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigTruncate.is() )
599cdf0e10cSrcweir 			throw uno::RuntimeException();
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 		m_pStreamData->m_xOrigTruncate->truncate();
602cdf0e10cSrcweir 	}
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 
607cdf0e10cSrcweir // com::sun::star::io::XSeekable
608cdf0e10cSrcweir // ------------------------------------------------------------------------
seek(::sal_Int64 location)609cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::seek( ::sal_Int64 location )
610cdf0e10cSrcweir 	throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 	if ( !m_pStreamData )
615cdf0e10cSrcweir 		throw io::NotConnectedException();
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
618cdf0e10cSrcweir 	{
619cdf0e10cSrcweir 		// temporary stream data should be provided
620cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
621cdf0e10cSrcweir 			throw uno::RuntimeException();
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 		m_pStreamData->m_xTempSeekable->seek( location );
624cdf0e10cSrcweir 	}
625cdf0e10cSrcweir 	else
626cdf0e10cSrcweir 	{
627cdf0e10cSrcweir 		// the original stream data should be provided
628cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
629cdf0e10cSrcweir 			throw uno::RuntimeException();
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 		m_pStreamData->m_xOrigSeekable->seek( location );
632cdf0e10cSrcweir 	}
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 
636cdf0e10cSrcweir // ------------------------------------------------------------------------
getPosition()637cdf0e10cSrcweir ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getPosition(  )
638cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
639cdf0e10cSrcweir {
640cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 	if ( !m_pStreamData )
643cdf0e10cSrcweir 		throw io::NotConnectedException();
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
646cdf0e10cSrcweir 	{
647cdf0e10cSrcweir 		// temporary stream data should be provided
648cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
649cdf0e10cSrcweir 			throw uno::RuntimeException();
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 		return m_pStreamData->m_xTempSeekable->getPosition();
652cdf0e10cSrcweir 	}
653cdf0e10cSrcweir 	else
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir 		// the original stream data should be provided
656cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
657cdf0e10cSrcweir 			throw uno::RuntimeException();
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 		return m_pStreamData->m_xOrigSeekable->getPosition();
660cdf0e10cSrcweir 	}
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 
664cdf0e10cSrcweir // ------------------------------------------------------------------------
getLength()665cdf0e10cSrcweir ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getLength(  )
666cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
667cdf0e10cSrcweir {
668cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 	if ( !m_pStreamData )
671cdf0e10cSrcweir 		throw io::NotConnectedException();
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
674cdf0e10cSrcweir 	{
675cdf0e10cSrcweir 		// temporary stream data should be provided
676cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
677cdf0e10cSrcweir 			throw uno::RuntimeException();
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 		return m_pStreamData->m_xTempSeekable->getLength();
680cdf0e10cSrcweir 	}
681cdf0e10cSrcweir 	else
682cdf0e10cSrcweir 	{
683cdf0e10cSrcweir 		// the original stream data should be provided
684cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
685cdf0e10cSrcweir 			throw uno::RuntimeException();
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 		return m_pStreamData->m_xOrigSeekable->getLength();
688cdf0e10cSrcweir 	}
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir // com::sun::star::beans::XPropertySetInfo
692cdf0e10cSrcweir // ------------------------------------------------------------------------
getProperties()693cdf0e10cSrcweir uno::Sequence< beans::Property > SAL_CALL OTruncatedTransactedFileStream::getProperties()
694cdf0e10cSrcweir 	throw (uno::RuntimeException)
695cdf0e10cSrcweir {
696cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 	uno::Sequence< beans::Property > aProps( 1 );
699cdf0e10cSrcweir 	aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
700cdf0e10cSrcweir 	aProps[0].Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
701cdf0e10cSrcweir 	aProps[0].Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 	return aProps;
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 
707cdf0e10cSrcweir // ------------------------------------------------------------------------
getPropertyByName(const::rtl::OUString & aName)708cdf0e10cSrcweir beans::Property SAL_CALL OTruncatedTransactedFileStream::getPropertyByName( const ::rtl::OUString& aName )
709cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, uno::RuntimeException)
710cdf0e10cSrcweir {
711cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 	if ( !aName.equals( aTransactionPropName ) )
716cdf0e10cSrcweir 		throw beans::UnknownPropertyException();
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 	beans::Property aProp;
719cdf0e10cSrcweir 	aProp.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
720cdf0e10cSrcweir 	aProp.Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
721cdf0e10cSrcweir 	aProp.Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 	return aProp;
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 
727cdf0e10cSrcweir // ------------------------------------------------------------------------
hasPropertyByName(const::rtl::OUString & Name)728cdf0e10cSrcweir ::sal_Bool SAL_CALL OTruncatedTransactedFileStream::hasPropertyByName( const ::rtl::OUString& Name )
729cdf0e10cSrcweir 	throw (uno::RuntimeException)
730cdf0e10cSrcweir {
731cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
734cdf0e10cSrcweir 	return ( Name.equals( aTransactionPropName ) );
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 
739cdf0e10cSrcweir // com::sun::star::beans::XPropertySet
740cdf0e10cSrcweir // ------------------------------------------------------------------------
getPropertySetInfo()741cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL OTruncatedTransactedFileStream::getPropertySetInfo()
742cdf0e10cSrcweir 	throw (uno::RuntimeException)
743cdf0e10cSrcweir {
744cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	return static_cast< beans::XPropertySetInfo* >( this );
747cdf0e10cSrcweir }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 
750cdf0e10cSrcweir // ------------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any &)751cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& )
752cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
753cdf0e10cSrcweir {
754cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
757cdf0e10cSrcweir 	if ( aPropertyName.equals( aTransactionPropName ) )
758cdf0e10cSrcweir 		throw beans::PropertyVetoException();
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	throw beans::UnknownPropertyException();
761cdf0e10cSrcweir }
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 
764cdf0e10cSrcweir // ------------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & PropertyName)765cdf0e10cSrcweir uno::Any SAL_CALL OTruncatedTransactedFileStream::getPropertyValue( const ::rtl::OUString& PropertyName )
766cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 	if ( !m_pStreamData )
771cdf0e10cSrcweir 		throw io::NotConnectedException();
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
774cdf0e10cSrcweir 	if ( PropertyName.equals( aTransactionPropName ) )
775cdf0e10cSrcweir 	{
776cdf0e10cSrcweir 		uno::Reference< embed::XTransactedObject > xObj;
777cdf0e10cSrcweir 		if ( m_pStreamData->m_bTransacted )
778cdf0e10cSrcweir 			xObj = static_cast< embed::XTransactedObject* >( new OTransactionHelper( this ) );
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 		return uno::makeAny( xObj );
781cdf0e10cSrcweir 	}
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 	throw beans::UnknownPropertyException();
784cdf0e10cSrcweir }
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 
787cdf0e10cSrcweir // ------------------------------------------------------------------------
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)788cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::addPropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
789cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
790cdf0e10cSrcweir {
791cdf0e10cSrcweir 	// not implemented
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 
795cdf0e10cSrcweir // ------------------------------------------------------------------------
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)796cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::removePropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
797cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
798cdf0e10cSrcweir {
799cdf0e10cSrcweir 	// not implemented
800cdf0e10cSrcweir }
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 
803cdf0e10cSrcweir // ------------------------------------------------------------------------
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)804cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::addVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
805cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
806cdf0e10cSrcweir {
807cdf0e10cSrcweir 	// not implemented
808cdf0e10cSrcweir }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 
811cdf0e10cSrcweir // ------------------------------------------------------------------------
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)812cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::removeVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
813cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir 	// not implemented
816cdf0e10cSrcweir }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 
819cdf0e10cSrcweir } // namespace comphelper
820cdf0e10cSrcweir 
821