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