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 throw ( uno::Exception )
128 {
129 if ( !pStorage || !aName.getLength() || !xInputStream.is() )
130 throw uno::RuntimeException();
131
132 if ( pStorage->IsContained( aName ) )
133 throw container::ElementExistException(); // TODO:
134
135 BaseStorageStream* pNewStream = pStorage->OpenStream( aName );
136 if ( !pNewStream || pNewStream->GetError() || pStorage->GetError() )
137 {
138 if ( pNewStream )
139 DELETEZ( pNewStream );
140 pStorage->ResetError();
141 throw io::IOException(); // TODO
142 }
143
144 try
145 {
146 uno::Sequence< sal_Int8 > aData( nBytesCount );
147 sal_Int32 nRead = 0;
148 do
149 {
150 nRead = xInputStream->readBytes( aData, nBytesCount );
151 if ( nRead < nBytesCount )
152 aData.realloc( nRead );
153
154 sal_Int32 nWritten = pNewStream->Write( aData.getArray(), nRead );
155 if ( nWritten < nRead )
156 throw io::IOException();
157 } while( nRead == nBytesCount );
158 }
159 catch( uno::Exception& )
160 {
161 DELETEZ( pNewStream );
162 pStorage->Remove( aName );
163
164 throw;
165 }
166
167 DELETEZ( pNewStream );
168 }
169
170 //-------------------------------------------------------------------------
InsertNameAccessToStorage_Impl(BaseStorage * pStorage,::rtl::OUString aName,const uno::Reference<container::XNameAccess> & xNameAccess)171 void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< container::XNameAccess >& xNameAccess )
172 throw ( uno::Exception )
173 {
174 if ( !pStorage || !aName.getLength() || !xNameAccess.is() )
175 throw uno::RuntimeException();
176
177 if ( pStorage->IsContained( aName ) )
178 throw container::ElementExistException(); // TODO:
179
180 BaseStorage* pNewStorage = pStorage->OpenStorage( aName );
181 if ( !pNewStorage || pNewStorage->GetError() || pStorage->GetError() )
182 {
183 if ( pNewStorage )
184 DELETEZ( pNewStorage );
185 pStorage->ResetError();
186 throw io::IOException(); // TODO
187 }
188
189 try
190 {
191 uno::Sequence< ::rtl::OUString > aElements = xNameAccess->getElementNames();
192 for ( sal_Int32 nInd = 0; nInd < aElements.getLength(); nInd++ )
193 {
194 uno::Reference< io::XInputStream > xInputStream;
195 uno::Reference< container::XNameAccess > xSubNameAccess;
196 uno::Any aAny = xNameAccess->getByName( aElements[nInd] );
197 if ( aAny >>= xInputStream )
198 InsertInputStreamToStorage_Impl( pNewStorage, aElements[nInd], xInputStream );
199 else if ( aAny >>= xSubNameAccess )
200 InsertNameAccessToStorage_Impl( pNewStorage, aElements[nInd], xSubNameAccess );
201 }
202 }
203 catch( uno::Exception& )
204 {
205 DELETEZ( pNewStorage );
206 pStorage->Remove( aName );
207
208 throw;
209 }
210
211 DELETEZ( pNewStorage );
212 }
213
214 //____________________________________________________________________________________________________
215 // XInitialization
216 //____________________________________________________________________________________________________
217
initialize(const uno::Sequence<uno::Any> & aArguments)218 void SAL_CALL OLESimpleStorage::initialize( const uno::Sequence< uno::Any >& aArguments )
219 throw ( uno::Exception,
220 uno::RuntimeException)
221 {
222 if ( m_pStream || m_pStorage )
223 throw io::IOException(); // TODO: already initilized
224
225 sal_Int32 nArgNum = aArguments.getLength();
226 OSL_ENSURE( nArgNum >= 1 && nArgNum <= 2, "Wrong parameter number" );
227
228 if ( nArgNum < 1 || nArgNum > 2 )
229 throw lang::IllegalArgumentException(); // TODO:
230
231 uno::Reference< io::XStream > xStream;
232 uno::Reference< io::XInputStream > xInputStream;
233 if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) )
234 throw lang::IllegalArgumentException(); // TODO:
235
236 if ( nArgNum == 2 )
237 {
238 if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) )
239 throw lang::IllegalArgumentException(); // TODO:
240 }
241
242 if ( m_bNoTemporaryCopy )
243 {
244 // TODO: ???
245 // If the temporary stream is not created, the original stream must be wrapped
246 // since SvStream wrapper closes the stream is owns
247 if ( xInputStream.is() )
248 {
249 // the stream must be seekable for direct access
250 uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
251 m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, sal_False );
252 }
253 else if ( xStream.is() )
254 {
255 // the stream must be seekable for direct access
256 uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
257 m_pStream = ::utl::UcbStreamHelper::CreateStream( xStream, sal_False );
258 }
259 else
260 throw lang::IllegalArgumentException(); // TODO:
261 }
262 else
263 {
264 uno::Reference < io::XStream > xTempFile(
265 m_xContext->getServiceManager()->createInstanceWithContext( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ), m_xContext ),
266 uno::UNO_QUERY_THROW );
267 uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
268 uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream();
269 if ( !xTempOut.is() )
270 throw uno::RuntimeException();
271
272 if ( xInputStream.is() )
273 {
274 try
275 {
276 uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
277 xSeek->seek( 0 );
278 }
279 catch( uno::Exception& )
280 {}
281
282 ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut );
283 xTempOut->closeOutput();
284 xTempSeek->seek( 0 );
285 uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream();
286 m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempInput, sal_False );
287 }
288 else if ( xStream.is() )
289 {
290 // not sure that the storage flashes the stream on commit
291 m_xStream = xStream;
292 m_xTempStream = xTempFile;
293
294 uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
295 xSeek->seek( 0 );
296 uno::Reference< io::XInputStream > xInpStream = xStream->getInputStream();
297 if ( !xInpStream.is() || !xStream->getOutputStream().is() )
298 throw uno::RuntimeException();
299
300 ::comphelper::OStorageHelper::CopyInputToOutput( xInpStream, xTempOut );
301 xTempOut->flush();
302 xTempSeek->seek( 0 );
303
304 m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False );
305 }
306 else
307 throw lang::IllegalArgumentException(); // TODO:
308 }
309
310 if ( !m_pStream || m_pStream->GetError() )
311 throw io::IOException(); // TODO
312
313 m_pStorage = new Storage( *m_pStream, sal_False );
314 }
315
316
317 //____________________________________________________________________________________________________
318 // XNameContainer
319 //____________________________________________________________________________________________________
320
321 // --------------------------------------------------------------------------------
insertByName(const::rtl::OUString & aName,const uno::Any & aElement)322 void SAL_CALL OLESimpleStorage::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement )
323 throw ( lang::IllegalArgumentException,
324 container::ElementExistException,
325 lang::WrappedTargetException,
326 uno::RuntimeException)
327 {
328 ::osl::MutexGuard aGuard( m_aMutex );
329
330 if ( m_bDisposed )
331 throw lang::DisposedException();
332
333 if ( !m_pStorage )
334 throw uno::RuntimeException();
335
336 uno::Reference< io::XStream > xStream;
337 uno::Reference< io::XInputStream > xInputStream;
338 uno::Reference< container::XNameAccess > xNameAccess;
339
340 try
341 {
342 if ( !m_bNoTemporaryCopy && !m_xStream.is() )
343 throw io::IOException(); // TODO
344
345 if ( aElement >>= xStream )
346 xInputStream = xStream->getInputStream();
347 else if ( !( aElement >>= xInputStream ) && !( aElement >>= xNameAccess ) )
348 throw lang::IllegalArgumentException(); // TODO:
349
350 if ( xInputStream.is() )
351 InsertInputStreamToStorage_Impl( m_pStorage, aName, xInputStream );
352 else if ( xNameAccess.is() )
353 InsertNameAccessToStorage_Impl( m_pStorage, aName, xNameAccess );
354 else
355 throw uno::RuntimeException();
356 }
357 catch( uno::RuntimeException& )
358 {
359 throw;
360 }
361 catch( container::ElementExistException& )
362 {
363 throw;
364 }
365 catch( uno::Exception& e )
366 {
367 throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Insert has failed!" ) ),
368 uno::Reference< uno::XInterface >(),
369 uno::makeAny( e ) );
370 }
371 }
372
373 // --------------------------------------------------------------------------------
removeByName(const::rtl::OUString & aName)374 void SAL_CALL OLESimpleStorage::removeByName( const ::rtl::OUString& aName )
375 throw ( container::NoSuchElementException,
376 lang::WrappedTargetException,
377 uno::RuntimeException)
378 {
379 ::osl::MutexGuard aGuard( m_aMutex );
380
381 if ( m_bDisposed )
382 throw lang::DisposedException();
383
384 if ( !m_pStorage )
385 throw uno::RuntimeException();
386
387 if ( !m_bNoTemporaryCopy && !m_xStream.is() )
388 throw lang::WrappedTargetException(); // io::IOException(); // TODO
389
390 if ( !m_pStorage->IsContained( aName ) )
391 throw container::NoSuchElementException(); // TODO:
392
393 m_pStorage->Remove( aName );
394
395 if ( m_pStorage->GetError() )
396 {
397 m_pStorage->ResetError();
398 throw lang::WrappedTargetException(); // io::IOException(); // TODO
399 }
400 }
401
402 // --------------------------------------------------------------------------------
replaceByName(const::rtl::OUString & aName,const uno::Any & aElement)403 void SAL_CALL OLESimpleStorage::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
404 throw ( lang::IllegalArgumentException,
405 container::NoSuchElementException,
406 lang::WrappedTargetException,
407 uno::RuntimeException)
408 {
409 ::osl::MutexGuard aGuard( m_aMutex );
410
411 if ( m_bDisposed )
412 throw lang::DisposedException();
413
414 removeByName( aName );
415
416 try
417 {
418 insertByName( aName, aElement );
419 }
420 catch( container::ElementExistException& )
421 {
422 uno::Any aCaught( ::cppu::getCaughtException() );
423
424 throw lang::WrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
425 uno::Reference< uno::XInterface >(),
426 aCaught );
427 }
428 }
429
430 // --------------------------------------------------------------------------------
getByName(const::rtl::OUString & aName)431 uno::Any SAL_CALL OLESimpleStorage::getByName( const ::rtl::OUString& aName )
432 throw ( container::NoSuchElementException,
433 lang::WrappedTargetException,
434 uno::RuntimeException )
435 {
436 ::osl::MutexGuard aGuard( m_aMutex );
437
438 if ( m_bDisposed )
439 throw lang::DisposedException();
440
441 if ( !m_pStorage )
442 throw uno::RuntimeException();
443
444 if ( !m_pStorage->IsContained( aName ) )
445 throw container::NoSuchElementException(); // TODO:
446
447 uno::Any aResult;
448
449 uno::Reference< io::XStream > xTempFile(
450 m_xContext->getServiceManager()->createInstanceWithContext( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ), m_xContext ),
451 uno::UNO_QUERY );
452 uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW );
453 uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream();
454 uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream();
455 if ( !xOutputStream.is() || !xInputStream.is() )
456 throw uno::RuntimeException();
457
458 if ( m_pStorage->IsStorage( aName ) )
459 {
460 BaseStorage* pStrg = m_pStorage->OpenStorage( aName );
461 m_pStorage->ResetError();
462 if ( !pStrg )
463 throw io::IOException();
464
465 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False ); // do not close the original stream
466 if ( !pStream )
467 throw uno::RuntimeException();
468
469 BaseStorage* pNewStor = new Storage( *pStream, sal_False );
470 sal_Bool bSuccess =
471 ( pStrg->CopyTo( pNewStor ) && pNewStor->Commit() && !pNewStor->GetError() && !pStrg->GetError() );
472
473 DELETEZ( pNewStor );
474 DELETEZ( pStrg );
475 DELETEZ( pStream );
476
477 if ( !bSuccess )
478 throw uno::RuntimeException();
479
480 uno::Sequence< uno::Any > aArgs( 2 );
481 aArgs[0] <<= xInputStream; // allow readonly access only
482 aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
483
484 uno::Reference< container::XNameContainer > xResultNameContainer(
485 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
486 ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ),
487 aArgs,
488 m_xContext ),
489 uno::UNO_QUERY_THROW );
490
491 aResult <<= xResultNameContainer;
492 }
493 else
494 {
495 BaseStorageStream* pStream = m_pStorage->OpenStream( aName, STREAM_READ | STREAM_SHARE_DENYALL | STREAM_NOCREATE );
496 if ( !pStream || pStream->GetError() || m_pStorage->GetError() )
497 {
498 m_pStorage->ResetError();
499 DELETEZ( pStream );
500 throw io::IOException(); // TODO
501 }
502
503 try
504 {
505 uno::Sequence< sal_Int8 > aData( nBytesCount );
506 sal_Int32 nSize = nBytesCount;
507 sal_Int32 nRead = 0;
508 while( 0 != ( nRead = pStream->Read( aData.getArray(), nSize ) ) )
509 {
510 if ( nRead < nSize )
511 {
512 nSize = nRead;
513 aData.realloc( nSize );
514 }
515
516 xOutputStream->writeBytes( aData );
517 }
518
519 if ( pStream->GetError() )
520 throw io::IOException(); // TODO
521
522 xOutputStream->closeOutput();
523 xSeekable->seek( 0 );
524 }
525 catch( uno::RuntimeException& )
526 {
527 DELETEZ( pStream );
528 throw;
529 }
530 catch( uno::Exception& )
531 {
532 DELETEZ( pStream );
533 throw lang::WrappedTargetException(); // TODO:
534 }
535
536 DELETEZ( pStream );
537
538 aResult <<= xInputStream;
539 }
540
541 return aResult;
542 }
543
544 // --------------------------------------------------------------------------------
getElementNames()545 uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getElementNames()
546 throw ( uno::RuntimeException )
547 {
548 ::osl::MutexGuard aGuard( m_aMutex );
549
550 if ( m_bDisposed )
551 throw lang::DisposedException();
552
553 if ( !m_pStorage )
554 throw uno::RuntimeException();
555
556 SvStorageInfoList aList;
557 m_pStorage->FillInfoList( &aList );
558
559 if ( m_pStorage->GetError() )
560 {
561 m_pStorage->ResetError();
562 throw uno::RuntimeException(); // TODO:
563 }
564
565 uno::Sequence< ::rtl::OUString > aSeq( aList.Count() );
566 for ( sal_uInt32 nInd = 0; nInd < aList.Count(); nInd++ )
567 aSeq[nInd] = aList[nInd].GetName();
568
569 return aSeq;
570 }
571
572 // --------------------------------------------------------------------------------
hasByName(const::rtl::OUString & aName)573 sal_Bool SAL_CALL OLESimpleStorage::hasByName( const ::rtl::OUString& aName )
574 throw ( uno::RuntimeException )
575 {
576 ::osl::MutexGuard aGuard( m_aMutex );
577
578 if ( m_bDisposed )
579 throw lang::DisposedException();
580
581 if ( !m_pStorage )
582 throw uno::RuntimeException();
583
584 sal_Bool bResult = m_pStorage->IsContained( aName );
585
586 if ( m_pStorage->GetError() )
587 {
588 m_pStorage->ResetError();
589 throw uno::RuntimeException(); // TODO:
590 }
591
592 return bResult;
593 }
594
595 // --------------------------------------------------------------------------------
getElementType()596 uno::Type SAL_CALL OLESimpleStorage::getElementType()
597 throw ( uno::RuntimeException )
598 {
599 ::osl::MutexGuard aGuard( m_aMutex );
600
601 if ( m_bDisposed )
602 throw lang::DisposedException();
603
604 return getCppuType( (const uno::Reference< io::XInputStream >*)NULL );
605 }
606
607 // --------------------------------------------------------------------------------
hasElements()608 sal_Bool SAL_CALL OLESimpleStorage::hasElements()
609 throw ( uno::RuntimeException )
610 {
611 ::osl::MutexGuard aGuard( m_aMutex );
612
613 if ( m_bDisposed )
614 throw lang::DisposedException();
615
616 if ( !m_pStorage )
617 throw uno::RuntimeException();
618
619 SvStorageInfoList aList;
620 m_pStorage->FillInfoList( &aList );
621
622 if ( m_pStorage->GetError() )
623 {
624 m_pStorage->ResetError();
625 throw uno::RuntimeException(); // TODO:
626 }
627
628 return ( aList.Count() != 0 );
629 }
630
631 //____________________________________________________________________________________________________
632 // XComponent
633 //____________________________________________________________________________________________________
634
635 // --------------------------------------------------------------------------------
dispose()636 void SAL_CALL OLESimpleStorage::dispose()
637 throw ( uno::RuntimeException )
638 {
639 ::osl::MutexGuard aGuard( m_aMutex );
640
641 if ( m_bDisposed )
642 throw lang::DisposedException();
643
644 if ( m_pListenersContainer )
645 {
646 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
647 m_pListenersContainer->disposeAndClear( aSource );
648 }
649
650 DELETEZ( m_pStorage );
651 DELETEZ( m_pStream );
652
653 m_xStream = uno::Reference< io::XStream >();
654 m_xTempStream = uno::Reference< io::XStream >();
655
656 m_bDisposed = sal_True;
657 }
658
659 // --------------------------------------------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)660 void SAL_CALL OLESimpleStorage::addEventListener(
661 const uno::Reference< lang::XEventListener >& xListener )
662 throw ( uno::RuntimeException )
663 {
664 ::osl::MutexGuard aGuard( m_aMutex );
665
666 if ( m_bDisposed )
667 throw lang::DisposedException();
668
669 if ( !m_pListenersContainer )
670 m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
671
672 m_pListenersContainer->addInterface( xListener );
673 }
674
675 // --------------------------------------------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)676 void SAL_CALL OLESimpleStorage::removeEventListener(
677 const uno::Reference< lang::XEventListener >& xListener )
678 throw ( uno::RuntimeException )
679 {
680 ::osl::MutexGuard aGuard( m_aMutex );
681
682 if ( m_bDisposed )
683 throw lang::DisposedException();
684
685 if ( m_pListenersContainer )
686 m_pListenersContainer->removeInterface( xListener );
687 }
688
689 //____________________________________________________________________________________________________
690 // XTransactedObject
691 //____________________________________________________________________________________________________
692
693 // --------------------------------------------------------------------------------
commit()694 void SAL_CALL OLESimpleStorage::commit()
695 throw ( ::com::sun::star::io::IOException,
696 ::com::sun::star::lang::WrappedTargetException,
697 ::com::sun::star::uno::RuntimeException )
698 {
699 ::osl::MutexGuard aGuard( m_aMutex );
700
701 if ( m_bDisposed )
702 throw lang::DisposedException();
703
704 if ( !m_pStorage )
705 throw uno::RuntimeException();
706
707 if ( !m_bNoTemporaryCopy && !m_xStream.is() )
708 throw io::IOException(); // TODO
709
710 if ( !m_pStorage->Commit() || m_pStorage->GetError() )
711 {
712 m_pStorage->ResetError();
713 throw io::IOException(); // TODO
714 }
715
716 UpdateOriginal_Impl();
717 }
718
719 // --------------------------------------------------------------------------------
revert()720 void SAL_CALL OLESimpleStorage::revert()
721 throw ( ::com::sun::star::io::IOException,
722 ::com::sun::star::lang::WrappedTargetException,
723 ::com::sun::star::uno::RuntimeException )
724 {
725 ::osl::MutexGuard aGuard( m_aMutex );
726
727 if ( m_bDisposed )
728 throw lang::DisposedException();
729
730 if ( !m_pStorage )
731 throw uno::RuntimeException();
732
733 if ( !m_bNoTemporaryCopy && !m_xStream.is() )
734 throw io::IOException(); // TODO
735
736 if ( !m_pStorage->Revert() || m_pStorage->GetError() )
737 {
738 m_pStorage->ResetError();
739 throw io::IOException(); // TODO
740 }
741
742 UpdateOriginal_Impl();
743 }
744
745 //____________________________________________________________________________________________________
746 // XClassifiedObject
747 //____________________________________________________________________________________________________
748
getClassID()749 uno::Sequence< sal_Int8 > SAL_CALL OLESimpleStorage::getClassID()
750 throw ( uno::RuntimeException )
751 {
752 ::osl::MutexGuard aGuard( m_aMutex );
753
754 if ( m_bDisposed )
755 throw lang::DisposedException();
756
757 if ( !m_pStorage )
758 throw uno::RuntimeException();
759
760 return m_pStorage->GetClassName().GetByteSequence();
761 }
762
getClassName()763 ::rtl::OUString SAL_CALL OLESimpleStorage::getClassName()
764 throw ( uno::RuntimeException )
765 {
766 return ::rtl::OUString();
767 }
768
setClassInfo(const uno::Sequence<sal_Int8> &,const::rtl::OUString &)769 void SAL_CALL OLESimpleStorage::setClassInfo( const uno::Sequence< sal_Int8 >& /*aClassID*/,
770 const ::rtl::OUString& /*sClassName*/ )
771 throw ( lang::NoSupportException,
772 uno::RuntimeException )
773 {
774 throw lang::NoSupportException();
775 }
776
777 //____________________________________________________________________________________________________
778 // XServiceInfo
779 //____________________________________________________________________________________________________
780
781 // --------------------------------------------------------------------------------
getImplementationName()782 ::rtl::OUString SAL_CALL OLESimpleStorage::getImplementationName()
783 throw ( uno::RuntimeException )
784 {
785 return impl_staticGetImplementationName();
786 }
787
788 // --------------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)789 ::sal_Bool SAL_CALL OLESimpleStorage::supportsService( const ::rtl::OUString& ServiceName )
790 throw ( uno::RuntimeException )
791 {
792 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
793
794 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
795 if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
796 return sal_True;
797
798 return sal_False;
799 }
800
801 // --------------------------------------------------------------------------------
getSupportedServiceNames()802 uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getSupportedServiceNames()
803 throw ( uno::RuntimeException )
804 {
805 return impl_staticGetSupportedServiceNames();
806 }
807