Title: [waffle-scm] [94] trunk/core/src/main/java/org/codehaus/waffle/action: Refactored AbstractMethodDefinitionFinder to throw exceptions rather than return nulls.

Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java (93 => 94)

--- trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java	2007-05-27 21:16:30 UTC (rev 93)
+++ trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java	2007-05-27 21:46:13 UTC (rev 94)
@@ -112,11 +112,11 @@
         for (Method method : methods) {
             if (Modifier.isPublic(method.getModifiers())) {
                 List<Object> arguments = getArguments(method, request);
-                MethodDefinition methodDefinition = validateMethod(request, response, method, arguments);
-    
-                if (methodDefinition != null) {
-                    methodDefinitions.add(methodDefinition);
-                }
+                try {
+                    methodDefinitions.add(validateMethod(request, response, method, arguments));
+                } catch ( InvalidMethodException e) {
+                    // continue
+                }                 
             }
         }
     
@@ -136,7 +136,7 @@
         return resolvedArguments;
     }
 
-    protected MethodDefinition validateMethod(HttpServletRequest request,
+    private MethodDefinition validateMethod(HttpServletRequest request,
                                               HttpServletResponse response,
                                               Method method,
                                               List<Object> arguments) {
@@ -159,7 +159,7 @@
                     methodDefinition.addMethodArgument(iterator.next());
                 } else {
                     // not valid
-                    return null;
+                    throw new InvalidMethodException(method.getName());
                 }
             }
 
@@ -168,7 +168,7 @@
             }
         }
 
-        return null;
+        throw new InvalidMethodException(method.getName());
     }
 
     /**
@@ -251,11 +251,11 @@
 
         for (Method method : methods) {
             if (Modifier.isPublic(method.getModifiers())) {
-                MethodDefinition methodDefinition = validateMethod(request, response, method, arguments);
-
-                if (methodDefinition != null) {
-                    validMethods.add(methodDefinition);
-                }
+                try {
+                    validMethods.add(validateMethod(request, response, method, arguments));
+                } catch ( InvalidMethodException e) {
+                    // continue
+                }                 
             }
         }
 
@@ -283,7 +283,7 @@
             }
         }
 
-        return null;
+        throw new NoDefaultMethodException(clazz.getName());
     }
 
     private MethodDefinition buildMethodDefinitionForDefaultActionMethod(Method method, HttpServletRequest request) {

Added: trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java (0 => 94)

--- trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java	                        (rev 0)
+++ trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java	2007-05-27 21:46:13 UTC (rev 94)
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (C) 2005,2006 Michael Ward                                      *
+ * All rights reserved.                                                      *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by: Michael Ward                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.action;
+
+
+/**
+ * Thrown when method is invalid
+ *
+ * @author Mauro Talevi
+ */
+public class InvalidMethodException extends MatchingMethodException {
+
+    public InvalidMethodException(String message) {
+        super(message);
+    }
+
+}

Added: trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java (0 => 94)

--- trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java	                        (rev 0)
+++ trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java	2007-05-27 21:46:13 UTC (rev 94)
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (C) 2005,2006 Michael Ward                                      *
+ * All rights reserved.                                                      *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by: Michael Ward                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.action;
+
+
+/**
+ * Thrown when no default action method is found
+ *
+ * @author Mauro Talevi
+ */
+public class NoDefaultMethodException extends MatchingMethodException {
+
+    public NoDefaultMethodException(String message) {
+        super(message);
+    }
+
+}

Modified: trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java (93 => 94)

--- trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java	2007-05-27 21:16:30 UTC (rev 93)
+++ trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java	2007-05-27 21:46:13 UTC (rev 94)
@@ -232,7 +232,7 @@
             waffleServlet.service(request, null);
             fail("ServletException expected when an invalid controller is requested");
         } catch (ServletException expected) {
-            assertTrue(expected.getMessage().startsWith("Unable to locate the Waffle-Controller"));
+            assertTrue(expected.getMessage().startsWith("Unable to locate the Waffle Controller"));
         }
     }
 


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to