- Revision
- 743
- Author
- mauro
- Date
- 2008-06-19 11:17:34 -0500 (Thu, 19 Jun 2008)
Log Message
WAFFLE-88: Added value conversion events to BindMonitor.
Modified Paths
- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverter.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlControllerDataBinder.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java
Diff
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverter.java (742 => 743)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverter.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverter.java 2008-06-19 16:17:34 UTC (rev 743) @@ -8,15 +8,17 @@ import java.lang.reflect.Type; import java.util.Map; -import ognl.OgnlOps; import ognl.TypeConverter; import org.codehaus.waffle.bind.ValueConverter; import org.codehaus.waffle.bind.ValueConverterFinder; +import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.SilentMonitor; /** - * An implementation of Ognl's <code>TypeConverter</code> which handles Java 5 enums and will delegate custom - * <code>ValueConverter</code>'s registered per application. + * An implementation of Ognl's <code>TypeConverter</code> which handles Java 5 enums and will delegate to custom + * <code>ValueConverter</code>'s registered per application and retrieved via the the + * <code>ValueConverterFinder</code>. * * @author Michael Ward * @author Mauro Talevi @@ -24,13 +26,15 @@ public class DelegatingTypeConverter implements TypeConverter { private static final String EMPTY = ""; private final ValueConverterFinder valueConverterFinder; + private final BindMonitor bindMonitor; public DelegatingTypeConverter() { - this(new OgnlValueConverterFinder()); + this(new OgnlValueConverterFinder(), new SilentMonitor()); } - public DelegatingTypeConverter(ValueConverterFinder valueConverterFinder) { + public DelegatingTypeConverter(ValueConverterFinder valueConverterFinder, BindMonitor bindMonitor) { this.valueConverterFinder = valueConverterFinder; + this.bindMonitor = bindMonitor; } /** @@ -56,8 +60,11 @@ private Type genericParameterTypeFor(Method method) { Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes.length > 0) { - return parameterTypes[0]; + Type type = parameterTypes[0]; + bindMonitor.genericParameterTypeFound(type, method); + return type; } + bindMonitor.genericParameterTypeNotFound(method); return null; } @@ -66,26 +73,25 @@ * * @param propertyName property name being set * @param value value to be converted - * @param toType type to which value is converted - * @return Converted value Object of type toType or TypeConverter.NoConversionPossible to indicate that the - * conversion was not possible. + * @param type Type to which value is converted + * @return Converted value Object for type or the unconvertered value if type is not an enum or no converter found */ @SuppressWarnings( { "unchecked" }) - public Object convertValue(String propertyName, String value, Type toType) { - if (toType instanceof Class && ((Class) toType).isEnum()) { + public Object convertValue(String propertyName, String value, Type type) { + if (type instanceof Class && ((Class) type).isEnum()) { if (EMPTY.equals(value)) { return null; } - return Enum.valueOf((Class) toType, value); + return Enum.valueOf((Class) type, value); } - ValueConverter converter = valueConverterFinder.findConverter(toType); + ValueConverter converter = valueConverterFinder.findConverter(type); if (converter != null) { - return converter.convertValue(propertyName, value, toType); - } else if (toType instanceof Class) { - return OgnlOps.convertValue(value, (Class) toType); + bindMonitor.valueConverterFound(type, converter); + return converter.convertValue(propertyName, value, type); } else { + bindMonitor.valueConverterNotFound(type); return value; } }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlControllerDataBinder.java (742 => 743)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlControllerDataBinder.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlControllerDataBinder.java 2008-06-19 16:17:34 UTC (rev 743) @@ -35,7 +35,7 @@ private final BindMonitor bindMonitor; public OgnlControllerDataBinder(ValueConverterFinder valueConverterFinder, BindErrorMessageResolver bindErrorMessageResolver, BindMonitor bindMonitor) { - this.typeConverter = new DelegatingTypeConverter(valueConverterFinder); + this.typeConverter = new DelegatingTypeConverter(valueConverterFinder, bindMonitor); this.bindErrorMessageResolver = bindErrorMessageResolver; this.bindMonitor = bindMonitor; }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (742 => 743)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2008-06-19 16:17:34 UTC (rev 743) @@ -10,6 +10,7 @@ import static org.codehaus.waffle.monitor.Monitor.Level.WARN; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -23,6 +24,7 @@ import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; +import org.codehaus.waffle.bind.ValueConverter; import org.codehaus.waffle.context.ContextContainer; import org.codehaus.waffle.controller.ControllerDefinition; import org.codehaus.waffle.registrar.Registrar; @@ -73,6 +75,10 @@ levels.put("viewValueBound", DEBUG); levels.put("controllerBindFailed", WARN); levels.put("controllerValueBound", DEBUG); + levels.put("genericParameterTypeFound", DEBUG); + levels.put("genericParameterTypeNotFound", DEBUG); + levels.put("valueConverterFound", DEBUG); + levels.put("valueConverterNotFound", DEBUG); levels.put("registrarCreated", INFO); levels.put("registrarNotFound", WARN); levels.put("contextInitialized", DEBUG); @@ -122,12 +128,16 @@ 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("responseIsCommitted", "Response is committed for response: {0}"); messages.put("viewDispatched", "View dispatched: {0}"); messages.put("viewBindFailed", "View bind failed from controller ''{0}'': {1}"); messages.put("viewValueBound", "View value ''{1}'' bound for name ''{0}'' from controller ''{2}''"); messages.put("controllerBindFailed", "Controller bind failed to controller ''{0}'' with message {1}: {2}"); - messages.put("controllerValueBound", "Controller value ''{1}'' bound for name ''{0}'' to controller ''{2}''"); + messages.put("controllerValueBound", "Controller value ''{1}'' bound for name ''{0}'' to controller ''{2}''"); + messages.put("genericParameterTypeFound", "Generic parameter type ''{0}'' found for method ''{1}''"); + messages.put("genericParameterTypeNotFound", "Generic parameter type not found for method ''{0}''"); + messages.put("valueConverterFound", "Value converter ''{0}'' found for type ''{1}''"); + messages.put("valueConverterNotFound", "Value converter not found for type ''{0}''"); messages.put("registrarCreated", "Registrar ''{0}'' created with monitor ''{1}''"); messages.put("registrarNotFound", "Registrar ''{0}'' not found"); messages.put("contextInitialized", "Context initialized"); @@ -251,6 +261,22 @@ write("viewDispatched", view); } + public void genericParameterTypeFound(Type type, Method method) { + write("genericParameterTypeFound", type, method); + } + + public void genericParameterTypeNotFound(Method method) { + write("genericParameterTypeNotFound", method); + } + + public void valueConverterFound(Type type, ValueConverter converter) { + write("valueConverterFound", type, converter); + } + + public void valueConverterNotFound(Type type) { + write("valueConverterNotFound", type); + } + public void viewBindFailed(Object controller, Exception cause){ write("viewBindFailed", controller, cause); } @@ -266,7 +292,7 @@ public void controllerValueBound(String name, Object value, Object controller) { write("controllerValueBound", name, value, controller); } - + public void registrarCreated(Registrar registrar, RegistrarMonitor registrarMonitor) { write("registrarCreated", registrar, registrarMonitor); } @@ -362,4 +388,5 @@ public void viewResponded(ResponderView responderView) { write("viewResponded", responderView); } + }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java (742 => 743)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/BindMonitor.java 2008-06-19 16:17:34 UTC (rev 743) @@ -3,6 +3,10 @@ */ package org.codehaus.waffle.monitor; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import org.codehaus.waffle.bind.ValueConverter; import org.codehaus.waffle.validation.BindErrorMessage; /** @@ -19,5 +23,13 @@ void controllerBindFailed(Object controller, BindErrorMessage errorMessage, Exception cause); void controllerValueBound(String name, Object value, Object controller); + + void genericParameterTypeFound(Type type, Method method); + + void genericParameterTypeNotFound(Method method); + + void valueConverterFound(Type type, ValueConverter converter); + + void valueConverterNotFound(Type type); }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java (742 => 743)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java 2008-06-19 16:17:34 UTC (rev 743) @@ -11,6 +11,8 @@ import org.codehaus.waffle.bind.converters.StringListValueConverter; import org.codehaus.waffle.context.ContextLevel; import org.codehaus.waffle.i18n.DefaultMessageResources; +import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.SilentMonitor; import org.codehaus.waffle.testmodel.FakeControllerWithListMethods; import org.jmock.Expectations; import org.jmock.Mockery; @@ -26,6 +28,7 @@ public class DelegatingTypeConverterTest { private Mockery mockery = new Mockery(); + private BindMonitor bindMonitor = new SilentMonitor(); @Test public void canConvertValueForEnum() { @@ -42,7 +45,7 @@ @Test public void canDelegateToListValueConverter() throws IntrospectionException { final ValueConverter valueConverter = new StringListValueConverter(new DefaultMessageResources()); - DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter)); + DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter), bindMonitor); assertEquals(asList("one", "two"), converter.convertValue("propertyName", "one,two", methodParameterType("listOfStrings"))); assertEquals(asList(), converter.convertValue("propertyName", "", methodParameterType("listOfStrings"))); } @@ -61,13 +64,13 @@ will(returnValue(controller)); } }); - DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter)); + DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter), bindMonitor); assertSame(controller, converter.convertValue("propertyName", "foobar", FakeControllerWithListMethods.class)); } @Test public void canReturnValueIfNotConverterFoundForTypeThatIsNotAClass() throws IntrospectionException { - DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder()); + DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(), bindMonitor); assertEquals("one,two", converter.convertValue("propertyName", "one,two", FakeControllerWithListMethods .methodParameterType("listOfStrings"))); }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (742 => 743)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2008-06-19 11:02:23 UTC (rev 742) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2008-06-19 16:17:34 UTC (rev 743) @@ -1,6 +1,7 @@ package org.codehaus.waffle.testmodel; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.List; import java.util.Map; import java.util.Set; @@ -11,6 +12,7 @@ import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; +import org.codehaus.waffle.bind.ValueConverter; import org.codehaus.waffle.context.ContextContainer; import org.codehaus.waffle.controller.ControllerDefinition; import org.codehaus.waffle.monitor.ActionMonitor; @@ -78,6 +80,18 @@ public void controllerValueBound(String name, Object value, Object controller) { } + public void genericParameterTypeFound(Type type, Method method) { + } + + public void genericParameterTypeNotFound(Method method) { + } + + public void valueConverterFound(Type type, ValueConverter converter) { + } + + public void valueConverterNotFound(Type type) { + } + public void contextInitialized() { } @@ -150,4 +164,5 @@ public void viewResponded(ResponderView responderView) { } + }
To unsubscribe from this list please visit:
