Tag: cws_src680_qiq User: fs Date: 06/05/24 07:55:19 Modified: /dba/dbaccess/source/core/dataaccess/ definitioncontainer.cxx
Log: #i51143# be an XContainerApproveBroadcaster File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: definitioncontainer.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/definitioncontainer.cxx?r1=1.21.4.1&r2=1.21.4.2 Delta lines: +74 -48 --------------------- --- definitioncontainer.cxx 24 May 2006 09:11:14 -0000 1.21.4.1 +++ definitioncontainer.cxx 24 May 2006 14:55:16 -0000 1.21.4.2 @@ -4,9 +4,9 @@ * * $RCSfile: definitioncontainer.cxx,v $ * - * $Revision: 1.21.4.1 $ + * $Revision: 1.21.4.2 $ * - * last change: $Author: fs $ $Date: 2006/05/24 09:11:14 $ + * last change: $Author: fs $ $Date: 2006/05/24 14:55:16 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -105,6 +105,7 @@ ) :OContentHelper(_xORB,_xParentContainer,_pImpl) ,m_aContainerListeners(m_aMutex) + ,m_aApproveListeners(m_aMutex) ,m_bInPropertyChange(sal_False) { m_pImpl->m_aProps.bIsDocument = sal_False; @@ -130,6 +131,7 @@ // say our listeners goobye EventObject aEvt(*this); + m_aApproveListeners.disposeAndClear(aEvt); m_aContainerListeners.disposeAndClear(aEvt); // dispose our elements @@ -179,21 +181,22 @@ //-------------------------------------------------------------------------- void SAL_CALL ODefinitionContainer::insertByName( const ::rtl::OUString& _rName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) { - ClearableMutexGuard aGuard(m_aMutex); + ResettableMutexGuard aGuard(m_aMutex); // approve the new object Reference< XContent > xNewElement(aElement,UNO_QUERY); approveNewObject( _rName, xNewElement ); // will throw if necessary + notifyByName( aGuard, _rName, xNewElement, NULL, E_INSERTED, ApproveListeners ); implAppend( _rName, xNewElement ); - - notifyByName(aGuard,_rName,xNewElement,NULL,E_INSERTED); + notifyByName( aGuard, _rName, xNewElement, NULL, E_INSERTED, ContainerListemers ); } //-------------------------------------------------------------------------- void SAL_CALL ODefinitionContainer::removeByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) { - ClearableMutexGuard aGuard(m_aMutex); + ResettableMutexGuard aGuard(m_aMutex); + // check the arguments if (!_rName.getLength()) throw IllegalArgumentException(); @@ -202,71 +205,80 @@ throw NoSuchElementException(_rName,*this); // the old element (for the notifications) - Reference< XContent > xOldElement = implGetByName(_rName, (m_aContainerListeners.getLength() != 0)); - removeObjectListener( xOldElement ); + Reference< XContent > xOldElement = implGetByName( _rName, impl_haveAnyListeners_nothrow() ); // do the removal - implRemove(_rName); + notifyByName( aGuard, _rName, NULL, xOldElement, E_REMOVED, ApproveListeners ); + implRemove( _rName ); + notifyByName( aGuard, _rName, NULL, xOldElement, E_REMOVED, ContainerListemers ); + removeObjectListener( xOldElement ); disposeComponent(xOldElement); - notifyByName(aGuard,_rName,NULL,xOldElement,E_REMOVED); } // XNameReplace //-------------------------------------------------------------------------- void SAL_CALL ODefinitionContainer::replaceByName( const ::rtl::OUString& _rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) { - ClearableMutexGuard aGuard(m_aMutex); + ResettableMutexGuard aGuard(m_aMutex); // let derived classes approve the new object Reference< XContent > xNewElement(aElement,UNO_QUERY); approveNewObject( _rName, xNewElement ); // will throw if necessary // the old element (for the notifications) - Reference< XContent > xOldElement = implGetByName(_rName, m_aContainerListeners.getLength() != 0); + Reference< XContent > xOldElement = implGetByName( _rName, impl_haveAnyListeners_nothrow() ); - // do the replace - implReplace(_rName, xNewElement); + notifyByName( aGuard, _rName, xNewElement, xOldElement, E_REPLACED, ApproveListeners ); + implReplace( _rName, xNewElement ); + notifyByName( aGuard, _rName, xNewElement, xOldElement, E_REPLACED, ContainerListemers ); // and dispose it disposeComponent(xOldElement); - notifyByName(aGuard,_rName,xNewElement,xOldElement,E_REPLACED); } // ----------------------------------------------------------------------------- -void ODefinitionContainer::notifyByName( ClearableMutexGuard& _rGuard - ,const ::rtl::OUString& _rName - ,const Reference< XContent >& _xNewElement - ,const Reference< XContent >& _xOldElement - ,ENotifyKind _eHowToNotify) +void ODefinitionContainer::notifyByName( ResettableMutexGuard& _rGuard, const ::rtl::OUString& _rName, + const Reference< XContent >& _xNewElement, const Reference< XContent >& _xOldElement, + ContainerOperation _eOperation, ListenerType _eType ) { + bool bApprove = ( _eType == ApproveListeners ); + + ::cppu::OInterfaceContainerHelper& rContainer( bApprove ? m_aApproveListeners : m_aContainerListeners ); + if ( !rContainer.getLength() ) + return; + + ContainerEvent aEvent( *this, makeAny( _rName ), makeAny( _xNewElement ), makeAny( _xOldElement ) ); + _rGuard.clear(); - // notify the listeners - if (m_aContainerListeners.getLength()) - { - ContainerEvent aEvent(*this, makeAny(_rName), makeAny(_xNewElement), makeAny(_xOldElement)); - OInterfaceIteratorHelper aListenerIterator(m_aContainerListeners); - while (aListenerIterator.hasMoreElements()) - { - switch( _eHowToNotify ) + switch ( _eOperation ) { + case E_INSERTED: + if ( bApprove ) + rContainer.notifyEach( &XContainerApproveListener::approveInsertElement, aEvent ); + else + rContainer.notifyEach( &XContainerListener::elementInserted, aEvent ); + break; case E_REPLACED: - static_cast< XContainerListener* >(aListenerIterator.next())->elementReplaced(aEvent); + if ( bApprove ) + rContainer.notifyEach( &XContainerApproveListener::approveReplaceElement, aEvent ); + else + rContainer.notifyEach( &XContainerListener::elementReplaced, aEvent ); break; case E_REMOVED: - static_cast< XContainerListener* >(aListenerIterator.next())->elementRemoved(aEvent); + if ( bApprove ) + rContainer.notifyEach( &XContainerApproveListener::approveRemoveElement, aEvent ); + else + rContainer.notifyEach( &XContainerListener::elementRemoved, aEvent ); break; - case E_INSERTED: - static_cast< XContainerListener* >(aListenerIterator.next())->elementInserted(aEvent); - break; - } - } } + + if ( bApprove ) + _rGuard.reset(); } //-------------------------------------------------------------------------- void SAL_CALL ODefinitionContainer::addContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException) { - MutexGuard aGuard(m_aMutex); if (_rxListener.is()) m_aContainerListeners.addInterface(_rxListener); } @@ -274,11 +286,25 @@ //-------------------------------------------------------------------------- void SAL_CALL ODefinitionContainer::removeContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException) { - MutexGuard aGuard(m_aMutex); if (_rxListener.is()) m_aContainerListeners.removeInterface(_rxListener); } +//-------------------------------------------------------------------------- +void SAL_CALL ODefinitionContainer::addContainerApproveListener( const Reference< XContainerApproveListener >& _Listener ) throw (RuntimeException) +{ + if ( _Listener.is() ) + m_aApproveListeners.addInterface( _Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL ODefinitionContainer::removeContainerApproveListener( const Reference< XContainerApproveListener >& _Listener ) throw (RuntimeException) +{ + if ( _Listener.is() ) + m_aApproveListeners.removeInterface( _Listener ); +} + + // XElementAccess //-------------------------------------------------------------------------- Type SAL_CALL ODefinitionContainer::getElementType( ) throw (RuntimeException) @@ -335,7 +361,7 @@ { MutexGuard aGuard(m_aMutex); - return makeAny(implGetByName(_rName)); + return makeAny( implGetByName( _rName, sal_True ) ); } //-------------------------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
