Author: germuska
Date: Sat Aug  6 01:12:10 2005
New Revision: 230537

URL: http://svn.apache.org/viewcvs?rev=230537&view=rev
Log:
Support use of global exception handlers in cases when no ActionConfig has yet 
been identified, as in with "preprocessing" commands in a custom chain.  In the 
case when
there is no ActionConfig, the AbstractExceptionHandler will now call a new 
method in ModuleConfig which provides similar logic for finding a globally 
mapped exception handler
for the given exception class or any of its superclasses.


Modified:
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractExceptionHandler.java
    struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java
    struts/core/trunk/src/share/org/apache/struts/config/ModuleConfig.java
    
struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractExceptionHandler.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractExceptionHandler.java?rev=230537&r1=230536&r2=230537&view=diff
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractExceptionHandler.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractExceptionHandler.java
 Sat Aug  6 01:12:10 2005
@@ -78,6 +78,9 @@
             log.debug("See if actionConfig " + actionConfig + " has an 
exceptionConfig for " + exception.getClass().getName());
             exceptionConfig =
                 actionConfig.findException(exception.getClass());
+        } else if (moduleConfig != null) {
+            log.debug("No action yet, see if moduleConfig " + moduleConfig + " 
has an exceptionConfig " + exception.getClass().getName());
+            exceptionConfig = moduleConfig.findException(exception.getClass());
         }
 
         // Handle the exception in the configured manner

Modified: struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java?rev=230537&r1=230536&r2=230537&view=diff
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java 
(original)
+++ struts/core/trunk/src/share/org/apache/struts/config/ActionConfig.java Sat 
Aug  6 01:12:10 2005
@@ -20,6 +20,8 @@
 
 import org.apache.struts.util.RequestUtils;
 import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -38,6 +40,7 @@
  */
 public class ActionConfig extends BaseConfig {
 
+    private static final Log log = LogFactory.getLog(ActionConfig.class);
 
     // ----------------------------------------------------- Instance Variables
 
@@ -859,12 +862,14 @@
 
             // Check for a locally defined handler
             String name = type.getName();
+            log.debug("findException: look locally for " + name);
             config = findExceptionConfig(name);
             if (config != null) {
                 return (config);
             }
 
             // Check for a globally defined handler
+            log.debug("findException: look globally for " + name);
             config = getModuleConfig().findExceptionConfig(name);
             if (config != null) {
                 return (config);

Modified: struts/core/trunk/src/share/org/apache/struts/config/ModuleConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ModuleConfig.java?rev=230537&r1=230536&r2=230537&view=diff
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/config/ModuleConfig.java 
(original)
+++ struts/core/trunk/src/share/org/apache/struts/config/ModuleConfig.java Sat 
Aug  6 01:12:10 2005
@@ -192,6 +192,18 @@
     ExceptionConfig findExceptionConfig(String type);
 
     /**
+     * Perform a recursive search for an ExceptionConfig registered for this 
class, or for any
+     * superclass.  This should only be used in the case when an 
<code>ActionConfig</code> 
+     * is not available; otherwise, use 
<code>ActionConfig.findException(Class)</code>
+     * to preserve the search order.
+     *
+     * @param type Exception class name to find a configuration for
+     * @see ActionConfig.findException(Class)
+     */
+    ExceptionConfig findException(Class type);
+
+    
+    /**
      * Return the exception configurations for this module.  If there
      * are none, a zero-length array is returned.
      */

Modified: 
struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java?rev=230537&r1=230536&r2=230537&view=diff
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java 
(original)
+++ 
struts/core/trunk/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java 
Sat Aug  6 01:12:10 2005
@@ -347,6 +347,47 @@
 
     }
 
+    
+    /**
+     * <p>Find and return the <code>ExceptionConfig</code> instance defining
+     * how <code>Exceptions</code> of the specified type should be handled.
+     * 
+     * <p>In original Struts usage, this was only available in 
<code>ActionConfig</code>,
+     * but there are cases when an exception could be thrown before an 
<code>ActionConfig</code>
+     * has been identified, where global exception handlers may still be 
pertinent.</p>
+     * 
+     * <p>TODO: Look for a way to share this logic with 
<code>ActionConfig</code>, although
+     * there are subtle differences, and it certainly doesn't seem like it 
should be done with
+     * inheritance.</p>
+     *
+     * @param type Exception class for which to find a handler
+     * @since Struts 1.3.0
+     */
+    public ExceptionConfig findException(Class type) {
+
+        // Check through the entire superclass hierarchy as needed
+        ExceptionConfig config = null;
+        while (true) {
+
+            // Check for a locally defined handler
+            String name = type.getName();
+            log.debug("findException: look locally for " + name);
+            config = findExceptionConfig(name);
+            if (config != null) {
+                return (config);
+            }
+
+            // Loop again for our superclass (if any)
+            type = type.getSuperclass();
+            if (type == null) {
+                break;
+            }
+
+        }
+        return (null); // No handler has been configured
+
+    }
+
     /**
      * Return the exception configurations for this module.  If there
      * are none, a zero-length array is returned.



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

Reply via email to