INTEGRATION: CWS fwklhf01 (1.8.8); FILE MERGED

2004/07/13 13:32:59 mav 1.8.8.6: #i30236# use list
2004/07/13 12:07:29 mav 1.8.8.5: #i30236# add to the correct list
2004/06/24 10:50:22 mav 1.8.8.4: #i30677# do streams commit before the common process to avoid exceptional situations
2004/06/23 09:57:52 mav 1.8.8.3: #i29321# handle gracefuly cases when nonmodified storage is commited and nothing is written to a new stream
2004/06/21 11:24:48 mav 1.8.8.2: #i30236# fix autodisposing of readonly storages
2004/06/21 09:24:24 mav 1.8.8.1: #i30400# do not ignore target name
This commit is contained in:
Jens-Heiner Rechtien 2004-07-23 10:13:03 +00:00
parent 9476344797
commit d404ba0eab

View file

@ -2,9 +2,9 @@
* *
* $RCSfile: xstorage.cxx,v $ * $RCSfile: xstorage.cxx,v $
* *
* $Revision: 1.8 $ * $Revision: 1.9 $
* *
* last change: $Author: rt $ $Date: 2004-05-19 09:19:38 $ * last change: $Author: hr $ $Date: 2004-07-23 11:13:03 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@ -126,6 +126,9 @@
using namespace ::com::sun::star; using namespace ::com::sun::star;
//========================================================= //=========================================================
typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList;
struct StorInternalData_Impl struct StorInternalData_Impl
{ {
SotMutexHolderRef m_rSharedMutexRef; SotMutexHolderRef m_rSharedMutexRef;
@ -136,7 +139,7 @@ struct StorInternalData_Impl
OChildDispListener_Impl* m_pSubElDispListener; OChildDispListener_Impl* m_pSubElDispListener;
uno::Sequence< uno::Reference< lang::XComponent > > m_aOpenSubComponentsList; WeakComponentList m_aOpenSubComponentsList;
// the mutex reference MUST NOT be empty // the mutex reference MUST NOT be empty
StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Bool bReadOnlyWrap ) StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Bool bReadOnlyWrap )
@ -150,6 +153,7 @@ struct StorInternalData_Impl
~StorInternalData_Impl(); ~StorInternalData_Impl();
}; };
//========================================================= //=========================================================
extern uno::Sequence< sal_Int8 > MakeKeyFromPass( ::rtl::OUString aPass, sal_Bool bUseUTF ); extern uno::Sequence< sal_Int8 > MakeKeyFromPass( ::rtl::OUString aPass, sal_Bool bUseUTF );
@ -335,12 +339,13 @@ OStorage_Impl::~OStorage_Impl()
{ {
for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ ) pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ )
if ( *pStorageIter ) {
uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
if ( xTmp.is() )
try { try {
(*pStorageIter)->InternalDispose( sal_False ); pStorageIter->m_pPointer->InternalDispose( sal_False );
(*pStorageIter)->release();
(*pStorageIter) = NULL;
} catch( uno::Exception& ) {} } catch( uno::Exception& ) {}
}
m_aReadOnlyWrapList.clear(); m_aReadOnlyWrapList.clear();
} }
@ -393,26 +398,31 @@ OStorage_Impl::~OStorage_Impl()
//----------------------------------------------- //-----------------------------------------------
void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage ) void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage )
{ {
aStorage.acquire(); // Weak reference is used inside the holder so the refcount must not be zero at this point
m_aReadOnlyWrapList.push_back( &aStorage ); OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" );
m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) );
} }
//----------------------------------------------- //-----------------------------------------------
void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage ) void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage )
{ {
for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ ) pStorageIter != m_aReadOnlyWrapList.end();)
if ( *pStorageIter == &aStorage ) {
uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage )
{ {
try { try {
(*pStorageIter)->InternalDispose( sal_False ); pStorageIter->m_pPointer->InternalDispose( sal_False );
} catch( uno::Exception& ) {} } catch( uno::Exception& ) {}
(*pStorageIter)->release(); OStorageList_Impl::iterator pIterToDelete( pStorageIter );
(*pStorageIter) = NULL; pStorageIter++;
m_aReadOnlyWrapList.erase( pIterToDelete );
} }
else
m_aReadOnlyWrapList.remove( NULL ); pStorageIter++;
}
} }
//----------------------------------------------- //-----------------------------------------------
@ -679,7 +689,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
if ( !pElement->m_pStream->IsEncrypted() ) if ( !pElement->m_pStream->IsEncrypted() )
{ {
uno::Reference< io::XStream > xSubStr = uno::Reference< io::XStream > xSubStr =
xDest->openStreamElement( pElement->m_aName, xDest->openStreamElement( aName,
embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
@ -688,7 +698,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
else if ( pElement->m_pStream->HasCachedPassword() && pElement->m_pStream->IsModified() ) else if ( pElement->m_pStream->HasCachedPassword() && pElement->m_pStream->IsModified() )
{ {
uno::Reference< io::XStream > xSubStr = uno::Reference< io::XStream > xSubStr =
xDest->openEncryptedStreamElement( pElement->m_aName, xDest->openEncryptedStreamElement( aName,
embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
pElement->m_pStream->GetCachedPassword() ); pElement->m_pStream->GetCachedPassword() );
OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
@ -762,6 +772,9 @@ void OStorage_Impl::Commit()
OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE, OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE,
"Commit of readonly storage, should be detected before!\n" ); "Commit of readonly storage, should be detected before!\n" );
if ( !m_bIsModified )
return;
uno::Reference< container::XNameContainer > xNewPackageFolder; uno::Reference< container::XNameContainer > xNewPackageFolder;
// here the storage will switch to the temporary package folder // here the storage will switch to the temporary package folder
@ -825,6 +838,13 @@ void OStorage_Impl::Commit()
if ( !(*pElementIter)->m_bIsInserted ) if ( !(*pElementIter)->m_bIsInserted )
{ {
// for now stream is opened in direct mode that means that in case
// storage is commited all the streams from it are commited in current state.
// following two steps are separated to allow easily implement transacted mode
// for streams if we need it in future.
if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream )
(*pElementIter)->m_pStream->Commit();
// if the storage was not open, there is no need to commit it ??? // if the storage was not open, there is no need to commit it ???
// the storage should be checked that it is commited // the storage should be checked that it is commited
if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited ) if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited )
@ -838,15 +858,8 @@ void OStorage_Impl::Commit()
(*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
} }
else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream ) else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed )
{ {
// for now stream is opened in direct mode that means that in case
// storage is commited all the streams from it are commited in current state.
// following two steps are separated to allow easily implement transacted mode
// for streams if we need it in future.
(*pElementIter)->m_pStream->Commit();
// the renamed elements are not in new temporary storage // the renamed elements are not in new temporary storage
if ( m_bCommited || m_bIsRoot ) if ( m_bCommited || m_bIsRoot )
xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
@ -1339,9 +1352,7 @@ OStorage::OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap )
m_pData->m_bReadOnlyWrap, m_pData->m_bReadOnlyWrap,
"The wrapper can not allow writing in case implementation does not!\n" ); "The wrapper can not allow writing in case implementation does not!\n" );
if ( m_pData->m_bReadOnlyWrap ) if ( !bReadOnlyWrap )
m_pImpl->SetReadOnlyWrap( *this );
else
m_pImpl->m_pAntiImpl = this; m_pImpl->m_pAntiImpl = this;
} }
@ -1384,7 +1395,7 @@ void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl )
if ( m_pData->m_bReadOnlyWrap ) if ( m_pData->m_bReadOnlyWrap )
{ {
OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.getLength() || m_pData->m_pSubElDispListener, OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener,
"If any subelements are open the listener must exist!\n" ); "If any subelements are open the listener must exist!\n" );
if ( m_pData->m_pSubElDispListener ) if ( m_pData->m_pSubElDispListener )
@ -1393,20 +1404,25 @@ void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl )
// iterate through m_pData->m_aOpenSubComponentsList // iterate through m_pData->m_aOpenSubComponentsList
// deregister m_pData->m_pSubElDispListener and dispose all of them // deregister m_pData->m_pSubElDispListener and dispose all of them
for ( sal_Int32 nInd = 0; nInd < m_pData->m_aOpenSubComponentsList.getLength(); nInd++ ) if ( !m_pData->m_aOpenSubComponentsList.empty() )
if ( m_pData->m_aOpenSubComponentsList[nInd].is() ) {
for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
pCompIter != m_pData->m_aOpenSubComponentsList.end(); pCompIter++ )
{ {
m_pData->m_aOpenSubComponentsList[nInd]->removeEventListener( uno::Reference< lang::XEventListener >( uno::Reference< lang::XComponent > xTmp = (*pCompIter);
if ( xTmp.is() )
{
xTmp->removeEventListener( uno::Reference< lang::XEventListener >(
static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) ); static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) );
try { try {
m_pData->m_aOpenSubComponentsList[nInd]->dispose(); xTmp->dispose();
} catch( uno::Exception& ) } catch( uno::Exception& ) {}
{} }
m_pData->m_aOpenSubComponentsList[nInd] = uno::Reference< XComponent >();
} }
m_pData->m_aOpenSubComponentsList.realloc( 0 ); m_pData->m_aOpenSubComponentsList.clear();
}
} }
if ( bNotifyImpl ) if ( bNotifyImpl )
@ -1439,17 +1455,22 @@ void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild
// this method must not contain any locking // this method must not contain any locking
// the locking is done in the listener // the locking is done in the listener
sal_Int32 nOldLength = m_pData->m_aOpenSubComponentsList.getLength(); if ( !m_pData->m_aOpenSubComponentsList.empty() )
sal_Int32 nNewLength = 0; {
for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
uno::Sequence< uno::Reference< lang::XComponent > > aNewSeq( nOldLength ); pCompIter != m_pData->m_aOpenSubComponentsList.end(); )
{
for ( sal_Int32 nInd = 0; nInd < nOldLength; nInd++ ) uno::Reference< lang::XComponent > xTmp = (*pCompIter);
if ( m_pData->m_aOpenSubComponentsList[nInd] != xChild ) if ( !xTmp.is() || xTmp == xChild )
aNewSeq[nNewLength++] = m_pData->m_aOpenSubComponentsList[nInd]; {
WeakComponentList::iterator pIterToRemove = pCompIter;
aNewSeq.realloc( nNewLength ); pCompIter++;
m_pData->m_aOpenSubComponentsList = aNewSeq; m_pData->m_aOpenSubComponentsList.erase( pIterToRemove );
}
else
pCompIter++;
}
}
} }
//----------------------------------------------- //-----------------------------------------------
@ -1571,9 +1592,7 @@ void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XCompone
xComponent->addEventListener( uno::Reference< lang::XEventListener >( xComponent->addEventListener( uno::Reference< lang::XEventListener >(
static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) ); static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) );
sal_Int32 nLength = m_pData->m_aOpenSubComponentsList.getLength(); m_pData->m_aOpenSubComponentsList.push_back( xComponent );
m_pData->m_aOpenSubComponentsList.realloc( nLength + 1 );
m_pData->m_aOpenSubComponentsList[nLength] = xComponent;
} }
//____________________________________________________________________________________________________ //____________________________________________________________________________________________________
@ -1933,14 +1952,15 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
if ( !pElement->m_pStorage ) if ( !pElement->m_pStorage )
throw io::IOException(); // TODO: general_error throw io::IOException(); // TODO: general_error
uno::Reference< embed::XStorage > xResult( sal_Bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE );
static_cast< OWeakObject* >( new OStorage( OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap );
pElement->m_pStorage, uno::Reference< embed::XStorage > xResult( (embed::XStorage*) pResultStorage );
( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) ),
uno::UNO_QUERY );
if ( m_pData->m_bReadOnlyWrap ) if ( bReadOnlyWrap )
{ {
// Before this call is done the object must be refcounted already
pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage );
// before the storage disposes the stream it must deregister itself as listener // before the storage disposes the stream it must deregister itself as listener
uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY ); uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY );
if ( !xStorageComponent.is() ) if ( !xStorageComponent.is() )