Tag: cws_src680_warnings01
User: sb      
Date: 06/04/07 13:47:03

Modified:
 /dba/dbaccess/source/core/dataaccess/
  databasedocument.cxx

Log:
 RESYNC: (1.24-1.26); FILE MERGED

File Changes:

Directory: /dba/dbaccess/source/core/dataaccess/
================================================

File [changed]: databasedocument.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.cxx?r1=1.24.22.1&r2=1.24.22.2
Delta lines:  +115 -80
----------------------
--- databasedocument.cxx        24 Mar 2006 15:35:52 -0000      1.24.22.1
+++ databasedocument.cxx        7 Apr 2006 20:47:01 -0000       1.24.22.2
@@ -105,6 +105,9 @@
 #ifndef _TOOLS_DEBUG_HXX
 #include <tools/debug.hxx>
 #endif
+#ifndef _CPPUHELPER_EXC_HLP_HXX_
+#include <cppuhelper/exc_hlp.hxx>
+#endif
 
 #ifndef BOOST_BIND_HPP_INCLUDED
 #include <boost/bind.hpp>
@@ -182,19 +185,15 @@
     {
         OSL_ENSURE(0,"Could not create GlobalEventBroadcaster!");
     }
-       Reference<XChild> xChild(m_pImpl->m_xForms.get(),UNO_QUERY);
-       if ( xChild.is() )
-               xChild->setParent(static_cast<OWeakObject*>(this));
 
-       xChild.set(m_pImpl->m_xReports.get(),UNO_QUERY);
-       if ( xChild.is() )
-               xChild->setParent(static_cast<OWeakObject*>(this));
-       xChild.set(m_pImpl->m_xTableDefinitions.get(),UNO_QUERY);
-       if ( xChild.is() )
-               xChild->setParent(static_cast<OWeakObject*>(this));
-       xChild.set(m_pImpl->m_xCommandDefinitions.get(),UNO_QUERY);
-       if ( xChild.is() )
-               xChild->setParent(static_cast<OWeakObject*>(this));
+    osl_incrementInterlockedCount( &m_refCount );
+    {
+        impl_reparent_nothrow( m_xForms );
+        impl_reparent_nothrow( m_xReports );
+        impl_reparent_nothrow( m_pImpl->m_xTableDefinitions );
+        impl_reparent_nothrow( m_pImpl->m_xCommandDefinitions );
+    }
+    osl_decrementInterlockedCount( &m_refCount );
 }
 //--------------------------------------------------------------------------
 ODatabaseDocument::~ODatabaseDocument()
@@ -254,15 +253,11 @@
 
         if ( m_pImpl->m_bOwnStorage )
                    ::comphelper::disposeComponent(m_pImpl->m_xStorage);
-               Reference< XNameAccess > xContainer = m_pImpl->m_xForms;
-               ::comphelper::disposeComponent(xContainer);
-               xContainer = m_pImpl->m_xReports;
-               ::comphelper::disposeComponent(xContainer);
-               xContainer = m_pImpl->m_xTableDefinitions;
-               ::comphelper::disposeComponent(xContainer);
 
-               xContainer = m_pImpl->m_xCommandDefinitions;
-               ::comphelper::disposeComponent(xContainer);
+        impl_clearObjectContainer( m_xForms );
+               impl_clearObjectContainer( m_xReports );
+               impl_clearObjectContainer( m_pImpl->m_xTableDefinitions );
+               impl_clearObjectContainer( m_pImpl->m_xCommandDefinitions );
 
                m_pImpl->m_aContainer.clear();
                m_pImpl->lateInit();
@@ -363,6 +358,20 @@
     
m_pImpl->m_aControllers.erase(::std::find(m_pImpl->m_aControllers.begin(),m_pImpl->m_aControllers.end(),_xController));
        if ( m_pImpl->m_xCurrentController == _xController )
                m_pImpl->m_xCurrentController = NULL;
+
+    if ( m_pImpl->m_aControllers.empty() )
+    {
+        // if this was the last view, close the document as a whole
+        // #i51157# / 2006-03-16 / [EMAIL PROTECTED]
+        try
+        {
+            close( sal_True );
+        }
+        catch( const CloseVetoException& )
+        {
+            // okay, somebody vetoed and took ownership
+        }
+    }
 }
 // 
-----------------------------------------------------------------------------
 void SAL_CALL ODatabaseDocument::lockControllers(  ) throw (RuntimeException)
@@ -464,9 +473,7 @@
        if ( m_pImpl->m_bDocumentReadOnly )
                throw IOException();
 
-    m_bCommitMasterStorage = sal_False;
     m_pImpl->commitStorages();
-    m_bCommitMasterStorage = sal_True;
 
        Reference<XStorage> xMyStorage = m_pImpl->getStorage();
     OSL_ENSURE( xMyStorage.is(), "ODatabaseDocument::storeToURL: no own 
storage?" );
@@ -503,16 +510,39 @@
                Sequence<Any> aParam(2);
                aParam[0] <<= _rURL;
                aParam[1] <<= ElementModes::READWRITE | ElementModes::TRUNCATE;
+
                Reference<XStorage> xStorage;
+        ::rtl::OUString sOriginalExceptionType;
+        ::rtl::OUString sOriginalExceptionMessage;
                try
                {
                        
xStorage.set(xStorageFactory->createInstanceWithArguments( aParam ),UNO_QUERY);
                }
-        catch(Exception&)
+        catch ( const Exception& e )
                {
+            Any aException( ::cppu::getCaughtException() );
+            sOriginalExceptionType = aException.getValueTypeName();
+            sOriginalExceptionMessage = e.Message;
                }
+
                if ( !xStorage.is() )
-                       throw IOException();
+        {
+            // TODO: localize this
+            ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii( 
"Could not store the database document to '" );
+            sMessage += _rURL;
+            sMessage += ::rtl::OUString::createFromAscii( "'." );
+            if ( sOriginalExceptionMessage.getLength() )
+            {
+                sMessage += ::rtl::OUString::createFromAscii( "\noriginal 
error message: " );
+                sMessage += sOriginalExceptionMessage;
+            }
+            if ( sOriginalExceptionType.getLength() )
+            {
+                sMessage += ::rtl::OUString::createFromAscii( "\noriginal 
error type: " );
+                sMessage += sOriginalExceptionType;
+            }
+                       throw IOException( sMessage, *this );
+        }
 
         if ( m_pImpl->isEmbeddedDatabase() )
             m_pImpl->clearConnections();
@@ -682,6 +712,53 @@
     DBG_ERROR( "ODatabaseDocument::print: not supported!" );
 }
 // 
-----------------------------------------------------------------------------
+void ODatabaseDocument::impl_reparent_nothrow( const WeakReference< 
XNameAccess >& _rxContainer )
+{
+       Reference< XChild > xChild( _rxContainer.get(), UNO_QUERY );
+       if  ( xChild.is() )
+               xChild->setParent( *this );
+}
+// 
-----------------------------------------------------------------------------
+void ODatabaseDocument::impl_clearObjectContainer( WeakReference< XNameAccess 
>& _rxContainer, bool _bResetAndRelease )
+{
+    Reference< XNameAccess > xContainer = _rxContainer;
+    ::comphelper::disposeComponent( xContainer );
+
+    if ( _bResetAndRelease )
+    {
+               Reference< XChild > xChild( _rxContainer.get(),UNO_QUERY );
+               if ( xChild.is() )
+                       xChild->setParent( NULL );
+        _rxContainer = Reference< XNameAccess >();
+    }
+}
+// 
-----------------------------------------------------------------------------
+Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( 
ODatabaseModelImpl::ObjectType _eType )
+{
+    ModelMethodGuard aGuard( *this );
+    OSL_POSTCOND( m_pImpl.is(), 
"ODatabaseDocument::impl_getDocumentContainer_throw: Impl is NULL" );
+
+    if ( ( _eType != ODatabaseModelImpl::E_FORM ) && ( _eType != 
ODatabaseModelImpl::E_REPORT ) )
+        throw IllegalArgumentException();
+
+    bool bFormsContainer = _eType == ODatabaseModelImpl::E_FORM;
+
+    WeakReference< XNameAccess >& rContainerRef( bFormsContainer ? m_xForms : 
m_xReports );
+    Reference< XNameAccess > xContainer = rContainerRef;
+       if ( !xContainer.is() )
+       {
+               if ( !m_pImpl->m_aContainer[ _eType ].get() )
+               {
+                       m_pImpl->m_aContainer[ _eType ] = TContentPtr( new 
ODefinitionContainer_Impl );
+                       m_pImpl->m_aContainer[ _eType ]->m_pDataSource = 
m_pImpl.get();
+                       m_pImpl->m_aContainer[ _eType ]->m_aProps.aTitle = 
::rtl::OUString::createFromAscii( bFormsContainer ? "forms" : "reports" );
+               }
+        rContainerRef = xContainer = new ODocumentContainer( 
m_pImpl->m_xServiceFactory, *this, m_pImpl->m_aContainer[ _eType ], 
bFormsContainer );
+        impl_reparent_nothrow( xContainer );
+       }
+       return xContainer;
+}
+// 
-----------------------------------------------------------------------------
 void ODatabaseDocument::impl_closeControllerFrames( sal_Bool 
_bDeliverOwnership )
 {
     ::std::vector< Reference< XController> > aCopy = m_pImpl->m_aControllers;
@@ -721,7 +798,6 @@
         aGuard.reset();
     }
 
-    DBG_ASSERT( m_pImpl->m_aControllers.empty(), "ODatabaseDocument::close: 
aren't controllers expected to veto the closing?" );
     impl_closeControllerFrames( _bDeliverOwnership );
 
     {
@@ -747,44 +823,12 @@
 // 
-----------------------------------------------------------------------------
 Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments(  ) 
throw (RuntimeException)
 {
-    ModelMethodGuard aGuard( *this );
-    OSL_ENSURE(m_pImpl.is(),"Impl is NULL");
-
-       Reference< XNameAccess > xContainer = m_pImpl->m_xForms;
-       if ( !xContainer.is() )
-       {
-               if ( !m_pImpl->m_aContainer[ODatabaseModelImpl::E_FORM].get() )
-               {
-                       ::rtl::OUString 
sName(RTL_CONSTASCII_USTRINGPARAM("forms"));
-                       m_pImpl->m_aContainer[ODatabaseModelImpl::E_FORM] = 
TContentPtr(new ODefinitionContainer_Impl);
-                       
m_pImpl->m_aContainer[ODatabaseModelImpl::E_FORM]->m_pDataSource = 
m_pImpl.get();
-                       
m_pImpl->m_aContainer[ODatabaseModelImpl::E_FORM]->m_aProps.aTitle = sName;
-               }
-               xContainer = new 
ODocumentContainer(m_pImpl->m_xServiceFactory,*this,m_pImpl->m_aContainer[ODatabaseModelImpl::E_FORM],sal_True);
-               m_pImpl->m_xForms = xContainer;
-       }
-       return xContainer;
+    return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM );
 }
 // 
-----------------------------------------------------------------------------
 Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments(  ) 
throw (RuntimeException)
 {
-    ModelMethodGuard aGuard( *this );
-    OSL_ENSURE(m_pImpl.is(),"Impl is NULL");
-
-       Reference< XNameAccess > xContainer = m_pImpl->m_xReports;
-       if ( !xContainer.is() )
-       {
-               if ( !m_pImpl->m_aContainer[ODatabaseModelImpl::E_REPORT].get() 
)
-               {
-                       m_pImpl->m_aContainer[ODatabaseModelImpl::E_REPORT] = 
TContentPtr(new ODefinitionContainer_Impl);
-                       ::rtl::OUString 
sName(RTL_CONSTASCII_USTRINGPARAM("reports"));
-                       
m_pImpl->m_aContainer[ODatabaseModelImpl::E_REPORT]->m_pDataSource = 
m_pImpl.get();
-                       
m_pImpl->m_aContainer[ODatabaseModelImpl::E_REPORT]->m_aProps.aTitle = sName;
-               }
-               xContainer = new 
ODocumentContainer(m_pImpl->m_xServiceFactory,*this,m_pImpl->m_aContainer[ODatabaseModelImpl::E_REPORT],sal_False);
-               m_pImpl->m_xReports = xContainer;
-       }
-       return xContainer;
+    return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT );
 }
 // 
-----------------------------------------------------------------------------
 sal_Bool ODatabaseDocument::WriteThroughComponent(
@@ -1060,8 +1104,8 @@
     }
 
     DBG_ASSERT( m_pImpl->m_aControllers.empty(), 
"ODatabaseDocument::disposing: there still are controllers!" );
-        // normally, nobody should explicitly dispose, but only 
XCloseable::close the document. And controllers
-        // are expected to veto the closing, so when we're here, there 
shouldn't be any controllers anymore.
+        // normally, nobody should explicitly dispose, but only 
XCloseable::close the document.An upon
+        // closing, our controllers are closed, too
     m_pImpl->m_aControllers.clear();
 
     Reference< XModel > xHoldAlive( this );
@@ -1079,19 +1123,10 @@
         m_xDocEventBroadcaster = NULL;
         m_xUIConfigurationManager = NULL;
 
-               Reference<XChild> xChild(m_pImpl->m_xForms.get(),UNO_QUERY);
-               if ( xChild.is() )
-                       xChild->setParent(NULL);
-
-               xChild.set(m_pImpl->m_xReports.get(),UNO_QUERY);
-               if ( xChild.is() )
-                       xChild->setParent(NULL);
-               xChild.set(m_pImpl->m_xTableDefinitions.get(),UNO_QUERY);
-               if ( xChild.is() )
-                       xChild->setParent(NULL);
-               xChild.set(m_pImpl->m_xCommandDefinitions.get(),UNO_QUERY);
-               if ( xChild.is() )
-                       xChild->setParent(NULL);
+        impl_clearObjectContainer( m_xForms, true );
+               impl_clearObjectContainer( m_xReports, true );
+               impl_clearObjectContainer( m_pImpl->m_xTableDefinitions, true );
+               impl_clearObjectContainer( m_pImpl->m_xCommandDefinitions, true 
);
 
         m_pImpl->modelIsDisposing( ODatabaseModelImpl::ResetModelAccess() );
     }




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to