You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ni...@apache.org on 2006/03/08 07:42:48 UTC

svn commit: r384133 - in /struts/extras/trunk/src/java/org/apache/struts/actions: EventActionDispatcher.java EventDispatchAction.java

Author: niallp
Date: Tue Mar  7 22:42:48 2006
New Revision: 384133

URL: http://svn.apache.org/viewcvs?rev=384133&view=rev
Log:
Implement unspecified method in EventDispatchAction and EventActionDispatcher and remove check/exception from getMethodName() method, which was preventing "unspecified" from ever being called - thanks to Paul Benedict for pointing this out.

Also, remove unecessary getParameter() method (duplicates inherited version) from EventDispatchAction and EventActionDispatcher.

Modified:
    struts/extras/trunk/src/java/org/apache/struts/actions/EventActionDispatcher.java
    struts/extras/trunk/src/java/org/apache/struts/actions/EventDispatchAction.java

Modified: struts/extras/trunk/src/java/org/apache/struts/actions/EventActionDispatcher.java
URL: http://svn.apache.org/viewcvs/struts/extras/trunk/src/java/org/apache/struts/actions/EventActionDispatcher.java?rev=384133&r1=384132&r2=384133&view=diff
==============================================================================
--- struts/extras/trunk/src/java/org/apache/struts/actions/EventActionDispatcher.java (original)
+++ struts/extras/trunk/src/java/org/apache/struts/actions/EventActionDispatcher.java Tue Mar  7 22:42:48 2006
@@ -19,6 +19,7 @@
 package org.apache.struts.actions;
 
 import java.util.StringTokenizer;
+import java.lang.reflect.Method;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -29,6 +30,7 @@
 import org.apache.struts.action.Action;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionForward;
 
 /**
  * <p>An Action helper class that dispatches to to one of the public methods
@@ -109,7 +111,47 @@
      * @param action the action
      */
     public EventActionDispatcher(Action action) {
-        super(action, -1);
+        // N.B. MAPPING_FLAVOR causes the getParameter() method
+        //      in ActionDispatcher to throw an exception if the
+        //      parameter is missing
+        super(action, ActionDispatcher.MAPPING_FLAVOR);
+    }
+
+    /**
+     * <p>Dispatches to the target class' <code>unspecified</code> method, if
+     * present, otherwise throws a ServletException. Classes utilizing
+     * <code>EventActionDispatcher</code> should provide an <code>unspecified</code>
+     * method if they wish to provide behavior different than throwing a
+     * ServletException.</p>
+     *
+     * @param mapping  The ActionMapping used to select this instance
+     * @param form     The optional ActionForm bean for this request (if any)
+     * @param request  The non-HTTP request we are processing
+     * @param response The non-HTTP response we are creating
+     * @return The forward to which control should be transferred, or
+     *         <code>null</code> if the response has been completed.
+     * @throws Exception if the application business logic throws an
+     *                   exception.
+     */
+    protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
+        HttpServletRequest request, HttpServletResponse response)
+        throws Exception {
+        // Identify if there is an "unspecified" method to be dispatched to
+        String name = "unspecified";
+        Method method = null;
+
+        try {
+            method = getMethod(name);
+        } catch (NoSuchMethodException e) {
+            String message =
+                messages.getMessage("event.parameter", mapping.getPath());
+
+            LOG.error(message + " " + mapping.getParameter());
+
+            throw new ServletException(message);
+        }
+
+        return dispatchMethod(mapping, form, request, response, name, method);
     }
 
     /**
@@ -156,42 +198,6 @@
             }
         }
 
-        if (defaultMethodName == null || defaultMethodName.length() == 0) {
-            String message =
-                messages.getMessage("event.parameter", mapping.getPath());
-            LOG.error(message + " " + parameter);
-            throw new ServletException(message);
-        }
-
         return defaultMethodName;
-    }
-
-    /**
-     * Returns the parameter.
-     *
-     * @param mapping  The ActionMapping used to select this instance
-     * @param form     The optional ActionForm bean for this request (if any)
-     * @param request  The HTTP request we are processing
-     * @param response The HTTP response we are creating
-     * @return The <code>ActionMapping</code> parameter's value
-     * @throws Exception if the parameter is missing.
-     */
-    protected String getParameter(ActionMapping mapping, ActionForm form,
-            HttpServletRequest request, HttpServletResponse response)
-            throws Exception {
-
-        String parameter = mapping.getParameter();
-        if ("".equals(parameter)) {
-            parameter = null;
-        }
-
-        if (parameter == null) {
-            String message =
-                messages.getMessage("dispatch.handler", mapping.getPath());
-            LOG.error(message);
-            throw new ServletException(message);
-        }
-
-        return parameter;
     }
 }

Modified: struts/extras/trunk/src/java/org/apache/struts/actions/EventDispatchAction.java
URL: http://svn.apache.org/viewcvs/struts/extras/trunk/src/java/org/apache/struts/actions/EventDispatchAction.java?rev=384133&r1=384132&r2=384133&view=diff
==============================================================================
--- struts/extras/trunk/src/java/org/apache/struts/actions/EventDispatchAction.java (original)
+++ struts/extras/trunk/src/java/org/apache/struts/actions/EventDispatchAction.java Tue Mar  7 22:42:48 2006
@@ -27,6 +27,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionForward;
 
 /**
  * <p>An <strong>Action</strong> that dispatches to to one of the public methods
@@ -86,6 +87,33 @@
     // --------------------------------------------------------- Protected Methods
 
     /**
+     * Method which is dispatched to when there is no value for specified
+     * request parameter included in the request.  Subclasses of
+     * <code>DispatchAction</code> should override this method if they wish to
+     * provide default behavior different than throwing a ServletException.
+     *
+     * @param mapping  The ActionMapping used to select this instance
+     * @param form     The optional ActionForm bean for this request (if any)
+     * @param request  The non-HTTP request we are processing
+     * @param response The non-HTTP response we are creating
+     * @return The forward to which control should be transferred, or
+     *         <code>null</code> if the response has been completed.
+     * @throws Exception if the application business logic throws an
+     *                   exception.
+     */
+    protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
+        HttpServletRequest request, HttpServletResponse response)
+        throws Exception {
+        String message =
+            messages.getMessage("event.parameter", mapping.getPath(),
+                mapping.getParameter());
+
+        LOG.error(message + " " + mapping.getParameter());
+
+        throw new ServletException(message);
+    }
+
+    /**
      * Returns the method name, given a parameter's value.
      *
      * @param mapping   The ActionMapping used to select this instance
@@ -129,42 +157,6 @@
             }
         }
 
-        if (defaultMethodName == null || defaultMethodName.length() == 0) {
-            String message =
-                messages.getMessage("event.parameter", mapping.getPath());
-            LOG.error(message + " " + parameter);
-            throw new ServletException(message);
-        }
-
         return defaultMethodName;
-    }
-
-    /**
-     * Returns the parameter.
-     *
-     * @param mapping  The ActionMapping used to select this instance
-     * @param form     The optional ActionForm bean for this request (if any)
-     * @param request  The HTTP request we are processing
-     * @param response The HTTP response we are creating
-     * @return The <code>ActionMapping</code> parameter's value
-     * @throws Exception if the parameter is missing.
-     */
-    protected String getParameter(ActionMapping mapping, ActionForm form,
-            HttpServletRequest request, HttpServletResponse response)
-            throws Exception {
-
-        String parameter = mapping.getParameter();
-        if ("".equals(parameter)) {
-            parameter = null;
-        }
-
-        if (parameter == null) {
-            String message =
-                messages.getMessage("dispatch.handler", mapping.getPath());
-            LOG.error(message);
-            throw new ServletException(message);
-        }
-
-        return parameter;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org