You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by pb...@apache.org on 2007/07/12 04:17:12 UTC

svn commit: r555462 - /struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java

Author: pbenedict
Date: Wed Jul 11 19:17:11 2007
New Revision: 555462

URL: http://svn.apache.org/viewvc?view=rev&rev=555462
Log:
STR-2499: Add findRequiredForward

Modified:
    struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java?view=diff&rev=555462&r1=555461&r2=555462
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionMapping.java Wed Jul 11 19:17:11 2007
@@ -65,6 +65,7 @@
      * @param forwardName Logical name of the forwarding instance to be
      *                    returned
      * @return The local or global forward with the specified name.
+     * @see #findRequiredForward(String)
      */
     public ActionForward findForward(String forwardName) {
         ForwardConfig config = findForwardConfig(forwardName);
@@ -73,6 +74,7 @@
             config = getModuleConfig().findForwardConfig(forwardName);
         }
 
+        // TODO: remove warning since findRequiredForward takes care of use case? 
         if (config == null) {
             if (log.isWarnEnabled()) {
                 log.warn("Unable to find '" + forwardName + "' forward.");
@@ -80,6 +82,27 @@
         }
 
         return ((ActionForward) config);
+    }
+    
+    /**
+     * <p>Find and return the <code>ForwardConfig</code> instance of this
+     * mapping, throwing an exception if not found locally or globally.</p>
+     * 
+     * @param forwardName Logical name of the forwarding instance to be
+     *                    returned
+     * @return The local or global forward with the specified name.
+     * @throws IllegalStateException if the forward is not found
+     * @see #findForward(String)
+     * @since Struts 1.4
+     */
+    public ActionForward findRequiredForward(String forwardName) {
+        ActionForward forward = findForward(forwardName);
+        if (forward == null) {
+            throw new IllegalStateException(
+                    "Unable to find '" + forwardName + 
+                    "' forward of action path '" + getPath() + "'"); 
+        }
+        return forward;
     }
 
     /**