Tag: cws_dev300_odbmacros3 User: fs Date: 2008-07-29 08:22:38+0000 Modified: dba/dbaccess/source/core/dataaccess/ModelImpl.cxx dba/dbaccess/source/core/dataaccess/ModelImpl.hxx dba/dbaccess/source/core/dataaccess/databasedocument.cxx dba/dbaccess/source/core/dataaccess/databasedocument.hxx
Log: #i76128# moved the InitState handling from ModelImpl to the DatabaseDocument, as it really only affects the latter File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: ModelImpl.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.cxx?r1=1.25.6.9&r2=1.25.6.10 Delta lines: +7 -18 -------------------- --- ModelImpl.cxx 2008-07-24 05:33:20+0000 1.25.6.9 +++ ModelImpl.cxx 2008-07-29 08:22:34+0000 1.25.6.10 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: ModelImpl.cxx,v $ - * $Revision: 1.25.6.9 $ + * $Revision: 1.25.6.10 $ * * This file is part of OpenOffice.org. * @@ -341,7 +341,6 @@ ,m_bHasAnyObjectWithMacros( false ) ,m_bHasMacroStorages( false ) ,m_bModificationLock( false ) - ,m_eInitState( NotInitialized ) ,m_aContext( _rxFactory ) ,m_nLoginTimeout(0) ,m_bReadOnly(sal_False) @@ -380,7 +379,6 @@ ,m_bHasAnyObjectWithMacros( false ) ,m_bHasMacroStorages( false ) ,m_bModificationLock( false ) - ,m_eInitState( NotInitialized ) ,m_aContext( _rxFactory ) ,m_sName(_rRegistrationName) ,m_nLoginTimeout(0) @@ -568,8 +566,6 @@ m_pStorageAccess->release(); m_pStorageAccess = NULL; } - - m_eInitState = NotInitialized; } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException) @@ -971,19 +967,12 @@ try { - if ( !isInitialized() ) - { // don't forward to the model if we are not yet initialized - m_bModified = _bModified; - } - else - { Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY ); if ( xModi.is() ) xModi->setModified( _bModified ); else m_bModified = _bModified; } - } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); @@ -1007,7 +996,7 @@ return m_xModel; } // ----------------------------------------------------------------------------- -Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitializeIfNecessary ) +Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize ) { Reference< XModel > xModel( m_xModel ); OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" ); @@ -1027,7 +1016,7 @@ DBG_UNHANDLED_EXCEPTION(); } - if ( _bInitializeIfNecessary && !isInitialized() ) + if ( _bInitialize ) { try { File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.24.4.5&r2=1.24.4.6 Delta lines: +3 -90 -------------------- --- ModelImpl.hxx 2008-07-29 07:09:56+0000 1.24.4.5 +++ ModelImpl.hxx 2008-07-29 08:22:35+0000 1.24.4.6 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: ModelImpl.hxx,v $ - * $Revision: 1.24.4.5 $ + * $Revision: 1.24.4.6 $ * * This file is part of OpenOffice.org. * @@ -201,13 +201,6 @@ E_TABLE = 3 }; - enum InitState - { - NotInitialized, - Initializing, - Initialized - }; - private: ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel; ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource > m_xDataSource; @@ -240,9 +233,6 @@ /// true if setting the Modified flag of the document is currently locked bool m_bModificationLock; - /// true if and only if the DatabaseDocument's "initNew" or "load" have been called - InitState m_eInitState; - /** the URL which the document should report as it's URL This might differ from ->m_sDocFileLocation in case the document was loaded @@ -399,7 +389,7 @@ @seealso getModel_noCreate */ - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership( bool _bInitializeIfNecessary ); + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership( bool _bInitialize ); struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } }; @@ -560,20 +550,6 @@ void unlockModify() { m_bModificationLock = false; } bool isModifyLocked() const { return m_bModificationLock; } - /** returns whether the model is currently being initialized - */ - bool isInitializing() const { return m_eInitState == Initializing; } - - /** returns whether the model is already initialized, i.e. the XModel's "initNew" or "load" methods have been called - */ - bool isInitialized() const { return m_eInitState == Initialized; } - - /// tells the model it is being initialized now - void setInitializing() { m_eInitState = Initializing; } - - /// tells the model its initialization is done - void setInitialized() { m_eInitState = Initialized; } - private: void impl_construct_nothrow(); ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > @@ -626,41 +602,6 @@ throw ::com::sun::star::lang::DisposedException( ::rtl::OUString::createFromAscii( "Component is already disposed." ), getThis() ); } - /** checks whether the component is already initialized, throws a NotInitializedException if not - - only to be called after checkDisposed! - */ - inline void checkInitialized() const - { - if ( !m_pImpl->isInitialized() ) - throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); - } - - /** checks the component is currently in the initialization phase, or already initialized. - Throws NotInitializedException if not so. - - only to be called after checkDisposed! - */ - inline void checkNotUninitilized() const - { - if ( m_pImpl->isInitialized() || m_pImpl->isInitializing() ) - // fine - return; - - throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); - } - - /** checks whether the component is currently being initialized, or already initialized, - throws a DoubleInitializationException if so - - only to be called after checkDisposed! - */ - inline void checkNotInitialized() const - { - if ( m_pImpl->isInitializing() || m_pImpl->isInitialized() ) - throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), getThis() ); - } - inline void lockModify() { m_pImpl->lockModify(); @@ -701,18 +642,6 @@ typedef ::osl::ResettableMutexGuard BaseMutexGuard; public: - enum MethodType - { - // a method which is to initialize the document - InitMethod, - // a default method - DefaultMethod, - // a method which is used (externally) during the initialization phase - MethodUsedDuringInit, - // a method which does not need initialization - use with care! - MethodWithoutInit - }; - /** constructs the guard @param _component @@ -720,27 +649,11 @@ @throws ::com::sun::star::lang::DisposedException If the given component is already disposed - - @throws ::com::sun::star::frame::DoubleInitializationException - if _eType is InitMethod, and the given component is already initialized, or currently being initialized. - - @throws ::com::sun::star::lang::NotInitializedException - if _eType is DefaultMethod, and the given component is not yet initialized; or if _eType - is MethodUsedDuringInit, and the component is still uninitialized, and not in the initialization - phase currently. */ - ModelMethodGuard( const ModelDependentComponent& _component, MethodType _eType = DefaultMethod ) + ModelMethodGuard( const ModelDependentComponent& _component ) :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) ) { _component.checkDisposed(); - - switch ( _eType ) - { - case InitMethod: _component.checkNotInitialized(); break; - case DefaultMethod: _component.checkInitialized(); break; - case MethodUsedDuringInit: _component.checkNotUninitilized(); break; - case MethodWithoutInit: break; - } } ~ModelMethodGuard() File [changed]: databasedocument.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.cxx?r1=1.40.6.13&r2=1.40.6.14 Delta lines: +102 -78 ---------------------- --- databasedocument.cxx 2008-07-29 07:10:54+0000 1.40.6.13 +++ databasedocument.cxx 2008-07-29 08:22:35+0000 1.40.6.14 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: databasedocument.cxx,v $ - * $Revision: 1.40.6.13 $ + * $Revision: 1.40.6.14 $ * * This file is part of OpenOffice.org. * @@ -158,6 +158,7 @@ ,m_pEventExecutor( NULL ) // initialized below, ref-count-protected ,m_aEventNotifier( *this, getMutex() ) ,m_aViewMonitor( m_aEventNotifier ) + ,m_eInitState( NotInitialized ) { DBG_CTOR(ODatabaseDocument,NULL); @@ -320,6 +321,15 @@ } // ----------------------------------------------------------------------------- +void ODatabaseDocument::impl_setInitialized() +{ + m_eInitState = Initialized; + + // start event notifications + m_aEventNotifier.onDocumentInitialized(); +} + +// ----------------------------------------------------------------------------- void ODatabaseDocument::impl_reset_nothrow() { try @@ -333,6 +343,8 @@ clearObjectContainer( m_pImpl->m_xTableDefinitions ); clearObjectContainer( m_pImpl->m_xCommandDefinitions ); + m_eInitState = NotInitialized; + m_pImpl->reset(); } catch(const Exception&) @@ -367,11 +379,11 @@ void SAL_CALL ODatabaseDocument::initNew( ) throw (DoubleInitializationException, IOException, Exception, RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this, ModelMethodGuard::InitMethod ); + DocumentGuard aGuard( *this, DocumentGuard::InitMethod ); impl_reset_nothrow(); - m_pImpl->setInitializing(); + impl_setInitializing(); // create a temporary storage Reference< XStorage > xTempStor( ::comphelper::OStorageHelper::GetTemporaryStorage( @@ -383,7 +395,7 @@ // let the impl know we're now based on this storage m_pImpl->switchToStorage( xTempStor ); - m_pImpl->setInitialized(); + impl_setInitialized(); m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" ); @@ -399,7 +411,7 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Arguments ) throw (DoubleInitializationException, IOException, Exception, RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this, ModelMethodGuard::InitMethod ); + DocumentGuard aGuard( *this, DocumentGuard::InitMethod ); impl_reset_nothrow(); @@ -410,7 +422,7 @@ m_pImpl->setImposedMacroExecMode( aResource.getOrDefault( "MacroExecutionMode", m_pImpl->getImposedMacroExecMode() ) ); - m_pImpl->setInitializing(); + impl_setInitializing(); try { impl_import_throw( aResource ); @@ -420,7 +432,11 @@ impl_reset_nothrow(); throw; } - // note that we do *not* call m_pImpl->setInitialized here: The initialization is only complete + // tell our view monitor that the document has been loaded - this way it will fire the proper + // even (OnLoad instead of OnCreate) later on + m_aViewMonitor.onLoadedDocument(); + + // note that we do *not* call impl_setInitialized() here: The initialization is only complete // when the XModel::attachResource has been called, not sooner. impl_setModified_nothrow( sal_False, aGuard ); @@ -431,13 +447,13 @@ // XModel sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); m_pImpl->attachResource( _rURL, _rArguments ); - if ( m_pImpl->isInitializing() ) + if ( impl_isInitializing() ) { // this means we've just been loaded, and this is the attachResource call which follows // the load call. - m_pImpl->setInitialized(); + impl_setInitialized(); m_aEventNotifier.notifyDocumentEvent( "OnLoadFinished" ); } @@ -447,21 +463,21 @@ // ----------------------------------------------------------------------------- ::rtl::OUString SAL_CALL ODatabaseDocument::getURL( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getURL(); } // ----------------------------------------------------------------------------- Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getResource(); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::connectController( const Reference< XController >& _xController ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aControllers.push_back( _xController ); @@ -476,7 +492,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::disconnectController( const Reference< XController >& _xController ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); Controllers::iterator pos = ::std::find( m_aControllers.begin(), m_aControllers.end(), _xController ); OSL_ENSURE( pos != m_aControllers.end(), "ODatabaseDocument::disconnectController: don't know this controller!" ); @@ -504,7 +520,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::lockControllers( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); ++m_pImpl->m_nControllerLockCount; } @@ -512,7 +528,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::unlockControllers( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); --m_pImpl->m_nControllerLockCount; } @@ -520,7 +536,7 @@ // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::hasControllersLocked( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->m_nControllerLockCount != 0; } @@ -528,7 +544,7 @@ // ----------------------------------------------------------------------------- Reference< XController > SAL_CALL ODatabaseDocument::getCurrentController() throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_xCurrentController.is() ? m_xCurrentController : ( m_aControllers.empty() ? Reference< XController >() : *m_aControllers.begin() ); } @@ -536,7 +552,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XController >& _xController ) throw (NoSuchElementException, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_xCurrentController = _xController; @@ -545,7 +561,7 @@ // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); Reference< XInterface > xRet; Reference< XSelectionSupplier > xDocView( getCurrentController(), UNO_QUERY ); @@ -559,26 +575,25 @@ // XStorable sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getLocation().getLength() > 0; } // ----------------------------------------------------------------------------- ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getLocation(); } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); - + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->m_bDocumentReadOnly; } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); if ( m_pImpl->getLocation() == m_pImpl->getURL() ) if ( m_pImpl->m_bDocumentReadOnly ) @@ -589,11 +604,17 @@ // ----------------------------------------------------------------------------- void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const Sequence< PropertyValue>& _rArguments, - const StoreType _eType, ModelMethodGuard& _rGuard ) + const StoreType _eType, DocumentGuard& _rGuard ) { OSL_PRECOND( ( _eType == SAVE ) || ( _eType == SAVE_AS ), "ODatabaseDocument::impl_storeAs_throw: you introduced a new type which cannot be handled here!" ); + // if we're in the process of initializing the document (which effectively means it is an implicit + // initialization triggered in storeAsURL), the we do not notify events, since to an observer, the SaveAs + // should not be noticable + bool bIsInitializationProcess = impl_isInitializing(); + + if ( !bIsInitializationProcess ) { _rGuard.clear(); m_aEventNotifier.notifyDocumentEvent( _eType == SAVE ? "OnSave" : "OnSaveAs" ); @@ -642,17 +663,19 @@ m_pImpl->attachResource( _rURL, aMediaDescriptor ); // if we are in an initialization process, then this is finished, now that we stored the document - if ( m_pImpl->isInitializing() ) - m_pImpl->setInitialized(); + if ( bIsInitializationProcess ) + impl_setInitialized(); } catch( const Exception& ) { // notify the failure + if ( !bIsInitializationProcess ) m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed" ); throw; } // notify the document event + if ( !bIsInitializationProcess ) m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveDone" : "OnSaveAsDone" ); // reset our "modified" flag, and clear the guard @@ -679,18 +702,18 @@ void SAL_CALL ODatabaseDocument::storeAsURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); // Normally, a document initialization is done via XLoadable::load or XLoadable::initNew. For convenience // reasons, and to not break existing API clients, it's allowed to call storeAsURL without having initialized // the document, in which case the initialization will be done implicitly. - bool bImplicitInitialization = !m_pImpl->isInitialized(); + bool bImplicitInitialization = !impl_isInitialized(); // implicit initialization while another initialization is just running is not possible - if ( bImplicitInitialization && m_pImpl->isInitializing() ) + if ( bImplicitInitialization && impl_isInitializing() ) throw DoubleInitializationException(); if ( bImplicitInitialization ) - m_pImpl->setInitializing(); + impl_setInitializing(); try { @@ -707,10 +730,6 @@ // updates its title only if it gets the OnSaveAsDone event (which was sent asynchronously // by impl_storeAs_throw). So, we simply notify always, and also asynchronously m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" ); - - // tell our view monitor that the document has been loaded - this way it will fire the proper - // even (OnLoad instead of OnCreate) later on - m_aViewMonitor.onLoadedDocument(); } catch( const Exception& ) { @@ -740,7 +759,7 @@ m_pImpl->commitStorages(); // copy own storage to target storage - if ( m_pImpl->isInitialized() ) + if ( impl_isInitialized() ) { Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_QUERY_THROW ); if ( xCurrentStorage != _rxTargetStorage ) @@ -765,7 +784,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); ModifyLock aLock( *this ); // create storage for target URL @@ -782,14 +801,14 @@ // XModifyBroadcaster void SAL_CALL ODatabaseDocument::addModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aModifyListeners.addInterface(_xListener); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::removeModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aModifyListeners.removeInterface(_xListener); } @@ -797,7 +816,7 @@ // XModifiable sal_Bool SAL_CALL ODatabaseDocument::isModified( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->m_bModified; } @@ -805,12 +824,16 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::setModified( sal_Bool _bModified ) throw (PropertyVetoException, RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); + if ( impl_isInitialized() ) impl_setModified_nothrow( _bModified, aGuard ); + // it's allowed to call setModified without the document being initialized already. In this case, + // we simply ignore the call - when the initialization is finished, the respective code will set + // a proper "modified" flag } // ----------------------------------------------------------------------------- -void ODatabaseDocument::impl_setModified_nothrow( sal_Bool _bModified, ModelMethodGuard& _rGuard ) +void ODatabaseDocument::impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard ) { // SYNCHRONIZED -> bool bModifiedChanged = ( m_pImpl->m_bModified != _bModified ) && ( !m_pImpl->isModifyLocked() ); @@ -834,14 +857,14 @@ // ::com::sun::star::document::XEventBroadcaster void SAL_CALL ODatabaseDocument::addEventListener(const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); m_aEventNotifier.addDocumentEventListener( _Listener ); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::removeEventListener( const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); m_aEventNotifier.removeDocumentEventListener( _Listener ); } @@ -959,7 +982,7 @@ // everything below can/must be done without our mutex locked, the below is just for // the checks for being disposed and the like { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); } // allow listeners to veto @@ -979,25 +1002,25 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::addCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aCloseListener.addInterface(Listener); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::removeCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aCloseListener.removeInterface(Listener); } // ----------------------------------------------------------------------------- Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM ); } // ----------------------------------------------------------------------------- Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT ); } @@ -1101,7 +1124,7 @@ // ----------------------------------------------------------------------------- Reference< XUIConfigurationManager > SAL_CALL ODatabaseDocument::getUIConfigurationManager( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); if ( !m_xUIConfigurationManager.is() ) { @@ -1139,7 +1162,7 @@ // ----------------------------------------------------------------------------- Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() ); return xStorageAccess->getDocumentSubStorage( aStorageName, nMode ); @@ -1170,6 +1193,7 @@ return; } + if ( impl_isInitialized() ) m_aEventNotifier.notifyDocumentEvent( "OnUnload" ); Reference< XModel > xHoldAlive( this ); @@ -1279,14 +1303,14 @@ // ----------------------------------------------------------------------------- Reference< XDataSource > SAL_CALL ODatabaseDocument::getDataSource() throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodWithoutInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getOrCreateDataSource(); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::loadFromStorage( const Reference< XStorage >& /*xStorage*/, const Sequence< PropertyValue >& /*aMediaDescriptor*/ ) throw (IllegalArgumentException, DoubleInitializationException, IOException, Exception, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); throw Exception( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Embedding of database documents is not supported." ) ), @@ -1298,7 +1322,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::storeToStorage( const Reference< XStorage >& _rxStorage, const Sequence< PropertyValue >& _rMediaDescriptor ) throw (IllegalArgumentException, IOException, Exception, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); impl_storeToStorage_throw( _rxStorage, _rMediaDescriptor ); } @@ -1306,7 +1330,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::switchToStorage( const Reference< XStorage >& _rxNewRootStorage ) throw (IllegalArgumentException, IOException, Exception, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); Reference< XStorage > xNewRootStorage( m_pImpl->switchToStorage( _rxNewRootStorage ) ); @@ -1317,56 +1341,56 @@ // ----------------------------------------------------------------------------- Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentStorage( ) throw (IOException, Exception, RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->getOrCreateRootStorage(); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::addStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aStorageListeners.addInterface( _Listener ); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::removeStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); m_aStorageListeners.addInterface( _Listener ); } // ----------------------------------------------------------------------------- Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getBasicLibraries() throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->getLibraryContainer( true ); } // ----------------------------------------------------------------------------- Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getDialogLibraries() throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->getLibraryContainer( false ); } // ----------------------------------------------------------------------------- ::sal_Bool SAL_CALL ODatabaseDocument::getAllowMacroExecution() throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return m_pImpl->adjustMacroMode_AutoReject(); } // ----------------------------------------------------------------------------- Reference< XEmbeddedScripts > SAL_CALL ODatabaseDocument::getScriptContainer() throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return this; } // ----------------------------------------------------------------------------- Reference< provider::XScriptProvider > SAL_CALL ODatabaseDocument::getScriptProvider( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); Reference< XScriptProvider > xScriptProvider( m_xScriptProvider ); if ( !xScriptProvider.is() ) @@ -1388,7 +1412,7 @@ // ----------------------------------------------------------------------------- Reference< XNameReplace > SAL_CALL ODatabaseDocument::getEvents( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); return m_pEventContainer; } @@ -1416,7 +1440,7 @@ // XModel2 Reference< XEnumeration > SAL_CALL ODatabaseDocument::getControllers( ) throw (RuntimeException) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); uno::Sequence< Any> aController( m_aControllers.size() ); ::std::transform( m_aControllers.begin(), m_aControllers.end(), aController.getArray(), CreateAny() ); return new ::comphelper::OAnyEnumeration(aController); @@ -1446,7 +1470,7 @@ if ( !_Frame.is() ) throw IllegalArgumentException( ::rtl::OUString(), *this, 3 ); - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); ::comphelper::ComponentContext aContext( m_pImpl->m_aContext ); aGuard.clear(); @@ -1524,7 +1548,7 @@ throw (uno::RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this, ModelMethodGuard::MethodUsedDuringInit ); + DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); return impl_getTitleHelper_throw()->getTitle(); } @@ -1534,7 +1558,7 @@ throw (uno::RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); impl_getTitleHelper_throw()->setTitle( sTitle ); m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" ); // <- SYNCHRONIZED @@ -1546,7 +1570,7 @@ throw (uno::RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW ); xBroadcaster->addTitleChangeListener( xListener ); @@ -1558,7 +1582,7 @@ throw (uno::RuntimeException) { // SYNCHRONIZED -> - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW ); xBroadcaster->removeTitleChangeListener( xListener ); @@ -1570,7 +1594,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException ) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); return impl_getUntitledHelper_throw(xComponent)->leaseNumber (xComponent); } @@ -1580,7 +1604,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException ) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); impl_getUntitledHelper_throw()->releaseNumber (nNumber); } @@ -1590,7 +1614,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException ) { - ModelMethodGuard aGuard( *this ); + DocumentGuard aGuard( *this ); impl_getUntitledHelper_throw(xComponent)->releaseNumberForComponent (xComponent); } File [changed]: databasedocument.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.hxx?r1=1.20.2.8&r2=1.20.2.9 Delta lines: +110 -3 --------------------- --- databasedocument.hxx 2008-07-29 07:10:54+0000 1.20.2.8 +++ databasedocument.hxx 2008-07-29 08:22:35+0000 1.20.2.9 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: databasedocument.hxx,v $ - * $Revision: 1.20.2.8 $ + * $Revision: 1.20.2.9 $ * * This file is part of OpenOffice.org. * @@ -84,6 +84,7 @@ class DocumentEvents; class DocumentEventExecutor; +class DocumentGuard; typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > > Controllers; @@ -166,6 +167,13 @@ ,public ODatabaseDocument_OfficeDocument ,public ODatabaseDocument_Title { + enum InitState + { + NotInitialized, + Initializing, + Initialized + }; + DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::frame::XUntitledNumbers >,TNumberedController); ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager> m_xUIConfigurationManager; @@ -190,6 +198,11 @@ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > m_xTitleHelper; TNumberedController m_aNumberedControllers; + /** true if and only if the DatabaseDocument's "initNew" or "load" have been called (or, well, + the document has be initialized implicitly - see storeAsURL + */ + InitState m_eInitState; + enum StoreType { SAVE, SAVE_AS }; /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets the modified flag, and notifies any listeners as required @@ -208,7 +221,7 @@ const ::rtl::OUString& _rURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rArguments, const StoreType _eType, - ModelMethodGuard& _rGuard + DocumentGuard& _rGuard ); /** notifies our storage change listeners that our underlying storage changed @@ -426,7 +439,50 @@ static void clearObjectContainer( ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >& _rxContainer); + /** checks whether the component is already initialized, throws a NotInitializedException if not + */ + inline void checkInitialized() const + { + if ( !impl_isInitialized() ) + throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); + } + + /** checks the document is currently in the initialization phase, or already initialized. + Throws NotInitializedException if not so. + */ + inline void checkNotUninitilized() const + { + if ( impl_isInitialized() || impl_isInitializing() ) + // fine + return; + + throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); + } + + /** checks whether the document is currently being initialized, or already initialized, + throws a DoubleInitializationException if so + */ + inline void checkNotInitialized() const + { + if ( impl_isInitializing() || impl_isInitialized() ) + throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), getThis() ); + } + private: + /** returns whether the model is currently being initialized + */ + bool impl_isInitializing() const { return m_eInitState == Initializing; } + + /** returns whether the model is already initialized, i.e. the XModel's "initNew" or "load" methods have been called + */ + bool impl_isInitialized() const { return m_eInitState == Initialized; } + + /// tells the model it is being initialized now + void impl_setInitializing() { m_eInitState = Initializing; } + + /// tells the model its initialization is done + void impl_setInitialized(); + /** closes the frames of all connected controllers @param _bDeliverOwnership @@ -498,7 +554,7 @@ @postcond our mutex is not locked */ - void impl_setModified_nothrow( sal_Bool _bModified, ModelMethodGuard& _rGuard ); + void impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard ); /** stores the document to the given storage @@ -528,6 +584,57 @@ */ }; +/** an extended version of the ModelMethodGuard, which also cares for the initialization state + of the document +*/ +class DocumentGuard : public ModelMethodGuard +{ +public: + enum MethodType + { + // a method which is to initialize the document + InitMethod, + // a default method + DefaultMethod, + // a method which is used (externally) during the initialization phase + MethodUsedDuringInit, + // a method which does not need initialization - use with care! + MethodWithoutInit + }; + + /** constructs the guard + + @param _document + the ODatabaseDocument instance + + @throws ::com::sun::star::lang::DisposedException + If the given component is already disposed + + @throws ::com::sun::star::frame::DoubleInitializationException + if _eType is InitMethod, and the given component is already initialized, or currently being initialized. + + @throws ::com::sun::star::lang::NotInitializedException + if _eType is DefaultMethod, and the given component is not yet initialized; or if _eType + is MethodUsedDuringInit, and the component is still uninitialized, and not in the initialization + phase currently. + */ + DocumentGuard( const ODatabaseDocument& _document, MethodType _eType = DefaultMethod ) + :ModelMethodGuard( _document ) + { + switch ( _eType ) + { + case InitMethod: _document.checkNotInitialized(); break; + case DefaultMethod: _document.checkInitialized(); break; + case MethodUsedDuringInit: _document.checkNotUninitilized(); break; + case MethodWithoutInit: break; + } + } + + ~DocumentGuard() + { + } +}; + //........................................................................ } // namespace dbaccess //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
