Title: [waffle-scm] [602] trunk/waffle-core/src/test/java/org/codehaus/waffle/bind: WAFFLE-66: Enhanced BindMonitor.

Diff

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinder.java (601 => 602)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinder.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinder.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -44,17 +44,20 @@
                 Method readMethod = propertyDescriptor.getReadMethod();
 
                 if(readMethod != null && readMethod.getParameterTypes().length == 0 && !readMethod.getName().equals("getClass")) {
-                    request.setAttribute(propertyDescriptor.getName(), readMethod.invoke(controller));
+                    String name = propertyDescriptor.getName();
+                    request.setAttribute(name, readMethod.invoke(controller));
+                    Object value = request.getAttribute(name);
+                    bindMonitor.attributeValueBoundFromController(name, value, controller);
                 }
             }
         } catch (IntrospectionException e) {
-            bindMonitor.bindFailedForController(controller, e);
+            bindMonitor.attributeBindFailed(controller, e);
             throw new WaffleException(e);
         } catch (IllegalAccessException e) {
-            bindMonitor.bindFailedForController(controller, e);
+            bindMonitor.attributeBindFailed(controller, e);
             throw new WaffleException(e);
         } catch (InvocationTargetException e) {
-            bindMonitor.bindFailedForController(controller, e);
+            bindMonitor.attributeBindFailed(controller, e);
             throw new WaffleException(e);
         }
     }

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlDataBinder.java (601 => 602)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlDataBinder.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlDataBinder.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -52,21 +52,22 @@
         Enumeration<String> parameterNames = request.getParameterNames();
 
         while (parameterNames.hasMoreElements()) {
-            String name = parameterNames.nextElement();           
-            String value = getParameterValue(request, name);
+            String parameterName = parameterNames.nextElement();           
+            String parameterValue = getParameterValue(request, parameterName);
 
             try {
-                handleConvert(name, value, controller);
+                Object dataValue = handleConvert(parameterName, parameterValue, controller);
+                bindMonitor.dataValueBoundToController(parameterName, dataValue, controller);
             } catch (OgnlException e) {
-                String message = bindErrorMessageResolver.resolve(controller, name, value);
-                BindErrorMessage errorMessage = new BindErrorMessage(name, value, message);
+                String message = bindErrorMessageResolver.resolve(controller, parameterName, parameterValue);
+                BindErrorMessage errorMessage = new BindErrorMessage(parameterName, parameterValue, message);
                 errorsContext.addErrorMessage(errorMessage);
-                bindMonitor.bindFailedForModel(controller, errorMessage);                
+                bindMonitor.dataBindFailed(controller, errorMessage);                
             } catch (BindException e) {
                 // by convention BindExceptions should provide the correct bind error message to display to the end-user
-                BindErrorMessage errorMessage = new BindErrorMessage(name, value, e.getMessage());
+                BindErrorMessage errorMessage = new BindErrorMessage(parameterName, parameterValue, e.getMessage());
                 errorsContext.addErrorMessage(errorMessage);
-                bindMonitor.bindFailedForModel(controller, errorMessage);
+                bindMonitor.dataBindFailed(controller, errorMessage);
             }
         }
     }
@@ -94,7 +95,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    protected void handleConvert(String propertyName,
+    protected Object handleConvert(String propertyName,
                                  String parameterValue,
                                  Object controller) throws OgnlException, BindException {
         try {
@@ -102,6 +103,7 @@
             Map ognlContext = Ognl.createDefaultContext(controller);
             Ognl.setTypeConverter(ognlContext, typeConverter);
             Ognl.setValue(tree, ognlContext, controller, parameterValue);
+            return Ognl.getValue(tree, ognlContext, controller);
         } catch (NoSuchPropertyException ignore) {
             // ignore NoSuchPropertyException
         } catch (InappropriateExpressionException ignore) {
@@ -112,6 +114,7 @@
             }
             throw e;
         }
+        return parameterValue;
     }
 
 }

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (601 => 602)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -73,8 +73,10 @@
         levels.put("argumentNameNotMatched", INFO);
         levels.put("responseIsCommitted", INFO);
         levels.put("viewDispatched", INFO);
-        levels.put("bindFailedForModel", INFO);
-        levels.put("bindFailedForController", INFO);
+        levels.put("attributeBindFailed", WARN);
+        levels.put("attributeValueBoundFromController", DEBUG);
+        levels.put("dataBindFailed", WARN);
+        levels.put("dataValueBoundToController", DEBUG);
         levels.put("registrarCreated", INFO);
         levels.put("registrarNotFound", WARN);
         levels.put("contextInitialized", DEBUG);
@@ -113,39 +115,41 @@
     protected Map<String, String> monitorMessages() {
         Map<String, String> messages = new HashMap<String, String>();
         messages.put("defaultActionMethodFound", "Default ActionMethod found: {0}");
-        messages.put("defaultActionMethodCached", "Default ActionMethod cached for controller {0}: {1}");
+        messages.put("defaultActionMethodCached", "Default ActionMethod cached for controller ''{0}'': {1}");
         messages.put("pragmaticActionMethodFound", "Pragmatic ActionMethod found: {0}");
         messages.put("actionMethodFound", "ActionMethod found: {0}");
         messages.put("actionMethodExecuted", "ActionMethod executed with response: {0}");
         messages.put("actionMethodExecutionFailed", "ActionMethod failed: {0}");
-        messages.put("methodNameResolved", "Method name ''{0}'' found for key ''{1}'' among keys {2}");
+        messages.put("methodNameResolved", "Method name ''{0}'' found for key ''{1}'' among keys ''{2}''");
         messages.put("methodIntercepted", "Method ''{0}'' intercepted with arguments {1} and returned value ''{2}''");
         messages.put("argumentNameResolved", "Argument name ''{0}'' resolved to ''{1}'' in scope ''{2}''");
         messages.put("argumentNameNotMatched", "Argument name ''{0}'' not matched by pattern ''{1}''");
         messages.put("responseIsCommitted", "Response is committed for response: {0}");
         messages.put("viewDispatched", "View dispatched: {0}");
-        messages.put("bindFailedForModel", "Bind failed for model ''{0}'': {1}");
-        messages.put("bindFailedForController", "Bind failed for controller ''{0}'': {1}");
-        messages.put("registrarCreated", "Registrar created {0} with monitor {1}");
-        messages.put("registrarNotFound", "Registrar not found {0}");
+        messages.put("attributeBindFailed", "Attribute bind failed from controller ''{0}'': {1}");
+        messages.put("attributeValueBoundFromController", "Attribute value ''{1}'' bound for name ''{0}'' from controller ''{2}''");        
+        messages.put("dataBindFailed", "Data bind failed to controller ''{0}'': {1}");
+        messages.put("dataValueBoundToController", "Data value ''{1}'' bound for name ''{0}'' to controller ''{2}''");        
+        messages.put("registrarCreated", "Registrar ''{0}'' created  with monitor ''{1}''");
+        messages.put("registrarNotFound", "Registrar ''{0}'' not found");
         messages.put("contextInitialized", "Context initialized");
         messages.put("applicationContextContainerStarted", "Application context container started");
         messages.put("applicationContextContainerDestroyed", "Application context container destroyed");
-        messages.put("sessionContextContainerCreated", "Session context container created with parent application container {0}");
-        messages.put("requestContextContainerCreated", "Request context container created with parent session container {0}");
-        messages.put("controllerNameResolved", "Controller name resolved to {0} from path {1}");        
-        messages.put("controllerNotFound", "Controller not found for name {0}");
-        messages.put("methodDefinitionNotFound", "Method definition not found for controller name {0}");
+        messages.put("sessionContextContainerCreated", "Session context container created with parent application container ''{0}''");
+        messages.put("requestContextContainerCreated", "Request context container created with parent session container ''{0}''");
+        messages.put("controllerNameResolved", "Controller name resolved to ''{0}'' from path ''{1}''");        
+        messages.put("controllerNotFound", "Controller not found for name ''{0}''");
+        messages.put("methodDefinitionNotFound", "Method definition not found for controller name ''{0}''");
         messages.put("requestContextContainerNotFound", "Request level context container not found");
-        messages.put("componentRegistered", "Registered component of type {1} with key {0} and parameters {2}");
-        messages.put("instanceRegistered", "Registered instance {1} with key {0}");
-        messages.put("nonCachingComponentRegistered", "Registered non-caching component of type {1} with key {0} and parameters {2}");
+        messages.put("componentRegistered", "Registered component of type ''{1}'' with key ''{0}'' and parameters ''{2}''");
+        messages.put("instanceRegistered", "Registered instance ''{1}'' with key ''{0}''");
+        messages.put("nonCachingComponentRegistered", "Registered non-caching component of type ''{1}'' with key ''{0}'' and parameters ''{2}''");
         messages.put("servletServiceFailed", "Servlet service failed: {0}");
         messages.put("servletServiceRequested", "Servlet service requested with parameters: {0}");
-        messages.put("controllerValidatorNotFound", "Controller validator {0} not found: defaulting to controller {1}");
-        messages.put("methodDefinitionNotFound", "Method definition not found in controller definition {0}");        
+        messages.put("controllerValidatorNotFound", "Controller validator ''{0}'' not found: defaulting to controller ''{1}''");
+        messages.put("methodDefinitionNotFound", "Method definition not found in controller definition ''{0}''");        
         messages.put("validationFailed", "Validation failed: {0}");  
-        messages.put("viewForwarded", "View forwarded to path {0}");        
+        messages.put("viewForwarded", "View forwarded to path ''{0}''");        
         messages.put("viewRedirected", "View redirected: {0}");
         messages.put("viewResponded", "View responded: {0}");
         return messages;
@@ -247,14 +251,22 @@
         write("viewDispatched", view);        
     }
 
-    public void bindFailedForModel(Object bindModel, BindErrorMessage errorMessage){
-        write("bindFailedForModel", bindModel, errorMessage);
+    public void attributeBindFailed(Object controller, Throwable cause){
+        write("attributeBindFailed", controller, cause);
     }
+
+    public void attributeValueBoundFromController(String name, Object value, Object controller) {
+        write("attributeValueBoundFromController", name, value, controller);
+    }
+
+    public void dataBindFailed(Object controller, BindErrorMessage errorMessage){
+        write("dataBindFailed", controller, errorMessage);
+    }
     
-    public void bindFailedForController(Object controller, Throwable cause){
-        write("bindFailedForController", controller, cause);
+    public void dataValueBoundToController(String name, Object value, Object controller) {
+        write("dataValueBoundToController", name, value, controller);
     }
-    
+
     public void registrarCreated(Registrar registrar, RegistrarMonitor registrarMonitor) {
         write("registrarCreated", registrar, registrarMonitor);         
     }

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java (601 => 602)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -19,8 +19,12 @@
  */
 public interface BindMonitor extends Monitor {
 
-    void bindFailedForModel(Object bindModel, BindErrorMessage errorMessage);
+    void attributeBindFailed(Object controller, Throwable cause);
 
-    void bindFailedForController(Object controller, Throwable cause);
+    void attributeValueBoundFromController(String name, Object value, Object controller);
+
+    void dataBindFailed(Object controller, BindErrorMessage errorMessage);
+
+    void dataValueBoundToController(String name, Object value, Object controller);
     
 }

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinderTest.java (601 => 602)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinderTest.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/IntrospectingRequestAttributeBinderTest.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -22,7 +22,11 @@
 
         context.checking(new Expectations() {{
             one (request).setAttribute("name", "my controller");
+            one (request).getAttribute("name");
+            will(returnValue("my controller"));
             one (request).setAttribute("null", null);
+            one (request).getAttribute("null");
+            will(returnValue(null));
         }});
 
         IntrospectingRequestAttributeBinder binder = new IntrospectingRequestAttributeBinder(new SilentMonitor());

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java (601 => 602)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -7,7 +7,6 @@
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
@@ -236,7 +235,7 @@
         });
 
         DataBinder binder = new OgnlDataBinder(new OgnlValueConverterFinder(), null, new SilentMonitor()) {
-            protected void handleConvert(String parameterName, String parameterValue, Object model) {
+            protected Object handleConvert(String parameterName, String parameterValue, Object model) {
                 throw new BindException("fake from test");
             }
         };

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (601 => 602)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java	2008-04-02 14:08:08 UTC (rev 601)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java	2008-04-02 17:16:01 UTC (rev 602)
@@ -1,6 +1,7 @@
 package org.codehaus.waffle.testmodel;
 
 import java.lang.reflect.Method;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -64,15 +65,18 @@
     public void viewDispatched(View view) {
     }
 
-    public void bindFailedForModel(Object bindModel, BindErrorMessage errorMessage) {
+    public void dataBindFailed(Object controller, BindErrorMessage errorMessage) {
     }
 
-    public void bindFailedForController(Object controller, Throwable cause) {
+    public void attributeBindFailed(Object controller, Throwable cause) {
     }
 
-    public void valueBound(String name, String value, Object controller) {
+    public void attributeValueBoundFromController(String name, Object value, Object controller) {
     }
 
+    public void dataValueBoundToController(String name, Object value, Object controller) {
+    }
+
     public void contextInitialized() {
     }
 
@@ -118,7 +122,7 @@
     public void servletServiceFailed(Exception cause) {
     }
     
-    public void servletServiceRequested(Map parameters) {
+    public void servletServiceRequested(Map<String, List<String>> parameters) {
     }
 
     public void controllerValidatorNotFound(String controllerValidatorName, String controllerName) {


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to