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