1*046d9d1fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*046d9d1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*046d9d1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*046d9d1fSAndrew Rist  * distributed with this work for additional information
6*046d9d1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*046d9d1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*046d9d1fSAndrew Rist  * "License"); you may not use this file except in compliance
9*046d9d1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*046d9d1fSAndrew Rist  *
11*046d9d1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*046d9d1fSAndrew Rist  *
13*046d9d1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*046d9d1fSAndrew Rist  * software distributed under the License is distributed on an
15*046d9d1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*046d9d1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*046d9d1fSAndrew Rist  * specific language governing permissions and limitations
18*046d9d1fSAndrew Rist  * under the License.
19*046d9d1fSAndrew Rist  *
20*046d9d1fSAndrew Rist  *************************************************************/
21*046d9d1fSAndrew Rist 
22*046d9d1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sot.hxx"
26cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
27cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
28cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <sot/storinfo.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "xolesimplestorage.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir const sal_Int32 nBytesCount = 32000;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // --------------------------------------------------------------------------------
OLESimpleStorage(uno::Reference<lang::XMultiServiceFactory> xFactory)49cdf0e10cSrcweir OLESimpleStorage::OLESimpleStorage( uno::Reference< lang::XMultiServiceFactory > xFactory )
50cdf0e10cSrcweir : m_bDisposed( sal_False )
51cdf0e10cSrcweir , m_pStream( NULL )
52cdf0e10cSrcweir , m_pStorage( NULL )
53cdf0e10cSrcweir , m_pListenersContainer( NULL )
54cdf0e10cSrcweir , m_xFactory( xFactory )
55cdf0e10cSrcweir , m_bNoTemporaryCopy( sal_False )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	OSL_ENSURE( m_xFactory.is(), "No factory is provided on creation!\n" );
58cdf0e10cSrcweir 	if ( !m_xFactory.is() )
59cdf0e10cSrcweir 		throw uno::RuntimeException();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir // --------------------------------------------------------------------------------
~OLESimpleStorage()63cdf0e10cSrcweir OLESimpleStorage::~OLESimpleStorage()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	try {
66cdf0e10cSrcweir 		m_refCount++;
67cdf0e10cSrcweir 		dispose();
68cdf0e10cSrcweir 	} catch( uno::Exception& )
69cdf0e10cSrcweir 	{}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	if ( m_pListenersContainer )
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		delete m_pListenersContainer;
74cdf0e10cSrcweir 		m_pListenersContainer = NULL;
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()79cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::impl_staticGetSupportedServiceNames()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(1);
82cdf0e10cSrcweir     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OLESimpleStorage");
83cdf0e10cSrcweir     return aRet;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetImplementationName()87cdf0e10cSrcweir ::rtl::OUString SAL_CALL OLESimpleStorage::impl_staticGetImplementationName()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OLESimpleStorage");
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)93cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OLESimpleStorage::impl_staticCreateSelfInstance(
94cdf0e10cSrcweir 			const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	return uno::Reference< uno::XInterface >( *new OLESimpleStorage( xServiceManager ) );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //-------------------------------------------------------------------------
UpdateOriginal_Impl()100cdf0e10cSrcweir void OLESimpleStorage::UpdateOriginal_Impl()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	if ( !m_bNoTemporaryCopy )
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		uno::Reference< io::XSeekable > xSeek( m_xStream, uno::UNO_QUERY_THROW );
105cdf0e10cSrcweir 		xSeek->seek( 0 );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		uno::Reference< io::XSeekable > xTempSeek( m_xTempStream, uno::UNO_QUERY_THROW );
108cdf0e10cSrcweir 		sal_Int64 nPos = xTempSeek->getPosition();
109cdf0e10cSrcweir 		xTempSeek->seek( 0 );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xTempInp = m_xTempStream->getInputStream();
112cdf0e10cSrcweir 		uno::Reference< io::XOutputStream > xOutputStream = m_xStream->getOutputStream();
113cdf0e10cSrcweir 		if ( !xTempInp.is() || !xOutputStream.is() )
114cdf0e10cSrcweir 			throw uno::RuntimeException();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		uno::Reference< io::XTruncate > xTrunc( xOutputStream, uno::UNO_QUERY_THROW );
117cdf0e10cSrcweir 		xTrunc->truncate();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xTempInp, xOutputStream );
120cdf0e10cSrcweir 		xOutputStream->flush();
121cdf0e10cSrcweir 		xTempSeek->seek( nPos );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //-------------------------------------------------------------------------
InsertInputStreamToStorage_Impl(BaseStorage * pStorage,::rtl::OUString aName,const uno::Reference<io::XInputStream> & xInputStream)126cdf0e10cSrcweir void OLESimpleStorage::InsertInputStreamToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInputStream )
127cdf0e10cSrcweir 	throw ( uno::Exception )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	if ( !pStorage || !aName.getLength() || !xInputStream.is() )
130cdf0e10cSrcweir 		throw uno::RuntimeException();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	if ( pStorage->IsContained( aName ) )
133cdf0e10cSrcweir 		throw container::ElementExistException(); // TODO:
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	BaseStorageStream* pNewStream = pStorage->OpenStream( aName );
136cdf0e10cSrcweir 	if ( !pNewStream || pNewStream->GetError() || pStorage->GetError() )
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		if ( pNewStream )
139cdf0e10cSrcweir 			DELETEZ( pNewStream );
140cdf0e10cSrcweir 		pStorage->ResetError();
141cdf0e10cSrcweir 		throw io::IOException(); // TODO
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	try
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		uno::Sequence< sal_Int8 > aData( nBytesCount );
147cdf0e10cSrcweir 		sal_Int32 nRead = 0;
148cdf0e10cSrcweir 		do
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			nRead = xInputStream->readBytes( aData, nBytesCount );
151cdf0e10cSrcweir 			if ( nRead < nBytesCount )
152cdf0e10cSrcweir 				aData.realloc( nRead );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 			sal_Int32 nWritten = pNewStream->Write( aData.getArray(), nRead );
155cdf0e10cSrcweir 			if ( nWritten < nRead )
156cdf0e10cSrcweir 				throw io::IOException();
157cdf0e10cSrcweir 		} while( nRead == nBytesCount );
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 	catch( uno::Exception& )
160cdf0e10cSrcweir 	{
161cdf0e10cSrcweir 		DELETEZ( pNewStream );
162cdf0e10cSrcweir 		pStorage->Remove( aName );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		throw;
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	DELETEZ( pNewStream );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //-------------------------------------------------------------------------
InsertNameAccessToStorage_Impl(BaseStorage * pStorage,::rtl::OUString aName,const uno::Reference<container::XNameAccess> & xNameAccess)171cdf0e10cSrcweir void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< container::XNameAccess >& xNameAccess )
172cdf0e10cSrcweir 	throw ( uno::Exception )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	if ( !pStorage || !aName.getLength() || !xNameAccess.is() )
175cdf0e10cSrcweir 		throw uno::RuntimeException();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	if ( pStorage->IsContained( aName ) )
178cdf0e10cSrcweir 		throw container::ElementExistException(); // TODO:
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	BaseStorage* pNewStorage = pStorage->OpenStorage( aName );
181cdf0e10cSrcweir 	if ( !pNewStorage || pNewStorage->GetError() || pStorage->GetError() )
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		if ( pNewStorage )
184cdf0e10cSrcweir 			DELETEZ( pNewStorage );
185cdf0e10cSrcweir 		pStorage->ResetError();
186cdf0e10cSrcweir 		throw io::IOException(); // TODO
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	try
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 		uno::Sequence< ::rtl::OUString > aElements = xNameAccess->getElementNames();
192cdf0e10cSrcweir 		for ( sal_Int32 nInd = 0; nInd < aElements.getLength(); nInd++ )
193cdf0e10cSrcweir 		{
194cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xInputStream;
195cdf0e10cSrcweir 			uno::Reference< container::XNameAccess > xSubNameAccess;
196cdf0e10cSrcweir 			uno::Any aAny = xNameAccess->getByName( aElements[nInd] );
197cdf0e10cSrcweir 			if ( aAny >>= xInputStream )
198cdf0e10cSrcweir 				InsertInputStreamToStorage_Impl( pNewStorage, aElements[nInd], xInputStream );
199cdf0e10cSrcweir 			else if ( aAny >>= xSubNameAccess )
200cdf0e10cSrcweir 				InsertNameAccessToStorage_Impl( pNewStorage, aElements[nInd], xSubNameAccess );
201cdf0e10cSrcweir 		}
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 	catch( uno::Exception& )
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		DELETEZ( pNewStorage );
206cdf0e10cSrcweir 		pStorage->Remove( aName );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 		throw;
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	DELETEZ( pNewStorage );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir //____________________________________________________________________________________________________
215cdf0e10cSrcweir //	XInitialization
216cdf0e10cSrcweir //____________________________________________________________________________________________________
217cdf0e10cSrcweir 
initialize(const uno::Sequence<uno::Any> & aArguments)218cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::initialize( const uno::Sequence< uno::Any >& aArguments )
219cdf0e10cSrcweir 		throw ( uno::Exception,
220cdf0e10cSrcweir 				uno::RuntimeException)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	if ( m_pStream || m_pStorage )
223cdf0e10cSrcweir 		throw io::IOException(); // TODO: already initilized
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	sal_Int32 nArgNum = aArguments.getLength();
226cdf0e10cSrcweir 	OSL_ENSURE( nArgNum >= 1 && nArgNum <= 2, "Wrong parameter number" );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if ( nArgNum < 1 || nArgNum > 2 )
229cdf0e10cSrcweir 		throw lang::IllegalArgumentException(); // TODO:
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	uno::Reference< io::XStream > xStream;
232cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xInputStream;
233cdf0e10cSrcweir 	if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) )
234cdf0e10cSrcweir 		throw lang::IllegalArgumentException(); // TODO:
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	if ( nArgNum == 2 )
237cdf0e10cSrcweir 	{
238cdf0e10cSrcweir 		if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) )
239cdf0e10cSrcweir 			throw lang::IllegalArgumentException(); // TODO:
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	if ( m_bNoTemporaryCopy )
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir 		// TODO: ???
245cdf0e10cSrcweir 		// If the temporary stream is not created, the original stream must be wrapped
246cdf0e10cSrcweir 		// since SvStream wrapper closes the stream is owns
247cdf0e10cSrcweir 		if ( xInputStream.is() )
248cdf0e10cSrcweir 		{
249cdf0e10cSrcweir 			// the stream must be seekable for direct access
250cdf0e10cSrcweir 			uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
251cdf0e10cSrcweir 			m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, sal_False );
252cdf0e10cSrcweir 		}
253cdf0e10cSrcweir 		else if ( xStream.is() )
254cdf0e10cSrcweir 		{
255cdf0e10cSrcweir 			// the stream must be seekable for direct access
256cdf0e10cSrcweir 			uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
257cdf0e10cSrcweir 			m_pStream = ::utl::UcbStreamHelper::CreateStream( xStream, sal_False );
258cdf0e10cSrcweir 		}
259cdf0e10cSrcweir 		else
260cdf0e10cSrcweir 			throw lang::IllegalArgumentException(); // TODO:
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir 	else
263cdf0e10cSrcweir 	{
264cdf0e10cSrcweir 		uno::Reference < io::XStream > xTempFile(
265cdf0e10cSrcweir 				m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
266cdf0e10cSrcweir 				uno::UNO_QUERY_THROW );
267cdf0e10cSrcweir 		uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
268cdf0e10cSrcweir 		uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream();
269cdf0e10cSrcweir 		if ( !xTempOut.is() )
270cdf0e10cSrcweir 			throw uno::RuntimeException();
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 		if ( xInputStream.is() )
273cdf0e10cSrcweir 		{
274cdf0e10cSrcweir 			try
275cdf0e10cSrcweir 			{
276cdf0e10cSrcweir 				uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
277cdf0e10cSrcweir 				xSeek->seek( 0 );
278cdf0e10cSrcweir 			}
279cdf0e10cSrcweir 			catch( uno::Exception& )
280cdf0e10cSrcweir 			{}
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 			::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut );
283cdf0e10cSrcweir 			xTempOut->closeOutput();
284cdf0e10cSrcweir 			xTempSeek->seek( 0 );
285cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream();
286cdf0e10cSrcweir 			m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempInput, sal_False );
287cdf0e10cSrcweir 		}
288cdf0e10cSrcweir 		else if ( xStream.is() )
289cdf0e10cSrcweir 		{
290cdf0e10cSrcweir 			// not sure that the storage flashes the stream on commit
291cdf0e10cSrcweir 			m_xStream = xStream;
292cdf0e10cSrcweir 			m_xTempStream = xTempFile;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 			uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
295cdf0e10cSrcweir 			xSeek->seek( 0 );
296cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xInpStream = xStream->getInputStream();
297cdf0e10cSrcweir 			if ( !xInpStream.is() || !xStream->getOutputStream().is() )
298cdf0e10cSrcweir 				throw uno::RuntimeException();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 			::comphelper::OStorageHelper::CopyInputToOutput( xInpStream, xTempOut );
301cdf0e10cSrcweir 			xTempOut->flush();
302cdf0e10cSrcweir 			xTempSeek->seek( 0 );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 			m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False );
305cdf0e10cSrcweir 		}
306cdf0e10cSrcweir 		else
307cdf0e10cSrcweir 			throw lang::IllegalArgumentException(); // TODO:
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	if ( !m_pStream || m_pStream->GetError() )
311cdf0e10cSrcweir 		throw io::IOException(); // TODO
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	m_pStorage = new Storage( *m_pStream, sal_False );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 
317cdf0e10cSrcweir //____________________________________________________________________________________________________
318cdf0e10cSrcweir //	XNameContainer
319cdf0e10cSrcweir //____________________________________________________________________________________________________
320cdf0e10cSrcweir 
321cdf0e10cSrcweir // --------------------------------------------------------------------------------
insertByName(const::rtl::OUString & aName,const uno::Any & aElement)322cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement )
323cdf0e10cSrcweir 		throw ( lang::IllegalArgumentException,
324cdf0e10cSrcweir 				container::ElementExistException,
325cdf0e10cSrcweir 				lang::WrappedTargetException,
326cdf0e10cSrcweir 				uno::RuntimeException)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	if ( m_bDisposed )
331cdf0e10cSrcweir 		throw lang::DisposedException();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	  if ( !m_pStorage )
334cdf0e10cSrcweir 		throw uno::RuntimeException();
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	uno::Reference< io::XStream > xStream;
337cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xInputStream;
338cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xNameAccess;
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	try
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		if ( !m_bNoTemporaryCopy && !m_xStream.is() )
343cdf0e10cSrcweir 			throw io::IOException(); // TODO
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		if ( aElement >>= xStream )
346cdf0e10cSrcweir 			xInputStream = xStream->getInputStream();
347cdf0e10cSrcweir 		else if ( !( aElement >>= xInputStream ) && !( aElement >>= xNameAccess ) )
348cdf0e10cSrcweir 			throw lang::IllegalArgumentException(); // TODO:
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		if ( xInputStream.is() )
351cdf0e10cSrcweir 			InsertInputStreamToStorage_Impl( m_pStorage, aName, xInputStream );
352cdf0e10cSrcweir 		else if ( xNameAccess.is() )
353cdf0e10cSrcweir 			InsertNameAccessToStorage_Impl( m_pStorage, aName, xNameAccess );
354cdf0e10cSrcweir 		else
355cdf0e10cSrcweir 			throw uno::RuntimeException();
356cdf0e10cSrcweir 	}
357cdf0e10cSrcweir 	catch( uno::RuntimeException& )
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir 		throw;
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 	catch( container::ElementExistException& )
362cdf0e10cSrcweir 	{
363cdf0e10cSrcweir 		throw;
364cdf0e10cSrcweir 	}
365cdf0e10cSrcweir 	catch( uno::Exception& e )
366cdf0e10cSrcweir 	{
367cdf0e10cSrcweir 		throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Insert has failed!" ) ),
368cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
369cdf0e10cSrcweir 											uno::makeAny( e ) );
370cdf0e10cSrcweir 	}
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir // --------------------------------------------------------------------------------
removeByName(const::rtl::OUString & aName)374cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::removeByName( const ::rtl::OUString& aName )
375cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
376cdf0e10cSrcweir 				lang::WrappedTargetException,
377cdf0e10cSrcweir 				uno::RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 	if ( m_bDisposed )
382cdf0e10cSrcweir 		throw lang::DisposedException();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	  if ( !m_pStorage )
385cdf0e10cSrcweir 		throw uno::RuntimeException();
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	if ( !m_bNoTemporaryCopy && !m_xStream.is() )
388cdf0e10cSrcweir 		throw lang::WrappedTargetException(); // io::IOException(); // TODO
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	if ( !m_pStorage->IsContained( aName ) )
391cdf0e10cSrcweir 		throw container::NoSuchElementException(); // TODO:
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 	m_pStorage->Remove( aName );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	if ( m_pStorage->GetError() )
396cdf0e10cSrcweir 	{
397cdf0e10cSrcweir 		m_pStorage->ResetError();
398cdf0e10cSrcweir 		throw lang::WrappedTargetException(); // io::IOException(); // TODO
399cdf0e10cSrcweir 	}
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir // --------------------------------------------------------------------------------
replaceByName(const::rtl::OUString & aName,const uno::Any & aElement)403cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
404cdf0e10cSrcweir 		throw ( lang::IllegalArgumentException,
405cdf0e10cSrcweir 				container::NoSuchElementException,
406cdf0e10cSrcweir 				lang::WrappedTargetException,
407cdf0e10cSrcweir 				uno::RuntimeException)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 	if ( m_bDisposed )
412cdf0e10cSrcweir 		throw lang::DisposedException();
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	removeByName( aName );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 	try
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		insertByName( aName, aElement );
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 	catch( container::ElementExistException& )
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir 	   	uno::Any aCaught( ::cppu::getCaughtException() );
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 		throw lang::WrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
425cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
426cdf0e10cSrcweir 											aCaught );
427cdf0e10cSrcweir 	}
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir // --------------------------------------------------------------------------------
getByName(const::rtl::OUString & aName)431cdf0e10cSrcweir uno::Any SAL_CALL OLESimpleStorage::getByName( const ::rtl::OUString& aName )
432cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
433cdf0e10cSrcweir 				lang::WrappedTargetException,
434cdf0e10cSrcweir 				uno::RuntimeException )
435cdf0e10cSrcweir {
436cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	if ( m_bDisposed )
439cdf0e10cSrcweir 		throw lang::DisposedException();
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	  if ( !m_pStorage )
442cdf0e10cSrcweir 		throw uno::RuntimeException();
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 	if ( !m_pStorage->IsContained( aName ) )
445cdf0e10cSrcweir 		throw container::NoSuchElementException(); // TODO:
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 	uno::Any aResult;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	uno::Reference< io::XStream > xTempFile(
450cdf0e10cSrcweir 		m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
451cdf0e10cSrcweir 		uno::UNO_QUERY );
452cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW );
453cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream();
454cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream();
455cdf0e10cSrcweir 	if ( !xOutputStream.is() || !xInputStream.is() )
456cdf0e10cSrcweir 		throw uno::RuntimeException();
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 	if ( m_pStorage->IsStorage( aName ) )
459cdf0e10cSrcweir 	{
460cdf0e10cSrcweir 		BaseStorage* pStrg = m_pStorage->OpenStorage( aName );
461cdf0e10cSrcweir 		m_pStorage->ResetError();
462cdf0e10cSrcweir 		if ( !pStrg )
463cdf0e10cSrcweir 			throw io::IOException();
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 		SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False ); // do not close the original stream
466cdf0e10cSrcweir 		if ( !pStream )
467cdf0e10cSrcweir 			throw uno::RuntimeException();
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 		BaseStorage* pNewStor = new Storage( *pStream, sal_False );
470cdf0e10cSrcweir 		sal_Bool bSuccess =
471cdf0e10cSrcweir 			( pStrg->CopyTo( pNewStor ) && pNewStor->Commit() && !pNewStor->GetError() && !pStrg->GetError() );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 		DELETEZ( pNewStor );
474cdf0e10cSrcweir 		DELETEZ( pStrg );
475cdf0e10cSrcweir 		DELETEZ( pStream );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 		if ( !bSuccess )
478cdf0e10cSrcweir 			throw uno::RuntimeException();
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 		uno::Sequence< uno::Any > aArgs( 2 );
481cdf0e10cSrcweir 		aArgs[0] <<= xInputStream; // allow readonly access only
482cdf0e10cSrcweir 		aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xResultNameContainer(
485cdf0e10cSrcweir 			m_xFactory->createInstanceWithArguments(
486cdf0e10cSrcweir 					::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ),
487cdf0e10cSrcweir 					aArgs ),
488cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 		aResult <<= xResultNameContainer;
491cdf0e10cSrcweir 	}
492cdf0e10cSrcweir 	else
493cdf0e10cSrcweir 	{
494cdf0e10cSrcweir 		BaseStorageStream* pStream = m_pStorage->OpenStream( aName, STREAM_READ | STREAM_SHARE_DENYALL | STREAM_NOCREATE );
495cdf0e10cSrcweir 		if ( !pStream || pStream->GetError() || m_pStorage->GetError() )
496cdf0e10cSrcweir 		{
497cdf0e10cSrcweir 			m_pStorage->ResetError();
498cdf0e10cSrcweir 			DELETEZ( pStream );
499cdf0e10cSrcweir 			throw io::IOException(); // TODO
500cdf0e10cSrcweir 		}
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 		try
503cdf0e10cSrcweir 		{
504cdf0e10cSrcweir 			uno::Sequence< sal_Int8 > aData( nBytesCount );
505cdf0e10cSrcweir 			sal_Int32 nSize = nBytesCount;
506cdf0e10cSrcweir 			sal_Int32 nRead = 0;
507cdf0e10cSrcweir 			while( 0 != ( nRead = pStream->Read( aData.getArray(), nSize ) ) )
508cdf0e10cSrcweir 			{
509cdf0e10cSrcweir 				if ( nRead < nSize )
510cdf0e10cSrcweir 				{
511cdf0e10cSrcweir 					nSize = nRead;
512cdf0e10cSrcweir 					aData.realloc( nSize );
513cdf0e10cSrcweir 				}
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 				xOutputStream->writeBytes( aData );
516cdf0e10cSrcweir 			}
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 			if ( pStream->GetError() )
519cdf0e10cSrcweir 				throw io::IOException(); // TODO
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 			xOutputStream->closeOutput();
522cdf0e10cSrcweir 			xSeekable->seek( 0 );
523cdf0e10cSrcweir 		}
524cdf0e10cSrcweir 		catch( uno::RuntimeException& )
525cdf0e10cSrcweir 		{
526cdf0e10cSrcweir 			DELETEZ( pStream );
527cdf0e10cSrcweir 			throw;
528cdf0e10cSrcweir 		}
529cdf0e10cSrcweir 		catch( uno::Exception& )
530cdf0e10cSrcweir 		{
531cdf0e10cSrcweir 			DELETEZ( pStream );
532cdf0e10cSrcweir 			throw lang::WrappedTargetException(); // TODO:
533cdf0e10cSrcweir 		}
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 		DELETEZ( pStream );
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 		aResult <<= xInputStream;
538cdf0e10cSrcweir 	}
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	return aResult;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir // --------------------------------------------------------------------------------
getElementNames()544cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getElementNames()
545cdf0e10cSrcweir 		throw ( uno::RuntimeException )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	if ( m_bDisposed )
550cdf0e10cSrcweir 		throw lang::DisposedException();
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 	  if ( !m_pStorage )
553cdf0e10cSrcweir 		throw uno::RuntimeException();
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 	SvStorageInfoList aList;
556cdf0e10cSrcweir 	m_pStorage->FillInfoList( &aList );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 	if ( m_pStorage->GetError() )
559cdf0e10cSrcweir 	{
560cdf0e10cSrcweir 		m_pStorage->ResetError();
561cdf0e10cSrcweir 		throw uno::RuntimeException(); // TODO:
562cdf0e10cSrcweir 	}
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq( aList.Count() );
565cdf0e10cSrcweir 	for ( sal_uInt32 nInd = 0; nInd < aList.Count(); nInd++ )
566cdf0e10cSrcweir 		aSeq[nInd] = aList[nInd].GetName();
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 	return aSeq;
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir // --------------------------------------------------------------------------------
hasByName(const::rtl::OUString & aName)572cdf0e10cSrcweir sal_Bool SAL_CALL OLESimpleStorage::hasByName( const ::rtl::OUString& aName )
573cdf0e10cSrcweir 		throw ( uno::RuntimeException )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 	if ( m_bDisposed )
578cdf0e10cSrcweir 		throw lang::DisposedException();
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 	 if ( !m_pStorage )
581cdf0e10cSrcweir 		throw uno::RuntimeException();
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 	sal_Bool bResult = m_pStorage->IsContained( aName );
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	if ( m_pStorage->GetError() )
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir 		m_pStorage->ResetError();
588cdf0e10cSrcweir 		throw uno::RuntimeException(); // TODO:
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 	return bResult;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir // --------------------------------------------------------------------------------
getElementType()595cdf0e10cSrcweir uno::Type SAL_CALL OLESimpleStorage::getElementType()
596cdf0e10cSrcweir 		throw ( uno::RuntimeException )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	if ( m_bDisposed )
601cdf0e10cSrcweir 		throw lang::DisposedException();
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 	return getCppuType( (const uno::Reference< io::XInputStream >*)NULL );
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir // --------------------------------------------------------------------------------
hasElements()607cdf0e10cSrcweir sal_Bool SAL_CALL OLESimpleStorage::hasElements()
608cdf0e10cSrcweir 		throw ( uno::RuntimeException )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 	if ( m_bDisposed )
613cdf0e10cSrcweir 		throw lang::DisposedException();
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	  if ( !m_pStorage )
616cdf0e10cSrcweir 		throw uno::RuntimeException();
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	SvStorageInfoList aList;
619cdf0e10cSrcweir 	m_pStorage->FillInfoList( &aList );
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 	if ( m_pStorage->GetError() )
622cdf0e10cSrcweir 	{
623cdf0e10cSrcweir 		m_pStorage->ResetError();
624cdf0e10cSrcweir 		throw uno::RuntimeException(); // TODO:
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 	return ( aList.Count() != 0 );
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
630cdf0e10cSrcweir //____________________________________________________________________________________________________
631cdf0e10cSrcweir //	XComponent
632cdf0e10cSrcweir //____________________________________________________________________________________________________
633cdf0e10cSrcweir 
634cdf0e10cSrcweir // --------------------------------------------------------------------------------
dispose()635cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::dispose()
636cdf0e10cSrcweir 		throw ( uno::RuntimeException )
637cdf0e10cSrcweir {
638cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 	if ( m_bDisposed )
641cdf0e10cSrcweir 		throw lang::DisposedException();
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	if ( m_pListenersContainer )
644cdf0e10cSrcweir 	{
645cdf0e10cSrcweir    		lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
646cdf0e10cSrcweir 		m_pListenersContainer->disposeAndClear( aSource );
647cdf0e10cSrcweir 	}
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 	DELETEZ( m_pStorage );
650cdf0e10cSrcweir 	DELETEZ( m_pStream );
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 	m_xStream = uno::Reference< io::XStream >();
653cdf0e10cSrcweir 	m_xTempStream = uno::Reference< io::XStream >();
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 	m_bDisposed = sal_True;
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir // --------------------------------------------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)659cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::addEventListener(
660cdf0e10cSrcweir 			const uno::Reference< lang::XEventListener >& xListener )
661cdf0e10cSrcweir 		throw ( uno::RuntimeException )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
664cdf0e10cSrcweir 
665cdf0e10cSrcweir 	if ( m_bDisposed )
666cdf0e10cSrcweir 		throw lang::DisposedException();
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 	if ( !m_pListenersContainer )
669cdf0e10cSrcweir 		m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 	m_pListenersContainer->addInterface( xListener );
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir // --------------------------------------------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)675cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::removeEventListener(
676cdf0e10cSrcweir 			const uno::Reference< lang::XEventListener >& xListener )
677cdf0e10cSrcweir 		throw ( uno::RuntimeException )
678cdf0e10cSrcweir {
679cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 	if ( m_bDisposed )
682cdf0e10cSrcweir 		throw lang::DisposedException();
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 	if ( m_pListenersContainer )
685cdf0e10cSrcweir 		m_pListenersContainer->removeInterface( xListener );
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir //____________________________________________________________________________________________________
689cdf0e10cSrcweir //	XTransactedObject
690cdf0e10cSrcweir //____________________________________________________________________________________________________
691cdf0e10cSrcweir 
692cdf0e10cSrcweir // --------------------------------------------------------------------------------
commit()693cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::commit()
694cdf0e10cSrcweir 		throw ( ::com::sun::star::io::IOException,
695cdf0e10cSrcweir 				::com::sun::star::lang::WrappedTargetException,
696cdf0e10cSrcweir 				::com::sun::star::uno::RuntimeException )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	if ( m_bDisposed )
701cdf0e10cSrcweir 		throw lang::DisposedException();
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 	 if ( !m_pStorage )
704cdf0e10cSrcweir 		throw uno::RuntimeException();
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 	if ( !m_bNoTemporaryCopy && !m_xStream.is() )
707cdf0e10cSrcweir 		throw io::IOException(); // TODO
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	if ( !m_pStorage->Commit() || m_pStorage->GetError() )
710cdf0e10cSrcweir 	{
711cdf0e10cSrcweir 		m_pStorage->ResetError();
712cdf0e10cSrcweir 		throw io::IOException(); // TODO
713cdf0e10cSrcweir 	}
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 	UpdateOriginal_Impl();
716cdf0e10cSrcweir }
717cdf0e10cSrcweir 
718cdf0e10cSrcweir // --------------------------------------------------------------------------------
revert()719cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::revert()
720cdf0e10cSrcweir 		throw ( ::com::sun::star::io::IOException,
721cdf0e10cSrcweir 				::com::sun::star::lang::WrappedTargetException,
722cdf0e10cSrcweir 				::com::sun::star::uno::RuntimeException )
723cdf0e10cSrcweir {
724cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	if ( m_bDisposed )
727cdf0e10cSrcweir 		throw lang::DisposedException();
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 	 if ( !m_pStorage )
730cdf0e10cSrcweir 		throw uno::RuntimeException();
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 	if ( !m_bNoTemporaryCopy && !m_xStream.is() )
733cdf0e10cSrcweir 		throw io::IOException(); // TODO
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 	if ( !m_pStorage->Revert() || m_pStorage->GetError() )
736cdf0e10cSrcweir 	{
737cdf0e10cSrcweir 		m_pStorage->ResetError();
738cdf0e10cSrcweir 		throw io::IOException(); // TODO
739cdf0e10cSrcweir 	}
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 	UpdateOriginal_Impl();
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir //____________________________________________________________________________________________________
745cdf0e10cSrcweir //	XClassifiedObject
746cdf0e10cSrcweir //____________________________________________________________________________________________________
747cdf0e10cSrcweir 
getClassID()748cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL OLESimpleStorage::getClassID()
749cdf0e10cSrcweir 	throw ( uno::RuntimeException )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
752cdf0e10cSrcweir 
753cdf0e10cSrcweir 	if ( m_bDisposed )
754cdf0e10cSrcweir 		throw lang::DisposedException();
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 	if ( !m_pStorage )
757cdf0e10cSrcweir 		throw uno::RuntimeException();
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 	return m_pStorage->GetClassName().GetByteSequence();
760cdf0e10cSrcweir }
761cdf0e10cSrcweir 
getClassName()762cdf0e10cSrcweir ::rtl::OUString SAL_CALL OLESimpleStorage::getClassName()
763cdf0e10cSrcweir 	throw ( uno::RuntimeException )
764cdf0e10cSrcweir {
765cdf0e10cSrcweir 	return ::rtl::OUString();
766cdf0e10cSrcweir }
767cdf0e10cSrcweir 
setClassInfo(const uno::Sequence<sal_Int8> &,const::rtl::OUString &)768cdf0e10cSrcweir void SAL_CALL OLESimpleStorage::setClassInfo( const uno::Sequence< sal_Int8 >& /*aClassID*/,
769cdf0e10cSrcweir 							const ::rtl::OUString& /*sClassName*/ )
770cdf0e10cSrcweir 		throw ( lang::NoSupportException,
771cdf0e10cSrcweir 				uno::RuntimeException )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir 	throw lang::NoSupportException();
774cdf0e10cSrcweir }
775cdf0e10cSrcweir 
776cdf0e10cSrcweir //____________________________________________________________________________________________________
777cdf0e10cSrcweir //	XServiceInfo
778cdf0e10cSrcweir //____________________________________________________________________________________________________
779cdf0e10cSrcweir 
780cdf0e10cSrcweir // --------------------------------------------------------------------------------
getImplementationName()781cdf0e10cSrcweir ::rtl::OUString SAL_CALL OLESimpleStorage::getImplementationName()
782cdf0e10cSrcweir 		throw ( uno::RuntimeException )
783cdf0e10cSrcweir {
784cdf0e10cSrcweir 	return impl_staticGetImplementationName();
785cdf0e10cSrcweir }
786cdf0e10cSrcweir 
787cdf0e10cSrcweir // --------------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)788cdf0e10cSrcweir ::sal_Bool SAL_CALL OLESimpleStorage::supportsService( const ::rtl::OUString& ServiceName )
789cdf0e10cSrcweir 		throw ( uno::RuntimeException )
790cdf0e10cSrcweir {
791cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
794cdf0e10cSrcweir     	if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
795cdf0e10cSrcweir         	return sal_True;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 	return sal_False;
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir // --------------------------------------------------------------------------------
getSupportedServiceNames()801cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getSupportedServiceNames()
802cdf0e10cSrcweir 		throw ( uno::RuntimeException )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir 	return impl_staticGetSupportedServiceNames();
805cdf0e10cSrcweir }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 
808