Title: [waffle-scm] [841] trunk/waffle-core/src/main/resources: WAFFLE-96: Added I18N support to Waffle servlet and method definition finders.
Revision
841
Author
mauro
Date
2008-09-15 12:43:18 -0500 (Mon, 15 Sep 2008)

Log Message

WAFFLE-96:  Added I18N support to Waffle servlet and method definition finders.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -3,23 +3,12 @@
  */
 package org.codehaus.waffle.action;
 
-import org.codehaus.waffle.WaffleException;
-import org.codehaus.waffle.action.annotation.ActionMethod;
-import org.codehaus.waffle.bind.StringTransmuter;
-import org.codehaus.waffle.context.ContextContainer;
-import org.codehaus.waffle.context.RequestLevelContainer;
-import org.codehaus.waffle.i18n.MessagesContext;
-import org.codehaus.waffle.monitor.ActionMonitor;
+import static java.text.MessageFormat.format;
 
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import static java.text.MessageFormat.format;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -27,6 +16,20 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.codehaus.waffle.WaffleException;
+import org.codehaus.waffle.action.annotation.ActionMethod;
+import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.context.ContextContainer;
+import org.codehaus.waffle.context.RequestLevelContainer;
+import org.codehaus.waffle.i18n.MessageResources;
+import org.codehaus.waffle.i18n.MessagesContext;
+import org.codehaus.waffle.monitor.ActionMonitor;
+
 /**
  * Abstract base implementation for all method definition finders
  * 
@@ -46,17 +49,17 @@
     private final StringTransmuter stringTransmuter;
     private final MethodNameResolver methodNameResolver;
     private final ActionMonitor actionMonitor;
+    protected final MessageResources messageResources;
 
-    public AbstractMethodDefinitionFinder(ServletContext servletContext,
-                                          ArgumentResolver argumentResolver,
-                                          MethodNameResolver methodNameResolver,
-                                          StringTransmuter stringTransmuter,
-                                          ActionMonitor actionMonitor) {
+    public AbstractMethodDefinitionFinder(ServletContext servletContext, ArgumentResolver argumentResolver,
+            MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter, ActionMonitor actionMonitor,
+            MessageResources messageResources) {
         this.servletContext = servletContext;
         this.argumentResolver = argumentResolver;
         this.stringTransmuter = stringTransmuter;
         this.methodNameResolver = methodNameResolver;
         this.actionMonitor = actionMonitor;
+        this.messageResources = messageResources;
     }
 
     public MethodDefinition find(Object controller, HttpServletRequest request, HttpServletResponse response)
@@ -123,10 +126,13 @@
         List<MethodDefinition> methodDefinitions = findMethodDefinitions(request, response, methods);
 
         if (methodDefinitions.size() > 1) {
-            throw new AmbiguousActionSignatureMethodException("Method: '" + methodName + "' for controller: '"
-                    + controller.getClass() + "'");
+            String message = messageResources.getMessageWithDefault("ambiguousActionMethodSignature",
+                    "ActionMethod ''{0}'' has ambiguous signature among methods ''{1}''", methodName, methods);
+            throw new AmbiguousActionMethodSignatureException(message);
         } else if (methodDefinitions.isEmpty()) {
-            throw new NoMatchingActionMethodException("No matching methods for "+methodName, controller.getClass());
+            String message = messageResources.getMessageWithDefault("noMatchingMethodFound",
+                    "No matching methods for name ''{0}''", methodName);
+            throw new NoMatchingActionMethodException(message, controller.getClass());
         }
 
         MethodDefinition methodDefinition = methodDefinitions.get(0);
@@ -155,8 +161,9 @@
     private MethodDefinition buildDefaultMethodDefinition(Method method, HttpServletRequest request) {
         MethodDefinition methodDefinition = new MethodDefinition(method);
         if (!isDefaultActionMethod(method)) {
-            throw new NoDefaultActionMethodException("Method " + method
-                    + " is not annotated with @ActionMethod(asDefault=true).");
+            String message = messageResources.getMessageWithDefault("noDefaultActionMethod", 
+                    "Method ''{0}'' is not annotated with @ActionMethod(asDefault=true)", method);
+            throw new NoDefaultActionMethodException(message);
         }
         ActionMethod defaultActionMethod = method.getAnnotation(ActionMethod.class);
         List<String> arguments = new ArrayList<String>(defaultActionMethod.parameters().length);
@@ -189,19 +196,20 @@
 
         if (methodDefinitions.size() > 1) {
             String methodName = methodDefinitions.get(0).getMethod().getName();
-            throw new AmbiguousActionSignatureMethodException("Method: " + methodName);
+            String message = messageResources.getMessageWithDefault("ambiguousActionMethodSignature",
+                    "ActionMethod ''{0}'' has ambiguous signature among methods ''{1}''", methodName, methods);
+            throw new AmbiguousActionMethodSignatureException(message);
         } else if (methodDefinitions.isEmpty()) {
-            // TODO - avoid null
-            throw new NoMatchingActionMethodException("No matching methods for "+methods.get(0).getName(), null);
+            String message = messageResources.getMessageWithDefault("noMatchingMethodFound",
+                    "No matching methods for name ''{0}''", methods.get(0).getName());
+            throw new NoMatchingActionMethodException(message, null);
         }
 
         return methodDefinitions.get(0); // TODO ... should we cache the method?
     }
 
-    private MethodDefinition buildMethodDefinition(HttpServletRequest request,
-                                                   HttpServletResponse response,
-                                                   Method method,
-                                                   List<Object> arguments) {
+    private MethodDefinition buildMethodDefinition(HttpServletRequest request, HttpServletResponse response,
+            Method method, List<Object> arguments) {
         Class<?>[] actualParameterTypes = method.getParameterTypes();
         MethodDefinition methodDefinition = new MethodDefinition(method);
 

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractOgnlMethodDefinitionFinder.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractOgnlMethodDefinitionFinder.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractOgnlMethodDefinitionFinder.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -4,13 +4,16 @@
 package org.codehaus.waffle.action;
 
 import static ognl.OgnlRuntime.getMethods;
-import org.codehaus.waffle.bind.StringTransmuter;
-import org.codehaus.waffle.monitor.ActionMonitor;
 
-import javax.servlet.ServletContext;
 import java.lang.reflect.Method;
 import java.util.List;
 
+import javax.servlet.ServletContext;
+
+import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.i18n.MessageResources;
+import org.codehaus.waffle.monitor.ActionMonitor;
+
 /**
  * Abstract method definition finder that uses Ognl to find methods
  * 
@@ -18,29 +21,28 @@
  */
 public abstract class AbstractOgnlMethodDefinitionFinder extends AbstractMethodDefinitionFinder {
 
-    public AbstractOgnlMethodDefinitionFinder(ServletContext servletContext,
-                                           ArgumentResolver argumentResolver,
-                                           MethodNameResolver methodNameResolver,
-                                           StringTransmuter stringTransmuter,
-                                           ActionMonitor actionMonitor) {
-        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor);
+    public AbstractOgnlMethodDefinitionFinder(ServletContext servletContext, ArgumentResolver argumentResolver,
+            MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter, ActionMonitor actionMonitor, MessageResources messageResources) {
+        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor,
+                messageResources);
     }
 
     /**
-     * Inspects the class (aka Type) and finds all methods with that name.  
-     *
-     * @param type       the Class in which to look for the method
+     * Inspects the class (aka Type) and finds all methods with that name.
+     * 
+     * @param type the Class in which to look for the method
      * @param methodName the method name
      * @return A List of methods
      * @throws NoMatchingActionMethodException if no methods match
      */
-    @SuppressWarnings({"unchecked"})
+    @SuppressWarnings( { "unchecked" })
     protected List<Method> findMethods(Class<?> type, String methodName) {
         List<Method> methods = getMethods(type, methodName, false);
         if (methods == null) {
-            throw new NoMatchingActionMethodException("No matching methods for "+methodName, type);
+            String message = messageResources.getMessageWithDefault("noMatchingMethodFound", "No matching methods for name ''{0}''", methodName);
+            throw new NoMatchingActionMethodException(message, type);
         }
         return methods;
     }
-    
+
 }

Copied: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionMethodSignatureException.java (from rev 840, trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionSignatureMethodException.java) (0 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionMethodSignatureException.java	                        (rev 0)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionMethodSignatureException.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
+ */
+package org.codehaus.waffle.action;
+
+
+/**
+ * Thrown when unable to determine which method to invoke.
+ *
+ * @author Michael Ward
+ */
[EMAIL PROTECTED]("serial")
+public class AmbiguousActionMethodSignatureException extends MatchingActionMethodException {
+
+    public AmbiguousActionMethodSignatureException(String message) {
+        super(message);
+    }
+
+}

Property changes: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionMethodSignatureException.java

Name: svn:mergeinfo
   + 

Deleted: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionSignatureMethodException.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionSignatureMethodException.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AmbiguousActionSignatureMethodException.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
- */
-package org.codehaus.waffle.action;
-
-
-/**
- * Thrown when unable to determine which method to invoke.
- *
- * @author Michael Ward
- */
[EMAIL PROTECTED]("serial")
-public class AmbiguousActionSignatureMethodException extends MatchingActionMethodException {
-
-    public AmbiguousActionSignatureMethodException(String message) {
-        super(message);
-    }
-
-}

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinder.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinder.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinder.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -3,20 +3,24 @@
  */
 package org.codehaus.waffle.action;
 
-import org.codehaus.waffle.action.annotation.ActionMethod;
-import org.codehaus.waffle.bind.StringTransmuter;
-import org.codehaus.waffle.monitor.ActionMonitor;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.codehaus.waffle.action.annotation.ActionMethod;
+import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.i18n.MessageResources;
+import org.codehaus.waffle.monitor.ActionMonitor;
+
 /**
- * <p>Annotation-based method definition finder. This is the default default definition finder used by Waffle.
- * <br/><br/>
+ * <p>
+ * Annotation-based method definition finder. This is the default default definition finder used by Waffle.
+ * </p>
+ * <p>
  * <b>Note</b>: Pragmatic method calls always take precedence over other types.
  * </p>
  * 
@@ -24,18 +28,16 @@
  */
 public class AnnotatedMethodDefinitionFinder extends AbstractOgnlMethodDefinitionFinder {
 
-    public AnnotatedMethodDefinitionFinder(ServletContext servletContext,
-                                           ArgumentResolver argumentResolver,
-                                           MethodNameResolver methodNameResolver,
-                                           StringTransmuter stringTransmuter,
-                                           ActionMonitor actionMonitor) {
-        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor);
+    public AnnotatedMethodDefinitionFinder(ServletContext servletContext, ArgumentResolver argumentResolver,
+            MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter, ActionMonitor actionMonitor,
+            MessageResources messageResources) {
+        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor, messageResources);
     }
 
     /**
      * Inspects the method's [EMAIL PROTECTED] ActionMethod} annotation to determine the parameter names to use to resolve the
      * argument values.
-     *
+     * 
      * @param method the action method to be invoked
      * @param request the HttpServetRequest
      * @return the resolved list of arguments needed to satisfy the action method invocation
@@ -46,7 +48,7 @@
             List<String> arguments = new ArrayList<String>(actionMethod.parameters().length);
 
             for (String value : actionMethod.parameters()) {
-                arguments.add(formatArgument(value)); 
+                arguments.add(formatArgument(value));
             }
 
             return resolveArguments(request, arguments.iterator());

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinder.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinder.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinder.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) terms as published in http://waffle.codehaus.org/license.html 
+ * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
  */
 package org.codehaus.waffle.action;
 
@@ -13,6 +13,7 @@
 import javax.servlet.http.HttpSession;
 
 import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.i18n.MessageResources;
 import org.codehaus.waffle.monitor.ActionMonitor;
 
 import com.thoughtworks.paranamer.CachingParanamer;
@@ -24,7 +25,9 @@
  * Pananamer-based method definition finder, which can be used in alternative to other definition finders, eg
  * [EMAIL PROTECTED] AnnotatedMethodDefinitionFinder}.
  * </p>
- * <br/><br/> <b>Note</b>: Pragmatic method calls will always take precedence.
+ * <p>
+ * <b>Note</b>: Pragmatic method calls will always take precedence.
+ * </p>
  * 
  * @author Paul Hammant
  * @see AnnotatedMethodDefinitionFinder
@@ -33,8 +36,9 @@
     private final CachingParanamer paranamer = new CachingParanamer();
 
     public ParanamerMethodDefinitionFinder(ServletContext servletContext, ArgumentResolver argumentResolver,
-            MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter, ActionMonitor actionMonitor) {
-        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor);
+            MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter, ActionMonitor actionMonitor,
+            MessageResources messageResources) {
+        super(servletContext, argumentResolver, methodNameResolver, stringTransmuter, actionMonitor, messageResources);
     }
 
     /**
@@ -96,14 +100,14 @@
                 parameterNames = paranamer.lookupParameterNames(method);
             }
             if (rc == Paranamer.NO_PARAMETER_NAMES_LIST) {
-                throw new MatchingActionMethodException("No parameter names list found by paranamer " + paranamer);
+                String message = messageResources.getMessageWithDefault("noParameterNamesListFound", "No parameter names list found by paranamer ''{0}''", paranamer);
+                throw new MatchingActionMethodException(message);
             } else if (rc == Paranamer.NO_PARAMETER_NAMES_FOR_CLASS) {
-                throw new MatchingActionMethodException("No parameter names found for class '"
-                        + declaringClass.getName() + "' by paranamer " + paranamer);
+                String message = messageResources.getMessageWithDefault("noParameterNamesFoundForClass", "No parameter names found for class ''{0}'' by paranamer ''{1}''", declaringClass.getName(), paranamer);
+                throw new MatchingActionMethodException(message);
             } else if (rc == Paranamer.NO_PARAMETER_NAMES_FOR_CLASS_AND_MEMBER) {
-                throw new MatchingActionMethodException("No parameter names found for class '"
-                        + declaringClass.getName() + "' and method '" + method.getName() + "' by paranamer "
-                        + paranamer);
+                String message = messageResources.getMessageWithDefault("noParameterNamesFoundForClassAndMethod", "No parameter names found for class ''{0}'' and method ''{1}'' by paranamer ''{2}''", declaringClass.getName(), method.getName(), paranamer);
+                throw new MatchingActionMethodException(message);
                 // } else if (rc == Paranamer.PARAMETER_NAMES_FOUND ){
                 // throw new MatchingActionMethodException("Invalid parameter names list for paranamer "+paranamer);
             }

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/RequestParameterMethodNameResolver.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/RequestParameterMethodNameResolver.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/RequestParameterMethodNameResolver.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -10,8 +10,10 @@
 /**
  * <p>Implementation of method name resolver which returns the value of a configurable action parameter key,
  * which defaults to 'method'.
- * </p><br/>
+ * </p>
+ * <p>
  * The resolved name is monitored along with the available parameter key set.
+ * </p>
  * 
  * @author Michael Ward
  * @author Mauro Talevi

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java (840 => 841)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -3,10 +3,24 @@
  */
 package org.codehaus.waffle.servlet;
 
-import org.codehaus.waffle.ComponentRegistry;
+import static java.util.Arrays.asList;
 import static org.codehaus.waffle.Constants.ERRORS_VIEW_KEY;
 import static org.codehaus.waffle.Constants.VIEW_PREFIX_KEY;
 import static org.codehaus.waffle.Constants.VIEW_SUFFIX_KEY;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.codehaus.waffle.ComponentRegistry;
 import org.codehaus.waffle.WaffleException;
 import org.codehaus.waffle.action.ActionMethodExecutor;
 import org.codehaus.waffle.action.ActionMethodInvocationException;
@@ -20,6 +34,7 @@
 import org.codehaus.waffle.context.RequestLevelContainer;
 import org.codehaus.waffle.controller.ControllerDefinition;
 import org.codehaus.waffle.controller.ControllerDefinitionFactory;
+import org.codehaus.waffle.i18n.MessageResources;
 import org.codehaus.waffle.monitor.ServletMonitor;
 import org.codehaus.waffle.validation.ErrorsContext;
 import org.codehaus.waffle.validation.GlobalErrorMessage;
@@ -27,21 +42,9 @@
 import org.codehaus.waffle.view.RedirectView;
 import org.codehaus.waffle.view.View;
 
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import static java.util.Arrays.asList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Waffle's FrontController for handling user requests.
- *
+ * 
  * @author Michael Ward
  * @author Mauro Talevi
  */
@@ -60,6 +63,7 @@
     private ActionMethodResponseHandler actionMethodResponseHandler;
     private ControllerDefinitionFactory controllerDefinitionFactory;
     private ControllerDataBinder controllerDataBinder;
+    private MessageResources messageResources;
     private ViewDataBinder viewDataBinder;
     private Validator validator;
     private ServletMonitor servletMonitor;
@@ -74,28 +78,27 @@
 
     /**
      * Constructor required by builder and useful for testing
-     *
+     * 
      * @param actionMethodExecutor
      * @param actionMethodResponseHandler
      * @param servletMonitor
      * @param controllerDataBinder
+     * @param controllerDefinitionFactory
+     * @param messageResources
      * @param viewDataBinder
-     * @param controllerDefinitionFactory
      * @param validator
      */
     public WaffleServlet(ActionMethodExecutor actionMethodExecutor,
-                         ActionMethodResponseHandler actionMethodResponseHandler,
-                         ServletMonitor servletMonitor,
-                         ControllerDataBinder controllerDataBinder,
-                         ViewDataBinder viewDataBinder,
-                         ControllerDefinitionFactory controllerDefinitionFactory,
-                         Validator validator) {
+            ActionMethodResponseHandler actionMethodResponseHandler, ServletMonitor servletMonitor,
+            ControllerDataBinder controllerDataBinder, ControllerDefinitionFactory controllerDefinitionFactory,
+            MessageResources messageResources, ViewDataBinder viewDataBinder, Validator validator) {
         this.actionMethodExecutor = actionMethodExecutor;
         this.actionMethodResponseHandler = actionMethodResponseHandler;
         this.servletMonitor = servletMonitor;
         this.controllerDataBinder = controllerDataBinder;
+        this.controllerDefinitionFactory = controllerDefinitionFactory;
+        this.messageResources = messageResources;
         this.viewDataBinder = viewDataBinder;
-        this.controllerDefinitionFactory = controllerDefinitionFactory;
         this.validator = validator;
         componentsRetrieved = true;
     }
@@ -112,6 +115,7 @@
             actionMethodResponseHandler = registry.getActionMethodResponseHandler();
             controllerDefinitionFactory = registry.getControllerDefinitionFactory();
             controllerDataBinder = registry.getControllerDataBinder();
+            messageResources = registry.getMessageResources();
             viewDataBinder = registry.getViewDataBinder();
             validator = registry.getValidator();
             servletMonitor = registry.getServletMonitor();
@@ -133,14 +137,14 @@
 
     /**
      * Responsible for servicing the requests from the users.
-     *
-     * @param request  the HttpServletResponse
+     * 
+     * @param request the HttpServletResponse
      * @param response the HttpServletResponse
      * @throws ServletException
      * @throws IOException
      */
-    protected void service(HttpServletRequest request,
-                           HttpServletResponse response) throws ServletException, IOException {
+    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+            IOException {
         servletMonitor.servletServiceRequested(parametersOf(request));
         ContextContainer requestContainer = RequestLevelContainer.get();
         ErrorsContext errorsContext = requestContainer.getComponent(ErrorsContext.class);
@@ -149,7 +153,7 @@
         View view = null;
         try {
             ControllerDefinition controllerDefinition = controllerDefinitionFactory.getControllerDefinition(request,
-            response);
+                    response);
             controllerDataBinder.bind(request, response, errorsContext, controllerDefinition.getController());
             validator.validate(controllerDefinition, errorsContext);
             try {
@@ -163,7 +167,7 @@
                         view = buildView(controllerDefinition);
                     } else if (actionMethodResponse.getReturnValue() == null) {
                         // Null or VOID indicate a Waffle convention (return to referring page)
-                        // unless PRG is disabled 
+                        // unless PRG is disabled
                         if (request.getMethod().equalsIgnoreCase(POST)) {
                             if (usePRG(controllerDefinition.getMethodDefinition())) {
                                 // PRG (Post/Redirect/Get): see http://en.wikipedia.org/wiki/Post/Redirect/Get
@@ -180,17 +184,18 @@
 
             } catch (ActionMethodInvocationException e) {
                 servletMonitor.actionMethodInvocationFailed(e);
-                errorsContext.addErrorMessage(new GlobalErrorMessage("Action method invocation failed for controller "
-                        + controllerDefinition, e));
+                String message = messageResources.getMessageWithDefault("actionMethodInvocationFailed",
+                        "Action method invocation failed for controller ''{0}''", controllerDefinition);
+                errorsContext.addErrorMessage(new GlobalErrorMessage(message, e));
                 view = buildActionMethodFailureView(controllerDefinition);
             }
             viewDataBinder.bind(request, controllerDefinition.getController());
-        } catch (WaffleException e) {      
+        } catch (WaffleException e) {
             servletMonitor.servletServiceFailed(e);
             errorsContext.addErrorMessage(new GlobalErrorMessage(e.getMessage(), e));
             view = buildErrorsView();
         }
-        
+
         if (view != null) {
             actionMethodResponse.setReturnValue(view);
         }
@@ -204,7 +209,7 @@
     @SuppressWarnings("unchecked")
     private Map<String, List<String>> parametersOf(HttpServletRequest request) {
         Map<String, List<String>> parameters = new HashMap<String, List<String>>();
-        for ( Enumeration<String> e = request.getParameterNames(); e.hasMoreElements(); ){
+        for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
             String name = e.nextElement();
             parameters.put(name, asList(request.getParameterValues(name)));
         }
@@ -221,7 +226,7 @@
         Method method = methodDefinition.getMethod();
         // look for PRG annotation
         PRG prg = method.getAnnotation(PRG.class);
-        if ( prg != null ){
+        if (prg != null) {
             return prg.value();
         }
         // else default to true
@@ -238,7 +243,7 @@
         String path = viewPrefix + controllerDefinition.getName() + viewSuffix;
         return new View(path, controllerDefinition.getController());
     }
-    
+
     /**
      * Build redirecting view, used by PRG paradigm.
      * 
@@ -252,8 +257,8 @@
     }
 
     /**
-     * Builds the view for action method failures, by default the referring view. 
-     * The user can extend and override behaviour, eg to throw a ServletException.
+     * Builds the view for action method failures, by default the referring view. The user can extend and override
+     * behaviour, eg to throw a ServletException.
      * 
      * @param controllerDefinition the ControllerDefinition
      * @return The referring View
@@ -264,8 +269,8 @@
     }
 
     /**
-     * Builds the errors view, for cases in which the context container or the controller are not found.
-     * The user can extend and override behaviour, eg to throw a ServletException.
+     * Builds the errors view, for cases in which the context container or the controller are not found. The user can
+     * extend and override behaviour, eg to throw a ServletException.
      * 
      * @return The referring View
      * @throws ServletException if required
@@ -292,6 +297,8 @@
         sb.append(controllerDefinitionFactory);
         sb.append(", controllerDataBinder=");
         sb.append(controllerDataBinder);
+        sb.append(", messageResources=");
+        sb.append(messageResources);
         sb.append(", viewDataBinder=");
         sb.append(viewDataBinder);
         sb.append(", validator=");

Added: trunk/waffle-core/src/main/resources/waffle-bundle.properties (0 => 841)

--- trunk/waffle-core/src/main/resources/waffle-bundle.properties	                        (rev 0)
+++ trunk/waffle-core/src/main/resources/waffle-bundle.properties	2008-09-15 17:43:18 UTC (rev 841)
@@ -0,0 +1,8 @@
+actionMethodInvocationFailed=Action method invocation failed for controller ''{0}''
+ambiguousActionMethodSignature=Action method ''{0}'' has ambiguous signature among methods ''{1}''
+noDefaultActionMethod=Method ''{0}'' is not annotated with @ActionMethod(asDefault=true)
+noMatchingMethodFound=No matching methods for name ''{0}''
+noParameterNamesListFound=No parameter names list found by paranamer ''{0}''"
+noParameterNamesFoundForClass=No parameter names found for class ''{0}'' by paranamer ''{1}''
+noParameterNamesFoundForClassAndMethod=No parameter names found for class ''{0}'' and method ''{1}'' by paranamer ''{2}''
+

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java (840 => 841)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -289,7 +289,7 @@
         assertEquals(expectedMethod, methodDefinition.getMethod());
     }
 
-    @Test(expected = AmbiguousActionSignatureMethodException.class)
+    @Test(expected = AmbiguousActionMethodSignatureException.class)
     public void cannotAllowAmbiguity() throws Exception {
         // Mock HttpServletRequest
         final HttpServletRequest request = mockery.mock(HttpServletRequest.class);

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java (840 => 841)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -11,6 +11,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.i18n.DefaultMessageResources;
 import org.codehaus.waffle.monitor.SilentMonitor;
 import org.codehaus.waffle.testmodel.FakeControllerWithListMethods;
 import org.codehaus.waffle.testmodel.FakeControllerWithMethodDefinitions;
@@ -33,7 +34,7 @@
             final ArgumentResolver argumentResolver, final MethodNameResolver methodNameResolver,
             final StringTransmuter stringTransmuter) {
         return new AnnotatedMethodDefinitionFinder(servletContext, argumentResolver, methodNameResolver,
-                stringTransmuter, new SilentMonitor());
+                stringTransmuter, new SilentMonitor(), new DefaultMessageResources());
     }
 
     @Test

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java (840 => 841)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -11,6 +11,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.codehaus.waffle.bind.StringTransmuter;
+import org.codehaus.waffle.i18n.DefaultMessageResources;
 import org.codehaus.waffle.monitor.SilentMonitor;
 import org.codehaus.waffle.testmodel.FakeControllerWithMethodDefinitions;
 import org.jmock.Expectations;
@@ -32,7 +33,7 @@
     protected MethodDefinitionFinder newMethodDefinitionFinder(ServletContext servletContext,
             ArgumentResolver argumentResolver, MethodNameResolver methodNameResolver, StringTransmuter stringTransmuter) {
         return new ParanamerMethodDefinitionFinder(servletContext, argumentResolver, methodNameResolver,
-                stringTransmuter, new SilentMonitor());
+                stringTransmuter, new SilentMonitor(), new DefaultMessageResources());
     }
 
     @Test

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java (840 => 841)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -48,7 +48,6 @@
         assertEquals(5, sb.toString().split("\n").length);
     }
 
-    @SuppressWarnings({"ThrowableInstanceNeverThrown"})
     @Test
     public void canTraceExceptions() {
         final StringWriter monitorWriter = new StringWriter();

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java (840 => 841)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java	2008-09-15 16:47:35 UTC (rev 840)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java	2008-09-15 17:43:18 UTC (rev 841)
@@ -39,6 +39,7 @@
 import org.codehaus.waffle.controller.ControllerDefinition;
 import org.codehaus.waffle.controller.ControllerDefinitionFactory;
 import org.codehaus.waffle.controller.ControllerNotFoundException;
+import org.codehaus.waffle.i18n.DefaultMessageResources;
 import org.codehaus.waffle.i18n.DefaultMessagesContext;
 import org.codehaus.waffle.i18n.MessagesContext;
 import org.codehaus.waffle.monitor.ServletMonitor;
@@ -83,8 +84,9 @@
             one(componentRegistry).getActionMethodResponseHandler();
             one(componentRegistry).getServletMonitor();
             one(componentRegistry).getControllerDataBinder();
+            one(componentRegistry).getControllerDefinitionFactory();
+            one(componentRegistry).getMessageResources();
             one(componentRegistry).getViewDataBinder();
-            one(componentRegistry).getControllerDefinitionFactory();
             one(componentRegistry).getValidator();
         }});
 
@@ -183,8 +185,8 @@
                                                         actionMethodResponseHandler,
                                                         monitor,
                                                         new OgnlControllerDataBinder(new OgnlValueConverterFinder(), null, monitor),
-                                                        viewDataBinder,
-                                                        controllerDefinitionFactory, validator) {
+                                                        controllerDefinitionFactory,
+                                                        new DefaultMessageResources(), viewDataBinder, validator) {
             @Override
             public ServletConfig getServletConfig() {
                 return servletConfig;
@@ -269,8 +271,8 @@
                                                         actionMethodResponseHandler,
                                                         monitor,
                                                         new OgnlControllerDataBinder(new OgnlValueConverterFinder(), null, monitor),
-                                                        viewDataBinder,
-                                                        controllerDefinitionFactory, validator) {
+                                                        controllerDefinitionFactory,
+                                                        new DefaultMessageResources(), viewDataBinder, validator) {
             @Override
             public ServletConfig getServletConfig() {
                 return servletConfig;
@@ -332,8 +334,8 @@
                 actionMethodResponseHandler,
                 new SilentMonitor(),
                 new OgnlControllerDataBinder(new OgnlValueConverterFinder(), null, new SilentMonitor()),
-                null,
-                controllerDefinitionFactory, null) {
+                controllerDefinitionFactory,
+                new DefaultMessageResources(), null, null) {
             @Override
             public ServletConfig getServletConfig() {
                 return servletConfig;
@@ -426,8 +428,8 @@
                 actionMethodResponseHandler,
                 new SilentMonitor(),
                 new OgnlControllerDataBinder(new OgnlValueConverterFinder(), null, new SilentMonitor()),
-                viewDataBinder,
-                controllerDefinitionFactory, validator) {
+                controllerDefinitionFactory,
+                new DefaultMessageResources(), viewDataBinder, validator) {
             @Override
             public ServletConfig getServletConfig() {
                 return servletConfig;
@@ -510,8 +512,8 @@
                 actionMethodResponseHandler,
                 new SilentMonitor(),
                 new OgnlControllerDataBinder(new OgnlValueConverterFinder(), null, new SilentMonitor()),
-                viewDataBinder,
-                controllerDefinitionFactory, validator) {
+                controllerDefinitionFactory,
+                new DefaultMessageResources(), viewDataBinder, validator) {
             @Override
             public ServletConfig getServletConfig() {
                 return servletConfig;


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to