User: kz      
Date: 05/01/21 09:03:03

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

Log:
 INTEGRATION: CWS dba22 (1.25.2); FILE MERGED
 2004/12/20 15:11:18 fs 1.25.2.1: #i39187# better granularity of error handling 
- callers can now determine whether a registered object they're asking for 
points to a non-existent URL

File Changes:

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

File [changed]: databasecontext.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasecontext.cxx?r1=1.25&r2=1.26
Delta lines:  +65 -39
---------------------
--- databasecontext.cxx 17 Nov 2004 14:43:12 -0000      1.25
+++ databasecontext.cxx 21 Jan 2005 17:02:59 -0000      1.26
@@ -96,6 +96,15 @@
 #ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
 #include <com/sun/star/beans/NamedValue.hpp>
 #endif
+#ifndef _COM_SUN_STAR_TASK_INTERACTIONCLASSIFICATION_HPP_
+#include <com/sun/star/task/InteractionClassification.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UCB_IOERRORCODE_HPP_
+#include <com/sun/star/ucb/IOErrorCode.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#endif
 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
 #include <cppuhelper/typeprovider.hxx>
 #endif
@@ -156,6 +165,10 @@
 using namespace ::osl;
 using namespace ::utl;
 
+using ::com::sun::star::task::InteractionClassification_ERROR;
+using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
+using ::com::sun::star::ucb::InteractiveIOException;
+
 //==========================================================================
 
 extern "C" void SAL_CALL createRegistryInfo_ODatabaseContext()
@@ -309,6 +322,25 @@
        m_aDatabaseObjects.clear();
 }
 
+//------------------------------------------------------------------------------
+bool ODatabaseContext::getURLForRegisteredObject( const ::rtl::OUString& 
_rRegisteredName, ::rtl::OUString& _rURL )
+{
+       if ( !_rRegisteredName.getLength() )
+               throw IllegalArgumentException();
+       
+       // the config node where all pooling relevant info are stored under
+       OConfigurationTreeRoot aDbRegisteredNamesRoot = 
OConfigurationTreeRoot::createWithServiceFactory(
+               m_xServiceManager, getDbRegisteredNamesNodeName(), -1, 
OConfigurationTreeRoot::CM_READONLY);
+       if ( aDbRegisteredNamesRoot.isValid() && 
aDbRegisteredNamesRoot.hasByName( _rRegisteredName ) )
+       {
+               OConfigurationNode aRegisterObj = 
aDbRegisteredNamesRoot.openNode( _rRegisteredName );
+               aRegisterObj.getNodeValue(getDbLocationNodeName()) >>= _rURL;
+               _rURL = SvtPathOptions().SubstituteVariable( _rURL );
+        return true;
+       }
+    return false;
+}
+
 // XNamingService
 
//------------------------------------------------------------------------------
 Reference< XInterface >  ODatabaseContext::getRegisteredObject(const 
rtl::OUString& _rName) throw( Exception, RuntimeException )
@@ -317,28 +349,20 @@
        if (DatabaseAccessContext_Base::rBHelper.bDisposed)
                throw DisposedException();
 
-       if (!_rName.getLength())
-               throw IllegalArgumentException();
-       
        ::rtl::OUString sURL;
-       // the config node where all pooling relevant info are stored under
-       OConfigurationTreeRoot aDbRegisteredNamesRoot = 
OConfigurationTreeRoot::createWithServiceFactory(
-               m_xServiceManager, getDbRegisteredNamesNodeName(), -1, 
OConfigurationTreeRoot::CM_READONLY);
-       if ( aDbRegisteredNamesRoot.isValid() && 
aDbRegisteredNamesRoot.hasByName(_rName) )
-       {
-               OConfigurationNode aThisDriverSettings = 
aDbRegisteredNamesRoot.openNode(_rName);
-               aThisDriverSettings.getNodeValue(getDbLocationNodeName()) >>= 
sURL;
-               sURL = SvtPathOptions().SubstituteVariable(sURL);
+    if ( !getURLForRegisteredObject( _rName, sURL ) )
+        NoSuchElementException();
+
+       if ( !sURL.getLength() )
+        // there is a registration for this name, but no URL
+               throw IllegalArgumentException();
 
                // check if URL is already loaded
-               Reference< XInterface > xExistent = getObject(sURL);
+       Reference< XInterface > xExistent = getObject( sURL );
                if ( xExistent.is() )
                        return xExistent;
-       }
-       if ( !sURL.getLength() )
-               throw IllegalArgumentException();
        
-       return loadObjectFromURL(_rName,sURL);
+       return loadObjectFromURL( _rName, sURL );
 }
 // 
-----------------------------------------------------------------------------
 Reference< XInterface > ODatabaseContext::loadObjectFromURL(const 
::rtl::OUString& _rName,const ::rtl::OUString& _sURL)
@@ -347,16 +371,17 @@
        {
                ::ucb::Content aContent(_sURL,Reference< 
::com::sun::star::ucb::XCommandEnvironment >());
                if ( !aContent.isDocument() )
-                       throw IllegalArgumentException(_sURL, 
Reference<XNamingService>(this),1);
+                       throw InteractiveIOException(
+                _sURL, *this, InteractionClassification_ERROR, 
IOErrorCode_NO_FILE
+            );
        }
-       catch(IllegalArgumentException)
+       catch(InteractiveIOException e)
        {
-               throw;
+               throw WrappedTargetException( _sURL, 
Reference<XNamingService>(this), makeAny( e ) );
        }
-       catch(Exception)
+       catch(Exception e)
        {
-               throw IllegalArgumentException(_sURL, 
Reference<XNamingService>(this),1);
-               OSL_ENSURE(0,"Exception catched!");
+               throw WrappedTargetException( _sURL, 
Reference<XNamingService>(this), makeAny( e ) );
        }
 
        Reference< XInterface > xExistent = *(new ODatabaseSource(*this, 
_rName, m_xServiceManager,this));
@@ -599,20 +624,21 @@
                if ( xExistent.is() )
                        return makeAny(xExistent);
 
-               try
+        // see whether this is an registered name
+        ::rtl::OUString sURL;
+        if ( getURLForRegisteredObject( _rName, sURL ) )
                {
-                       xExistent = getRegisteredObject(_rName);
+            // is the object cached under its URL?
+               xExistent = getObject( sURL );
                }
-               catch(Exception)
-               {
-                       // will throw an NoSuchElementException if neccessary
+        else
+            // interpret the name as URL
+            sURL = _rName;
+
                        if ( !xExistent.is() )
-                       {
                                // try to load this as URL
-                               xExistent = loadObjectFromURL(_rName,_rName);
-                       }
-               }
-               return makeAny(xExistent);
+            xExistent = loadObjectFromURL( _rName, sURL );
+               return makeAny( xExistent );
        }
        catch (NoSuchElementException&)
        {       // let these exceptions through
@@ -628,7 +654,7 @@
        }
        catch (Exception& e)
        {       // exceptions other than the speciafied ones -> wrap
-               throw NoSuchElementException(_rName, *this);
+               throw WrappedTargetException(_rName, *this, makeAny( e ) );
        }
 }
 




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

Reply via email to