1*2f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2f86921cSAndrew Rist * distributed with this work for additional information 6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance 9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2f86921cSAndrew Rist * software distributed under the License is distributed on an 15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the 17*2f86921cSAndrew Rist * specific language governing permissions and limitations 18*2f86921cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2f86921cSAndrew Rist *************************************************************/ 21*2f86921cSAndrew Rist 22*2f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir /************************************************************************** 28cdf0e10cSrcweir TODO 29cdf0e10cSrcweir ************************************************************************** 30cdf0e10cSrcweir 31cdf0e10cSrcweir - remove root storage access workaround 32cdf0e10cSrcweir 33cdf0e10cSrcweir *************************************************************************/ 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include "com/sun/star/lang/DisposedException.hpp" 36cdf0e10cSrcweir #include "com/sun/star/reflection/XProxyFactory.hpp" 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "tdoc_uri.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "tdoc_stgelems.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace com::sun::star; 43cdf0e10cSrcweir using namespace tdoc_ucp; 44cdf0e10cSrcweir 45cdf0e10cSrcweir //========================================================================= 46cdf0e10cSrcweir //========================================================================= 47cdf0e10cSrcweir // 48cdf0e10cSrcweir // ParentStorageHolder Implementation. 49cdf0e10cSrcweir // 50cdf0e10cSrcweir //========================================================================= 51cdf0e10cSrcweir //========================================================================= 52cdf0e10cSrcweir 53cdf0e10cSrcweir ParentStorageHolder::ParentStorageHolder( 54cdf0e10cSrcweir const uno::Reference< embed::XStorage > & xParentStorage, 55cdf0e10cSrcweir const rtl::OUString & rUri ) 56cdf0e10cSrcweir : m_xParentStorage( xParentStorage ), 57cdf0e10cSrcweir m_bParentIsRootStorage( false ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir Uri aUri( rUri ); 60cdf0e10cSrcweir if ( aUri.isDocument() ) 61cdf0e10cSrcweir m_bParentIsRootStorage = true; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir //========================================================================= 65cdf0e10cSrcweir //========================================================================= 66cdf0e10cSrcweir // 67cdf0e10cSrcweir // Storage Implementation. 68cdf0e10cSrcweir // 69cdf0e10cSrcweir //========================================================================= 70cdf0e10cSrcweir //========================================================================= 71cdf0e10cSrcweir 72cdf0e10cSrcweir Storage::Storage( const uno::Reference< lang::XMultiServiceFactory > & xSMgr, 73cdf0e10cSrcweir const rtl::Reference< StorageElementFactory > & xFactory, 74cdf0e10cSrcweir const rtl::OUString & rUri, 75cdf0e10cSrcweir const uno::Reference< embed::XStorage > & xParentStorage, 76cdf0e10cSrcweir const uno::Reference< embed::XStorage > & xStorageToWrap ) 77cdf0e10cSrcweir : ParentStorageHolder( xParentStorage, Uri( rUri ).getParentUri() ), 78cdf0e10cSrcweir m_xFactory( xFactory ), 79cdf0e10cSrcweir m_xWrappedStorage( xStorageToWrap ), 80cdf0e10cSrcweir m_xWrappedTransObj( xStorageToWrap, uno::UNO_QUERY ), // optional interface 81cdf0e10cSrcweir m_xWrappedComponent( xStorageToWrap, uno::UNO_QUERY ), 82cdf0e10cSrcweir m_xWrappedTypeProv( xStorageToWrap, uno::UNO_QUERY ), 83cdf0e10cSrcweir m_bIsDocumentStorage( Uri( rUri ).isDocument() ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir OSL_ENSURE( m_xWrappedStorage.is(), 86cdf0e10cSrcweir "Storage::Storage: No storage to wrap!" ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir OSL_ENSURE( m_xWrappedComponent.is(), 89cdf0e10cSrcweir "Storage::Storage: No component to wrap!" ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir OSL_ENSURE( m_xWrappedTypeProv.is(), 92cdf0e10cSrcweir "Storage::Storage: No Type Provider!" ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // Use proxy factory service to create aggregatable proxy. 95cdf0e10cSrcweir try 96cdf0e10cSrcweir { 97cdf0e10cSrcweir uno::Reference< reflection::XProxyFactory > xProxyFac( 98cdf0e10cSrcweir xSMgr->createInstance( 99cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 100cdf0e10cSrcweir "com.sun.star.reflection.ProxyFactory" ) ) ), 101cdf0e10cSrcweir uno::UNO_QUERY ); 102cdf0e10cSrcweir if ( xProxyFac.is() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_xAggProxy = xProxyFac->createProxy( m_xWrappedStorage ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir catch ( uno::Exception const & ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir OSL_ENSURE( false, "Storage::Storage: Caught exception!" ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir OSL_ENSURE( m_xAggProxy.is(), 113cdf0e10cSrcweir "Storage::Storage: Wrapped storage cannot be aggregated!" ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir if ( m_xAggProxy.is() ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 118cdf0e10cSrcweir { 119cdf0e10cSrcweir // Solaris compiler problem: 120cdf0e10cSrcweir // Extra block to enforce destruction of temporary object created 121cdf0e10cSrcweir // in next statement _before_ osl_decrementInterlockedCount is 122cdf0e10cSrcweir // called. Otherwise 'this' will destroy itself even before ctor 123cdf0e10cSrcweir // is completed (See impl. of XInterface::release())! 124cdf0e10cSrcweir 125cdf0e10cSrcweir m_xAggProxy->setDelegator( 126cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir //========================================================================= 133cdf0e10cSrcweir // virtual 134cdf0e10cSrcweir Storage::~Storage() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir if ( m_xAggProxy.is() ) 137cdf0e10cSrcweir m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir // Never dispose a document storage. Not owner! 140cdf0e10cSrcweir if ( !isDocumentStorage() ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir if ( m_xWrappedComponent.is() ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir // "Auto-dispose"... 145cdf0e10cSrcweir try 146cdf0e10cSrcweir { 147cdf0e10cSrcweir m_xWrappedComponent->dispose(); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir catch ( lang::DisposedException const & ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir // might happen. 152cdf0e10cSrcweir } 153cdf0e10cSrcweir catch ( ... ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir OSL_ENSURE( false, "Storage::~Storage - Caught exception!" ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir //========================================================================= 162cdf0e10cSrcweir // 163cdf0e10cSrcweir // uno::XInterface 164cdf0e10cSrcweir // 165cdf0e10cSrcweir //========================================================================= 166cdf0e10cSrcweir 167cdf0e10cSrcweir // virtual 168cdf0e10cSrcweir uno::Any SAL_CALL Storage::queryInterface( const uno::Type& aType ) 169cdf0e10cSrcweir throw ( uno::RuntimeException ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir // First, try to use interfaces implemented by myself and base class(es) 172cdf0e10cSrcweir uno::Any aRet = StorageUNOBase::queryInterface( aType ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir if ( aRet.hasValue() ) 175cdf0e10cSrcweir return aRet; 176cdf0e10cSrcweir 177cdf0e10cSrcweir // Try to use requested interface from aggregated storage 178cdf0e10cSrcweir return m_xAggProxy->queryAggregation( aType ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir //========================================================================= 182cdf0e10cSrcweir // virtual 183cdf0e10cSrcweir void SAL_CALL Storage::acquire() 184cdf0e10cSrcweir throw () 185cdf0e10cSrcweir { 186cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir //========================================================================= 190cdf0e10cSrcweir // virtual 191cdf0e10cSrcweir void SAL_CALL Storage::release() 192cdf0e10cSrcweir throw () 193cdf0e10cSrcweir { 194cdf0e10cSrcweir if ( osl_decrementInterlockedCount( &m_refCount ) == 0 ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir m_xFactory->releaseElement( this ); 197cdf0e10cSrcweir delete this; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir //========================================================================= 202cdf0e10cSrcweir // 203cdf0e10cSrcweir // lang::XTypeProvider 204cdf0e10cSrcweir // 205cdf0e10cSrcweir //========================================================================= 206cdf0e10cSrcweir 207cdf0e10cSrcweir // virtual 208cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Storage::getTypes() 209cdf0e10cSrcweir throw ( uno::RuntimeException ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir return m_xWrappedTypeProv->getTypes(); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir //========================================================================= 215cdf0e10cSrcweir // virtual 216cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Storage::getImplementationId() 217cdf0e10cSrcweir throw ( uno::RuntimeException ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir return m_xWrappedTypeProv->getImplementationId(); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir //========================================================================= 223cdf0e10cSrcweir // 224cdf0e10cSrcweir // lang::XComponent (base of embed::XStorage) 225cdf0e10cSrcweir // 226cdf0e10cSrcweir //========================================================================= 227cdf0e10cSrcweir // virtual 228cdf0e10cSrcweir void SAL_CALL Storage::dispose() 229cdf0e10cSrcweir throw ( uno::RuntimeException ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir m_xWrappedStorage->dispose(); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir //========================================================================= 235cdf0e10cSrcweir // virtual 236cdf0e10cSrcweir void SAL_CALL Storage::addEventListener( 237cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 238cdf0e10cSrcweir throw ( uno::RuntimeException ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir m_xWrappedStorage->addEventListener( xListener ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir //========================================================================= 243cdf0e10cSrcweir // virtual 244cdf0e10cSrcweir void SAL_CALL Storage::removeEventListener( 245cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& aListener ) 246cdf0e10cSrcweir throw (uno::RuntimeException) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir m_xWrappedStorage->removeEventListener( aListener ); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir //========================================================================= 252cdf0e10cSrcweir // 253cdf0e10cSrcweir // container::XElementAccess (base of container::XNameAccess) 254cdf0e10cSrcweir // 255cdf0e10cSrcweir //========================================================================= 256cdf0e10cSrcweir 257cdf0e10cSrcweir // virtual 258cdf0e10cSrcweir uno::Type SAL_CALL Storage::getElementType() 259cdf0e10cSrcweir throw ( uno::RuntimeException ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir return m_xWrappedStorage->getElementType(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir //========================================================================= 265cdf0e10cSrcweir // virtual 266cdf0e10cSrcweir ::sal_Bool SAL_CALL Storage::hasElements() 267cdf0e10cSrcweir throw ( uno::RuntimeException ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir return m_xWrappedStorage->hasElements(); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir //========================================================================= 273cdf0e10cSrcweir // 274cdf0e10cSrcweir // container::XNameAccess (base of embed::XStorage) 275cdf0e10cSrcweir // 276cdf0e10cSrcweir //========================================================================= 277cdf0e10cSrcweir 278cdf0e10cSrcweir // virtual 279cdf0e10cSrcweir uno::Any SAL_CALL Storage::getByName( const ::rtl::OUString& aName ) 280cdf0e10cSrcweir throw ( container::NoSuchElementException, 281cdf0e10cSrcweir lang::WrappedTargetException, 282cdf0e10cSrcweir uno::RuntimeException ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir return m_xWrappedStorage->getByName( aName ); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir //========================================================================= 288cdf0e10cSrcweir // virtual 289cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL Storage::getElementNames() 290cdf0e10cSrcweir throw ( uno::RuntimeException ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir return m_xWrappedStorage->getElementNames(); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir //========================================================================= 296cdf0e10cSrcweir // virtual 297cdf0e10cSrcweir ::sal_Bool SAL_CALL Storage::hasByName( const ::rtl::OUString& aName ) 298cdf0e10cSrcweir throw ( uno::RuntimeException ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir return m_xWrappedStorage->hasByName( aName ); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir //========================================================================= 304cdf0e10cSrcweir // 305cdf0e10cSrcweir // embed::XStorage 306cdf0e10cSrcweir // 307cdf0e10cSrcweir //========================================================================= 308cdf0e10cSrcweir 309cdf0e10cSrcweir // virtual 310cdf0e10cSrcweir void SAL_CALL Storage::copyToStorage( 311cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest ) 312cdf0e10cSrcweir throw ( embed::InvalidStorageException, 313cdf0e10cSrcweir lang::IllegalArgumentException, 314cdf0e10cSrcweir io::IOException, 315cdf0e10cSrcweir embed::StorageWrappedTargetException, 316cdf0e10cSrcweir uno::RuntimeException ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir m_xWrappedStorage->copyToStorage( xDest ); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir //========================================================================= 322cdf0e10cSrcweir // virtual 323cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL Storage::openStreamElement( 324cdf0e10cSrcweir const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) 325cdf0e10cSrcweir throw ( embed::InvalidStorageException, 326cdf0e10cSrcweir lang::IllegalArgumentException, 327cdf0e10cSrcweir packages::WrongPasswordException, 328cdf0e10cSrcweir io::IOException, 329cdf0e10cSrcweir embed::StorageWrappedTargetException, 330cdf0e10cSrcweir uno::RuntimeException ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir return m_xWrappedStorage->openStreamElement( aStreamName, nOpenMode ); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir //========================================================================= 336cdf0e10cSrcweir // virtual 337cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL Storage::openEncryptedStreamElement( 338cdf0e10cSrcweir const ::rtl::OUString& aStreamName, 339cdf0e10cSrcweir sal_Int32 nOpenMode, 340cdf0e10cSrcweir const ::rtl::OUString& aPassword ) 341cdf0e10cSrcweir throw ( embed::InvalidStorageException, 342cdf0e10cSrcweir lang::IllegalArgumentException, 343cdf0e10cSrcweir packages::NoEncryptionException, 344cdf0e10cSrcweir packages::WrongPasswordException, 345cdf0e10cSrcweir io::IOException, 346cdf0e10cSrcweir embed::StorageWrappedTargetException, 347cdf0e10cSrcweir uno::RuntimeException ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir return m_xWrappedStorage->openEncryptedStreamElement( 350cdf0e10cSrcweir aStreamName, nOpenMode, aPassword ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir //========================================================================= 354cdf0e10cSrcweir // virtual 355cdf0e10cSrcweir uno::Reference< embed::XStorage > SAL_CALL Storage::openStorageElement( 356cdf0e10cSrcweir const ::rtl::OUString& aStorName, sal_Int32 nOpenMode ) 357cdf0e10cSrcweir throw ( embed::InvalidStorageException, 358cdf0e10cSrcweir lang::IllegalArgumentException, 359cdf0e10cSrcweir io::IOException, 360cdf0e10cSrcweir embed::StorageWrappedTargetException, 361cdf0e10cSrcweir uno::RuntimeException ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir return m_xWrappedStorage->openStorageElement( aStorName, nOpenMode ); 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir //========================================================================= 367cdf0e10cSrcweir // virtual 368cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL Storage::cloneStreamElement( 369cdf0e10cSrcweir const ::rtl::OUString& aStreamName ) 370cdf0e10cSrcweir throw ( embed::InvalidStorageException, 371cdf0e10cSrcweir lang::IllegalArgumentException, 372cdf0e10cSrcweir packages::WrongPasswordException, 373cdf0e10cSrcweir io::IOException, 374cdf0e10cSrcweir embed::StorageWrappedTargetException, 375cdf0e10cSrcweir uno::RuntimeException ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir return m_xWrappedStorage->cloneStreamElement( aStreamName ); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir //========================================================================= 381cdf0e10cSrcweir // virtual 382cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL Storage::cloneEncryptedStreamElement( 383cdf0e10cSrcweir const ::rtl::OUString& aStreamName, 384cdf0e10cSrcweir const ::rtl::OUString& aPassword ) 385cdf0e10cSrcweir throw ( embed::InvalidStorageException, 386cdf0e10cSrcweir lang::IllegalArgumentException, 387cdf0e10cSrcweir packages::NoEncryptionException, 388cdf0e10cSrcweir packages::WrongPasswordException, 389cdf0e10cSrcweir io::IOException, 390cdf0e10cSrcweir embed::StorageWrappedTargetException, 391cdf0e10cSrcweir uno::RuntimeException ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir return m_xWrappedStorage->cloneEncryptedStreamElement( aStreamName, 394cdf0e10cSrcweir aPassword ); 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir //========================================================================= 398cdf0e10cSrcweir // virtual 399cdf0e10cSrcweir void SAL_CALL Storage::copyLastCommitTo( 400cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xTargetStorage ) 401cdf0e10cSrcweir throw ( embed::InvalidStorageException, 402cdf0e10cSrcweir lang::IllegalArgumentException, 403cdf0e10cSrcweir io::IOException, 404cdf0e10cSrcweir embed::StorageWrappedTargetException, 405cdf0e10cSrcweir uno::RuntimeException) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir m_xWrappedStorage->copyLastCommitTo( xTargetStorage ); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir //========================================================================= 411cdf0e10cSrcweir // virtual 412cdf0e10cSrcweir void SAL_CALL Storage::copyStorageElementLastCommitTo( 413cdf0e10cSrcweir const ::rtl::OUString& aStorName, 414cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xTargetStorage ) 415cdf0e10cSrcweir throw ( embed::InvalidStorageException, 416cdf0e10cSrcweir lang::IllegalArgumentException, 417cdf0e10cSrcweir io::IOException, 418cdf0e10cSrcweir embed::StorageWrappedTargetException, 419cdf0e10cSrcweir uno::RuntimeException) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir m_xWrappedStorage->copyStorageElementLastCommitTo( aStorName, xTargetStorage ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir 424cdf0e10cSrcweir //========================================================================= 425cdf0e10cSrcweir // virtual 426cdf0e10cSrcweir sal_Bool SAL_CALL Storage::isStreamElement( 427cdf0e10cSrcweir const ::rtl::OUString& aElementName ) 428cdf0e10cSrcweir throw ( container::NoSuchElementException, 429cdf0e10cSrcweir lang::IllegalArgumentException, 430cdf0e10cSrcweir embed::InvalidStorageException, 431cdf0e10cSrcweir uno::RuntimeException ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir return m_xWrappedStorage->isStreamElement( aElementName ); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir //========================================================================= 437cdf0e10cSrcweir // virtual 438cdf0e10cSrcweir sal_Bool SAL_CALL Storage::isStorageElement( 439cdf0e10cSrcweir const ::rtl::OUString& aElementName ) 440cdf0e10cSrcweir throw ( container::NoSuchElementException, 441cdf0e10cSrcweir lang::IllegalArgumentException, 442cdf0e10cSrcweir embed::InvalidStorageException, 443cdf0e10cSrcweir uno::RuntimeException ) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir return m_xWrappedStorage->isStorageElement( aElementName ); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir //========================================================================= 449cdf0e10cSrcweir // virtual 450cdf0e10cSrcweir void SAL_CALL Storage::removeElement( const ::rtl::OUString& aElementName ) 451cdf0e10cSrcweir throw ( embed::InvalidStorageException, 452cdf0e10cSrcweir lang::IllegalArgumentException, 453cdf0e10cSrcweir container::NoSuchElementException, 454cdf0e10cSrcweir io::IOException, 455cdf0e10cSrcweir embed::StorageWrappedTargetException, 456cdf0e10cSrcweir uno::RuntimeException ) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir m_xWrappedStorage->removeElement( aElementName ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir 461cdf0e10cSrcweir //========================================================================= 462cdf0e10cSrcweir // virtual 463cdf0e10cSrcweir void SAL_CALL Storage::renameElement( const ::rtl::OUString& aEleName, 464cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 465cdf0e10cSrcweir throw ( embed::InvalidStorageException, 466cdf0e10cSrcweir lang::IllegalArgumentException, 467cdf0e10cSrcweir container::NoSuchElementException, 468cdf0e10cSrcweir container::ElementExistException, 469cdf0e10cSrcweir io::IOException, 470cdf0e10cSrcweir embed::StorageWrappedTargetException, 471cdf0e10cSrcweir uno::RuntimeException ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir m_xWrappedStorage->renameElement( aEleName, aNewName ); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir 476cdf0e10cSrcweir //========================================================================= 477cdf0e10cSrcweir // virtual 478cdf0e10cSrcweir void SAL_CALL Storage::copyElementTo( 479cdf0e10cSrcweir const ::rtl::OUString& aElementName, 480cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest, 481cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 482cdf0e10cSrcweir throw ( embed::InvalidStorageException, 483cdf0e10cSrcweir lang::IllegalArgumentException, 484cdf0e10cSrcweir container::NoSuchElementException, 485cdf0e10cSrcweir container::ElementExistException, 486cdf0e10cSrcweir io::IOException, 487cdf0e10cSrcweir embed::StorageWrappedTargetException, 488cdf0e10cSrcweir uno::RuntimeException ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir m_xWrappedStorage->copyElementTo( aElementName, xDest, aNewName ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir //========================================================================= 494cdf0e10cSrcweir // virtual 495cdf0e10cSrcweir void SAL_CALL Storage::moveElementTo( 496cdf0e10cSrcweir const ::rtl::OUString& aElementName, 497cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest, 498cdf0e10cSrcweir const ::rtl::OUString& rNewName ) 499cdf0e10cSrcweir throw ( embed::InvalidStorageException, 500cdf0e10cSrcweir lang::IllegalArgumentException, 501cdf0e10cSrcweir container::NoSuchElementException, 502cdf0e10cSrcweir container::ElementExistException, 503cdf0e10cSrcweir io::IOException, 504cdf0e10cSrcweir embed::StorageWrappedTargetException, 505cdf0e10cSrcweir uno::RuntimeException ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir m_xWrappedStorage->moveElementTo( aElementName, xDest, rNewName ); 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir //========================================================================= 511cdf0e10cSrcweir // 512cdf0e10cSrcweir // embed::XTransactedObject 513cdf0e10cSrcweir // 514cdf0e10cSrcweir //========================================================================= 515cdf0e10cSrcweir 516cdf0e10cSrcweir // virtual 517cdf0e10cSrcweir void SAL_CALL Storage::commit() 518cdf0e10cSrcweir throw ( io::IOException, 519cdf0e10cSrcweir lang::WrappedTargetException, 520cdf0e10cSrcweir uno::RuntimeException ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir // Never commit a root storage (-> has no parent)! 523cdf0e10cSrcweir // Would lead in writing the whole document to disk. 524cdf0e10cSrcweir 525cdf0e10cSrcweir uno::Reference< embed::XStorage > xParentStorage = getParentStorage(); 526cdf0e10cSrcweir if ( xParentStorage.is() ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir OSL_ENSURE( m_xWrappedTransObj.is(), "No XTransactedObject interface!" ); 529cdf0e10cSrcweir 530cdf0e10cSrcweir if ( m_xWrappedTransObj.is() ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir m_xWrappedTransObj->commit(); 533cdf0e10cSrcweir 534cdf0e10cSrcweir if ( !isParentARootStorage() ) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xParentTA( 537cdf0e10cSrcweir xParentStorage, uno::UNO_QUERY ); 538cdf0e10cSrcweir OSL_ENSURE( xParentTA.is(), "No XTransactedObject interface!" ); 539cdf0e10cSrcweir 540cdf0e10cSrcweir if ( xParentTA.is() ) 541cdf0e10cSrcweir xParentTA->commit(); 542cdf0e10cSrcweir } 543cdf0e10cSrcweir } 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir //========================================================================= 548cdf0e10cSrcweir // virtual 549cdf0e10cSrcweir void SAL_CALL Storage::revert() 550cdf0e10cSrcweir throw ( io::IOException, 551cdf0e10cSrcweir lang::WrappedTargetException, 552cdf0e10cSrcweir uno::RuntimeException ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir uno::Reference< embed::XStorage > xParentStorage = getParentStorage(); 555cdf0e10cSrcweir if ( xParentStorage.is() ) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir OSL_ENSURE( m_xWrappedTransObj.is(), "No XTransactedObject interface!" ); 558cdf0e10cSrcweir 559cdf0e10cSrcweir if ( m_xWrappedTransObj.is() ) 560cdf0e10cSrcweir { 561cdf0e10cSrcweir m_xWrappedTransObj->revert(); 562cdf0e10cSrcweir 563cdf0e10cSrcweir if ( !isParentARootStorage() ) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xParentTA( 566cdf0e10cSrcweir xParentStorage, uno::UNO_QUERY ); 567cdf0e10cSrcweir OSL_ENSURE( xParentTA.is(), "No XTransactedObject interface!" ); 568cdf0e10cSrcweir 569cdf0e10cSrcweir if ( xParentTA.is() ) 570cdf0e10cSrcweir xParentTA->revert(); 571cdf0e10cSrcweir } 572cdf0e10cSrcweir } 573cdf0e10cSrcweir } 574cdf0e10cSrcweir } 575cdf0e10cSrcweir 576cdf0e10cSrcweir //========================================================================= 577cdf0e10cSrcweir //========================================================================= 578cdf0e10cSrcweir // 579cdf0e10cSrcweir // OutputStream Implementation. 580cdf0e10cSrcweir // 581cdf0e10cSrcweir //========================================================================= 582cdf0e10cSrcweir //========================================================================= 583cdf0e10cSrcweir 584cdf0e10cSrcweir OutputStream::OutputStream( 585cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xSMgr, 586cdf0e10cSrcweir const rtl::OUString & rUri, 587cdf0e10cSrcweir const uno::Reference< embed::XStorage > & xParentStorage, 588cdf0e10cSrcweir const uno::Reference< io::XOutputStream > & xStreamToWrap ) 589cdf0e10cSrcweir : ParentStorageHolder( xParentStorage, Uri( rUri ).getParentUri() ), 590cdf0e10cSrcweir m_xWrappedStream( xStreamToWrap ), 591cdf0e10cSrcweir m_xWrappedComponent( xStreamToWrap, uno::UNO_QUERY ), 592cdf0e10cSrcweir m_xWrappedTypeProv( xStreamToWrap, uno::UNO_QUERY ) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir OSL_ENSURE( m_xWrappedStream.is(), 595cdf0e10cSrcweir "OutputStream::OutputStream: No stream to wrap!" ); 596cdf0e10cSrcweir 597cdf0e10cSrcweir OSL_ENSURE( m_xWrappedComponent.is(), 598cdf0e10cSrcweir "OutputStream::OutputStream: No component to wrap!" ); 599cdf0e10cSrcweir 600cdf0e10cSrcweir OSL_ENSURE( m_xWrappedTypeProv.is(), 601cdf0e10cSrcweir "OutputStream::OutputStream: No Type Provider!" ); 602cdf0e10cSrcweir 603cdf0e10cSrcweir // Use proxy factory service to create aggregatable proxy. 604cdf0e10cSrcweir try 605cdf0e10cSrcweir { 606cdf0e10cSrcweir uno::Reference< reflection::XProxyFactory > xProxyFac( 607cdf0e10cSrcweir xSMgr->createInstance( 608cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 609cdf0e10cSrcweir "com.sun.star.reflection.ProxyFactory" ) ) ), 610cdf0e10cSrcweir uno::UNO_QUERY ); 611cdf0e10cSrcweir if ( xProxyFac.is() ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir m_xAggProxy = xProxyFac->createProxy( m_xWrappedStream ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir } 616cdf0e10cSrcweir catch ( uno::Exception const & ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir OSL_ENSURE( false, "OutputStream::OutputStream: Caught exception!" ); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir OSL_ENSURE( m_xAggProxy.is(), 622cdf0e10cSrcweir "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" ); 623cdf0e10cSrcweir 624cdf0e10cSrcweir if ( m_xAggProxy.is() ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 627cdf0e10cSrcweir { 628cdf0e10cSrcweir // Solaris compiler problem: 629cdf0e10cSrcweir // Extra block to enforce destruction of temporary object created 630cdf0e10cSrcweir // in next statement _before_ osl_decrementInterlockedCount is 631cdf0e10cSrcweir // called. Otherwise 'this' will destroy itself even before ctor 632cdf0e10cSrcweir // is completed (See impl. of XInterface::release())! 633cdf0e10cSrcweir 634cdf0e10cSrcweir m_xAggProxy->setDelegator( 635cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 636cdf0e10cSrcweir } 637cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir //========================================================================= 642cdf0e10cSrcweir // virtual 643cdf0e10cSrcweir OutputStream::~OutputStream() 644cdf0e10cSrcweir { 645cdf0e10cSrcweir if ( m_xAggProxy.is() ) 646cdf0e10cSrcweir m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() ); 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir //========================================================================= 650cdf0e10cSrcweir // 651cdf0e10cSrcweir // uno::XInterface 652cdf0e10cSrcweir // 653cdf0e10cSrcweir //========================================================================= 654cdf0e10cSrcweir 655cdf0e10cSrcweir // virtual 656cdf0e10cSrcweir uno::Any SAL_CALL OutputStream::queryInterface( const uno::Type& aType ) 657cdf0e10cSrcweir throw ( uno::RuntimeException ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir uno::Any aRet = OutputStreamUNOBase::queryInterface( aType ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir if ( aRet.hasValue() ) 662cdf0e10cSrcweir return aRet; 663cdf0e10cSrcweir 664cdf0e10cSrcweir if ( m_xAggProxy.is() ) 665cdf0e10cSrcweir return m_xAggProxy->queryAggregation( aType ); 666cdf0e10cSrcweir else 667cdf0e10cSrcweir return uno::Any(); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir 670cdf0e10cSrcweir //========================================================================= 671cdf0e10cSrcweir // 672cdf0e10cSrcweir // lang::XTypeProvider 673cdf0e10cSrcweir // 674cdf0e10cSrcweir //========================================================================= 675cdf0e10cSrcweir 676cdf0e10cSrcweir // virtual 677cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OutputStream::getTypes() 678cdf0e10cSrcweir throw ( uno::RuntimeException ) 679cdf0e10cSrcweir { 680cdf0e10cSrcweir return m_xWrappedTypeProv->getTypes(); 681cdf0e10cSrcweir } 682cdf0e10cSrcweir 683cdf0e10cSrcweir //========================================================================= 684cdf0e10cSrcweir // virtual 685cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL OutputStream::getImplementationId() 686cdf0e10cSrcweir throw ( uno::RuntimeException ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir return m_xWrappedTypeProv->getImplementationId(); 689cdf0e10cSrcweir } 690cdf0e10cSrcweir 691cdf0e10cSrcweir //========================================================================= 692cdf0e10cSrcweir // 693cdf0e10cSrcweir // io::XOutputStream 694cdf0e10cSrcweir // 695cdf0e10cSrcweir //========================================================================= 696cdf0e10cSrcweir 697cdf0e10cSrcweir // virtual 698cdf0e10cSrcweir void SAL_CALL 699cdf0e10cSrcweir OutputStream::writeBytes( const uno::Sequence< sal_Int8 >& aData ) 700cdf0e10cSrcweir throw ( io::NotConnectedException, 701cdf0e10cSrcweir io::BufferSizeExceededException, 702cdf0e10cSrcweir io::IOException, 703cdf0e10cSrcweir uno::RuntimeException ) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir m_xWrappedStream->writeBytes( aData ); 706cdf0e10cSrcweir } 707cdf0e10cSrcweir 708cdf0e10cSrcweir //========================================================================= 709cdf0e10cSrcweir // virtual 710cdf0e10cSrcweir void SAL_CALL 711cdf0e10cSrcweir OutputStream::flush() 712cdf0e10cSrcweir throw ( io::NotConnectedException, 713cdf0e10cSrcweir io::BufferSizeExceededException, 714cdf0e10cSrcweir io::IOException, 715cdf0e10cSrcweir uno::RuntimeException ) 716cdf0e10cSrcweir { 717cdf0e10cSrcweir m_xWrappedStream->flush(); 718cdf0e10cSrcweir } 719cdf0e10cSrcweir 720cdf0e10cSrcweir //========================================================================= 721cdf0e10cSrcweir // virtual 722cdf0e10cSrcweir void SAL_CALL 723cdf0e10cSrcweir OutputStream::closeOutput( ) 724cdf0e10cSrcweir throw ( io::NotConnectedException, 725cdf0e10cSrcweir io::BufferSizeExceededException, 726cdf0e10cSrcweir io::IOException, 727cdf0e10cSrcweir uno::RuntimeException ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir m_xWrappedStream->closeOutput(); 730cdf0e10cSrcweir 731cdf0e10cSrcweir // Release parent storage. 732cdf0e10cSrcweir // Now, that the stream is closed/disposed it is not needed any longer. 733cdf0e10cSrcweir setParentStorage( uno::Reference< embed::XStorage >() ); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir //========================================================================= 737cdf0e10cSrcweir // 738cdf0e10cSrcweir // lang::XComponent 739cdf0e10cSrcweir // 740cdf0e10cSrcweir //========================================================================= 741cdf0e10cSrcweir 742cdf0e10cSrcweir // virtual 743cdf0e10cSrcweir void SAL_CALL 744cdf0e10cSrcweir OutputStream::dispose() 745cdf0e10cSrcweir throw ( uno::RuntimeException ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir m_xWrappedComponent->dispose(); 748cdf0e10cSrcweir 749cdf0e10cSrcweir // Release parent storage. 750cdf0e10cSrcweir // Now, that the stream is closed/disposed it is not needed any longer. 751cdf0e10cSrcweir setParentStorage( uno::Reference< embed::XStorage >() ); 752cdf0e10cSrcweir } 753cdf0e10cSrcweir 754cdf0e10cSrcweir //========================================================================= 755cdf0e10cSrcweir // virtual 756cdf0e10cSrcweir void SAL_CALL 757cdf0e10cSrcweir OutputStream::addEventListener( 758cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 759cdf0e10cSrcweir throw ( uno::RuntimeException ) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir m_xWrappedComponent->addEventListener( xListener ); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir 764cdf0e10cSrcweir //========================================================================= 765cdf0e10cSrcweir // virtual 766cdf0e10cSrcweir void SAL_CALL 767cdf0e10cSrcweir OutputStream::removeEventListener( 768cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& aListener ) 769cdf0e10cSrcweir throw ( uno::RuntimeException ) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir m_xWrappedComponent->removeEventListener( aListener ); 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir //========================================================================= 775cdf0e10cSrcweir //========================================================================= 776cdf0e10cSrcweir // 777cdf0e10cSrcweir // Stream Implementation. 778cdf0e10cSrcweir // 779cdf0e10cSrcweir //========================================================================= 780cdf0e10cSrcweir //========================================================================= 781cdf0e10cSrcweir 782cdf0e10cSrcweir Stream::Stream( 783cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xSMgr, 784cdf0e10cSrcweir const rtl::OUString & rUri, 785cdf0e10cSrcweir const uno::Reference< embed::XStorage > & xParentStorage, 786cdf0e10cSrcweir const uno::Reference< io::XStream > & xStreamToWrap ) 787cdf0e10cSrcweir : ParentStorageHolder( xParentStorage, Uri( rUri ).getParentUri() ), 788cdf0e10cSrcweir m_xWrappedStream( xStreamToWrap ), 789cdf0e10cSrcweir m_xWrappedOutputStream( xStreamToWrap->getOutputStream() ), // might be empty 790cdf0e10cSrcweir m_xWrappedTruncate( m_xWrappedOutputStream, uno::UNO_QUERY ), // might be empty 791cdf0e10cSrcweir m_xWrappedInputStream( xStreamToWrap->getInputStream(), uno::UNO_QUERY ), 792cdf0e10cSrcweir m_xWrappedComponent( xStreamToWrap, uno::UNO_QUERY ), 793cdf0e10cSrcweir m_xWrappedTypeProv( xStreamToWrap, uno::UNO_QUERY ) 794cdf0e10cSrcweir { 795cdf0e10cSrcweir OSL_ENSURE( m_xWrappedStream.is(), 796cdf0e10cSrcweir "OutputStream::OutputStream: No stream to wrap!" ); 797cdf0e10cSrcweir 798cdf0e10cSrcweir OSL_ENSURE( m_xWrappedComponent.is(), 799cdf0e10cSrcweir "OutputStream::OutputStream: No component to wrap!" ); 800cdf0e10cSrcweir 801cdf0e10cSrcweir OSL_ENSURE( m_xWrappedTypeProv.is(), 802cdf0e10cSrcweir "OutputStream::OutputStream: No Type Provider!" ); 803cdf0e10cSrcweir 804cdf0e10cSrcweir // Use proxy factory service to create aggregatable proxy. 805cdf0e10cSrcweir try 806cdf0e10cSrcweir { 807cdf0e10cSrcweir uno::Reference< reflection::XProxyFactory > xProxyFac( 808cdf0e10cSrcweir xSMgr->createInstance( 809cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 810cdf0e10cSrcweir "com.sun.star.reflection.ProxyFactory" ) ) ), 811cdf0e10cSrcweir uno::UNO_QUERY ); 812cdf0e10cSrcweir if ( xProxyFac.is() ) 813cdf0e10cSrcweir { 814cdf0e10cSrcweir m_xAggProxy = xProxyFac->createProxy( m_xWrappedStream ); 815cdf0e10cSrcweir } 816cdf0e10cSrcweir } 817cdf0e10cSrcweir catch ( uno::Exception const & ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir OSL_ENSURE( false, "OutputStream::OutputStream: Caught exception!" ); 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir OSL_ENSURE( m_xAggProxy.is(), 823cdf0e10cSrcweir "OutputStream::OutputStream: Wrapped stream cannot be aggregated!" ); 824cdf0e10cSrcweir 825cdf0e10cSrcweir if ( m_xAggProxy.is() ) 826cdf0e10cSrcweir { 827cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 828cdf0e10cSrcweir { 829cdf0e10cSrcweir // Solaris compiler problem: 830cdf0e10cSrcweir // Extra block to enforce destruction of temporary object created 831cdf0e10cSrcweir // in next statement _before_ osl_decrementInterlockedCount is 832cdf0e10cSrcweir // called. Otherwise 'this' will destroy itself even before ctor 833cdf0e10cSrcweir // is completed (See impl. of XInterface::release())! 834cdf0e10cSrcweir 835cdf0e10cSrcweir m_xAggProxy->setDelegator( 836cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 837cdf0e10cSrcweir } 838cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir //========================================================================= 843cdf0e10cSrcweir // virtual 844cdf0e10cSrcweir Stream::~Stream() 845cdf0e10cSrcweir { 846cdf0e10cSrcweir if ( m_xAggProxy.is() ) 847cdf0e10cSrcweir m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() ); 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir //========================================================================= 851cdf0e10cSrcweir // 852cdf0e10cSrcweir // uno::XInterface 853cdf0e10cSrcweir // 854cdf0e10cSrcweir //========================================================================= 855cdf0e10cSrcweir 856cdf0e10cSrcweir // virtual 857cdf0e10cSrcweir uno::Any SAL_CALL Stream::queryInterface( const uno::Type& aType ) 858cdf0e10cSrcweir throw ( uno::RuntimeException ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir uno::Any aRet = StreamUNOBase::queryInterface( aType ); 861cdf0e10cSrcweir 862cdf0e10cSrcweir if ( aRet.hasValue() ) 863cdf0e10cSrcweir return aRet; 864cdf0e10cSrcweir 865cdf0e10cSrcweir if ( m_xAggProxy.is() ) 866cdf0e10cSrcweir return m_xAggProxy->queryAggregation( aType ); 867cdf0e10cSrcweir else 868cdf0e10cSrcweir return uno::Any(); 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir //========================================================================= 872cdf0e10cSrcweir // 873cdf0e10cSrcweir // lang::XTypeProvider 874cdf0e10cSrcweir // 875cdf0e10cSrcweir //========================================================================= 876cdf0e10cSrcweir 877cdf0e10cSrcweir // virtual 878cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Stream::getTypes() 879cdf0e10cSrcweir throw ( uno::RuntimeException ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir return m_xWrappedTypeProv->getTypes(); 882cdf0e10cSrcweir } 883cdf0e10cSrcweir 884cdf0e10cSrcweir //========================================================================= 885cdf0e10cSrcweir // virtual 886cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Stream::getImplementationId() 887cdf0e10cSrcweir throw ( uno::RuntimeException ) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir return m_xWrappedTypeProv->getImplementationId(); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir //========================================================================= 893cdf0e10cSrcweir // 894cdf0e10cSrcweir // io::XStream. 895cdf0e10cSrcweir // 896cdf0e10cSrcweir //========================================================================= 897cdf0e10cSrcweir 898cdf0e10cSrcweir // virtual 899cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL Stream::getInputStream() 900cdf0e10cSrcweir throw( uno::RuntimeException ) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir return uno::Reference< io::XInputStream >( this ); 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905cdf0e10cSrcweir //========================================================================= 906cdf0e10cSrcweir // virtual 907cdf0e10cSrcweir uno::Reference< io::XOutputStream > SAL_CALL Stream::getOutputStream() 908cdf0e10cSrcweir throw( uno::RuntimeException ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir return uno::Reference< io::XOutputStream >( this ); 911cdf0e10cSrcweir } 912cdf0e10cSrcweir 913cdf0e10cSrcweir //========================================================================= 914cdf0e10cSrcweir // 915cdf0e10cSrcweir // io::XOutputStream. 916cdf0e10cSrcweir // 917cdf0e10cSrcweir //========================================================================= 918cdf0e10cSrcweir 919cdf0e10cSrcweir // virtual 920cdf0e10cSrcweir void SAL_CALL Stream::writeBytes( const uno::Sequence< sal_Int8 >& aData ) 921cdf0e10cSrcweir throw( io::NotConnectedException, 922cdf0e10cSrcweir io::BufferSizeExceededException, 923cdf0e10cSrcweir io::IOException, 924cdf0e10cSrcweir uno::RuntimeException ) 925cdf0e10cSrcweir { 926cdf0e10cSrcweir if ( m_xWrappedOutputStream.is() ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir m_xWrappedOutputStream->writeBytes( aData ); 929cdf0e10cSrcweir commitChanges(); 930cdf0e10cSrcweir } 931cdf0e10cSrcweir } 932cdf0e10cSrcweir 933cdf0e10cSrcweir //========================================================================= 934cdf0e10cSrcweir // virtual 935cdf0e10cSrcweir void SAL_CALL Stream::flush() 936cdf0e10cSrcweir throw( io::NotConnectedException, 937cdf0e10cSrcweir io::BufferSizeExceededException, 938cdf0e10cSrcweir io::IOException, 939cdf0e10cSrcweir uno::RuntimeException ) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir if ( m_xWrappedOutputStream.is() ) 942cdf0e10cSrcweir { 943cdf0e10cSrcweir m_xWrappedOutputStream->flush(); 944cdf0e10cSrcweir commitChanges(); 945cdf0e10cSrcweir } 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir //========================================================================= 949cdf0e10cSrcweir // virtual 950cdf0e10cSrcweir void SAL_CALL Stream::closeOutput() 951cdf0e10cSrcweir throw( io::NotConnectedException, 952cdf0e10cSrcweir io::IOException, 953cdf0e10cSrcweir uno::RuntimeException ) 954cdf0e10cSrcweir { 955cdf0e10cSrcweir if ( m_xWrappedOutputStream.is() ) 956cdf0e10cSrcweir { 957cdf0e10cSrcweir m_xWrappedOutputStream->closeOutput(); 958cdf0e10cSrcweir commitChanges(); 959cdf0e10cSrcweir } 960cdf0e10cSrcweir 961cdf0e10cSrcweir // Release parent storage. 962cdf0e10cSrcweir // Now, that the stream is closed/disposed it is not needed any longer. 963cdf0e10cSrcweir setParentStorage( uno::Reference< embed::XStorage >() ); 964cdf0e10cSrcweir } 965cdf0e10cSrcweir 966cdf0e10cSrcweir //========================================================================= 967cdf0e10cSrcweir // 968cdf0e10cSrcweir // io::XTruncate. 969cdf0e10cSrcweir // 970cdf0e10cSrcweir //========================================================================= 971cdf0e10cSrcweir 972cdf0e10cSrcweir // virtual 973cdf0e10cSrcweir void SAL_CALL Stream::truncate() 974cdf0e10cSrcweir throw( io::IOException, 975cdf0e10cSrcweir uno::RuntimeException ) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir if ( m_xWrappedTruncate.is() ) 978cdf0e10cSrcweir { 979cdf0e10cSrcweir m_xWrappedTruncate->truncate(); 980cdf0e10cSrcweir commitChanges(); 981cdf0e10cSrcweir } 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir //========================================================================= 985cdf0e10cSrcweir // 986cdf0e10cSrcweir // io::XInputStream. 987cdf0e10cSrcweir // 988cdf0e10cSrcweir //========================================================================= 989cdf0e10cSrcweir 990cdf0e10cSrcweir // virtual 991cdf0e10cSrcweir sal_Int32 SAL_CALL Stream::readBytes( uno::Sequence< sal_Int8 >& aData, 992cdf0e10cSrcweir sal_Int32 nBytesToRead ) 993cdf0e10cSrcweir throw( io::NotConnectedException, 994cdf0e10cSrcweir io::BufferSizeExceededException, 995cdf0e10cSrcweir io::IOException, 996cdf0e10cSrcweir uno::RuntimeException ) 997cdf0e10cSrcweir { 998cdf0e10cSrcweir return m_xWrappedInputStream->readBytes( aData, nBytesToRead ); 999cdf0e10cSrcweir } 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir //========================================================================= 1002cdf0e10cSrcweir // virtual 1003cdf0e10cSrcweir sal_Int32 SAL_CALL Stream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, 1004cdf0e10cSrcweir sal_Int32 nMaxBytesToRead ) 1005cdf0e10cSrcweir throw( io::NotConnectedException, 1006cdf0e10cSrcweir io::BufferSizeExceededException, 1007cdf0e10cSrcweir io::IOException, 1008cdf0e10cSrcweir uno::RuntimeException ) 1009cdf0e10cSrcweir { 1010cdf0e10cSrcweir return m_xWrappedInputStream->readSomeBytes( aData, nMaxBytesToRead ); 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir //========================================================================= 1014cdf0e10cSrcweir // virtual 1015cdf0e10cSrcweir void SAL_CALL Stream::skipBytes( sal_Int32 nBytesToSkip ) 1016cdf0e10cSrcweir throw( io::NotConnectedException, 1017cdf0e10cSrcweir io::BufferSizeExceededException, 1018cdf0e10cSrcweir io::IOException, 1019cdf0e10cSrcweir uno::RuntimeException ) 1020cdf0e10cSrcweir { 1021cdf0e10cSrcweir m_xWrappedInputStream->skipBytes( nBytesToSkip ); 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir //========================================================================= 1025cdf0e10cSrcweir // virtual 1026cdf0e10cSrcweir sal_Int32 SAL_CALL Stream::available() 1027cdf0e10cSrcweir throw( io::NotConnectedException, 1028cdf0e10cSrcweir io::IOException, 1029cdf0e10cSrcweir uno::RuntimeException ) 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir return m_xWrappedInputStream->available(); 1032cdf0e10cSrcweir } 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir //========================================================================= 1035cdf0e10cSrcweir // virtual 1036cdf0e10cSrcweir void SAL_CALL Stream::closeInput() 1037cdf0e10cSrcweir throw( io::NotConnectedException, 1038cdf0e10cSrcweir io::IOException, 1039cdf0e10cSrcweir uno::RuntimeException ) 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir m_xWrappedInputStream->closeInput(); 1042cdf0e10cSrcweir } 1043cdf0e10cSrcweir 1044cdf0e10cSrcweir //========================================================================= 1045cdf0e10cSrcweir // 1046cdf0e10cSrcweir // lang::XComponent 1047cdf0e10cSrcweir // 1048cdf0e10cSrcweir //========================================================================= 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir // virtual 1051cdf0e10cSrcweir void SAL_CALL Stream::dispose() 1052cdf0e10cSrcweir throw ( uno::RuntimeException ) 1053cdf0e10cSrcweir { 1054cdf0e10cSrcweir m_xWrappedComponent->dispose(); 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir // Release parent storage. 1057cdf0e10cSrcweir // Now, that the stream is closed/disposed it is not needed any longer. 1058cdf0e10cSrcweir setParentStorage( uno::Reference< embed::XStorage >() ); 1059cdf0e10cSrcweir } 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir //========================================================================= 1062cdf0e10cSrcweir // virtual 1063cdf0e10cSrcweir void SAL_CALL Stream::addEventListener( 1064cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 1065cdf0e10cSrcweir throw ( uno::RuntimeException ) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir m_xWrappedComponent->addEventListener( xListener ); 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir //========================================================================= 1071cdf0e10cSrcweir // virtual 1072cdf0e10cSrcweir void SAL_CALL Stream::removeEventListener( 1073cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& aListener ) 1074cdf0e10cSrcweir throw ( uno::RuntimeException ) 1075cdf0e10cSrcweir { 1076cdf0e10cSrcweir m_xWrappedComponent->removeEventListener( aListener ); 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir //========================================================================= 1080cdf0e10cSrcweir // 1081cdf0e10cSrcweir // Non-UNO 1082cdf0e10cSrcweir // 1083cdf0e10cSrcweir //========================================================================= 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir void Stream::commitChanges() 1086cdf0e10cSrcweir throw( io::IOException ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > 1089cdf0e10cSrcweir xParentTA( getParentStorage(), uno::UNO_QUERY ); 1090cdf0e10cSrcweir OSL_ENSURE( xParentTA.is(), "No XTransactedObject interface!" ); 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir if ( xParentTA.is() ) 1093cdf0e10cSrcweir { 1094cdf0e10cSrcweir try 1095cdf0e10cSrcweir { 1096cdf0e10cSrcweir xParentTA->commit(); 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir throw io::IOException(); // @@@ 1101cdf0e10cSrcweir } 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir } 1104cdf0e10cSrcweir 1105