Tag: cws_src680_qiq
User: fs      
Date: 06/05/24 02:11:16

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

Log:
 #i51143# more detailed error messages during approveNewObject

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&r2=1.21.4.1
Delta lines:  +77 -72
---------------------
--- definitioncontainer.cxx     4 May 2006 08:38:06 -0000       1.21
+++ definitioncontainer.cxx     24 May 2006 09:11:14 -0000      1.21.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: definitioncontainer.cxx,v $
  *
- *  $Revision: 1.21 $
+ *  $Revision: 1.21.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2006/05/04 08:38:06 $
+ *  last change: $Author: fs $ $Date: 2006/05/24 09:11:14 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -181,30 +181,19 @@
 {
        ClearableMutexGuard aGuard(m_aMutex);
        
-       implInsert(_rName,aElement);
-
-       Reference< XContent > xNewElement(aElement,UNO_QUERY);
-       notifyByName(aGuard,_rName,xNewElement,NULL,E_INSERTED);
-}
-// 
-----------------------------------------------------------------------------
-void ODefinitionContainer::implInsert(const ::rtl::OUString& _rName, const 
Any& aElement)
-{
-       if (checkExistence(_rName))
-               throw ElementExistException(_rName,*this);
-
        // approve the new object
        Reference< XContent > xNewElement(aElement,UNO_QUERY);
-       if (!approveNewObject(_rName,xNewElement))
-               throw IllegalArgumentException();
+       approveNewObject( _rName, xNewElement );  // will throw if necessary
 
-       implAppend(_rName, xNewElement);
+       implAppend( _rName, xNewElement );
+
+       notifyByName(aGuard,_rName,xNewElement,NULL,E_INSERTED);
 }
+
 //--------------------------------------------------------------------------
 void SAL_CALL ODefinitionContainer::removeByName( const ::rtl::OUString& 
_rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
 {
-       Reference< XContent > xOldElement;
        ClearableMutexGuard aGuard(m_aMutex);
-       {
                // check the arguments
                if (!_rName.getLength())
                        throw IllegalArgumentException();
@@ -213,16 +202,14 @@
                        throw NoSuchElementException(_rName,*this);
 
                // the old element (for the notifications)
-               xOldElement = implGetByName(_rName, 
(m_aContainerListeners.getLength() != 0));
-                       // as this is potentially expensive (if the object is 
not already created and initialized from the registry)
-                       // we load the element only if we have listeners which 
may be interested in
+       Reference< XContent > xOldElement = implGetByName(_rName, 
(m_aContainerListeners.getLength() != 0));
+       removeObjectListener( xOldElement );
 
                // do the removal
                implRemove(_rName);
 
-               //      disposeComponent(xOldElement); // no dispose here, the 
object amy be inserted again unde a different name
-       }
-       notifyByName(aGuard,_rName,NULL,NULL,E_REMOVED);
+       disposeComponent(xOldElement);
+    notifyByName(aGuard,_rName,NULL,xOldElement,E_REMOVED);
 }
 
 // XNameReplace
@@ -231,20 +218,12 @@
 {
        ClearableMutexGuard aGuard(m_aMutex);
 
-       // check the arguments
-       if (!_rName.getLength())
-               throw IllegalArgumentException();
-
        // let derived classes approve the new object
        Reference< XContent > xNewElement(aElement,UNO_QUERY);
-       if (!approveNewObject(_rName,xNewElement))
-               throw IllegalArgumentException();
-
+       approveNewObject( _rName, xNewElement );    // will throw if necessary
 
        // the old element (for the notifications)
        Reference< XContent > xOldElement = implGetByName(_rName, 
m_aContainerListeners.getLength() != 0);
-               // as this is potentially expensive (if the object is not 
already created and initialized from the registry)
-               // we get the element only if we have listeners which may be 
interested in
 
        // do the replace
        implReplace(_rName, xNewElement);
@@ -557,18 +536,42 @@
        aFind->second = _rxNewObject;
        addObjectListener(aFind->second);
 }
+
 // 
-----------------------------------------------------------------------------
-sal_Bool ODefinitionContainer::approveNewObject(const ::rtl::OUString& 
_sName,const Reference< XContent >& _rxObject) const
+void ODefinitionContainer::approveNewObject(const ::rtl::OUString& 
_sName,const Reference< XContent >& _rxObject) const
 {
-       Reference<XUnoTunnel> xUnoTunnel(_rxObject,UNO_QUERY);
+       // check the arguments
+       if ( !_sName.getLength() )
+        throw IllegalArgumentException(
+            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The name must not 
be empty." ) ),
+            *this,
+            0 );
+        // TODO: resource
+
+       if ( !_rxObject.is() )
+        throw IllegalArgumentException(
+            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The container 
cannot contain NULL objects." ) ),
+            *this,
+            0 );
+        // TODO: resource
+
        ::rtl::Reference<OContentHelper> pContent = NULL;
-       sal_Bool bRet = sal_False;
        ODefinitionContainer_Impl* pItem = 
static_cast<ODefinitionContainer_Impl*>(m_pImpl.get());
        ODefinitionContainer_Impl::Documents::iterator aFind = 
pItem->m_aDocumentMap.find(_sName);
-       if ( aFind == pItem->m_aDocumentMap.end() )
-       {
-               if ( bRet = xUnoTunnel.is() )
-               {
+    if ( aFind != pItem->m_aDocumentMap.end() )
+        throw ElementExistException(
+            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There already is an 
object with the given name." ) ),
+            *this );
+        // TODO: resource
+
+       Reference< XUnoTunnel > xUnoTunnel( _rxObject, UNO_QUERY );
+    if ( !xUnoTunnel.is() )
+        throw IllegalArgumentException(
+            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This object cannot 
be part of this container." ) ),
+            *this,
+            1 );
+        // TODO: resource
+
                        pContent = 
reinterpret_cast<OContentHelper*>(xUnoTunnel->getSomething(OContentHelper::getUnoTunnelImplementationId()));
                        TContentPtr pImpl = pContent->getImpl();
                        ODefinitionContainer_Impl::Documents::iterator aIter =
@@ -581,11 +584,13 @@
                                        )
                                );
 
-                       bRet = aIter == pItem->m_aDocumentMap.end();
-               }
-       }
-       return bRet;
+    if ( aIter != pItem->m_aDocumentMap.end() )
+        throw ElementExistException(
+            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The object is 
already part of the container - under a different name." ) ),
+            *this );
+        // TODO: resource
 }
+
 // 
-----------------------------------------------------------------------------
 // XPropertyChangeListener
 void SAL_CALL ODefinitionContainer::propertyChange( const PropertyChangeEvent& 
evt ) throw (RuntimeException)
@@ -599,10 +604,10 @@
                        ::rtl::OUString sNewName,sOldName;
                        evt.OldValue >>= sOldName;
                        evt.NewValue >>= sNewName;
-                       Reference<XContent> xProp(evt.Source,UNO_QUERY);
-                       removeObjectListener(xProp);
-                       implRemove(sOldName);
-                       implInsert(sNewName,makeAny(evt.Source));
+                       Reference<XContent> xContent( evt.Source, UNO_QUERY );
+                       removeObjectListener( xContent );
+            implRemove( sOldName );
+                       implAppend( sNewName, xContent );
                }
                catch(const Exception&)
                {




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

Reply via email to