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