From 4d9bf3a45f9e83c8ff4991104df80d0506537cc4 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 14 Oct 2009 21:37:57 +0000 Subject: [PATCH] removed valueOf convention b/c of unwanted side effects --- .../support/GenericFormatterRegistry.java | 36 ++----------------- .../format/GenericFormatterRegistryTests.java | 7 ++-- .../support/ObjectToStringConverter.java | 8 ----- 3 files changed, 5 insertions(+), 46 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java b/org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java index ffeb83f63f..9b50da4c96 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java @@ -277,7 +277,7 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC } else { Formatted formattedAnnotation = annotationType.getAnnotation(Formatted.class); if (formattedAnnotation != null) { - // annotation has @Formatted meta-annotation + // property annotation has @Formatted meta-annotation Formatter formatter = createFormatter(formattedAnnotation.value()); addFormatterByAnnotation(annotationType, formatter); return findFormatterHolderForAnnotation(annotation); @@ -315,14 +315,7 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC addFormatterByType(type, formatter); return findFormatterHolderForType(type); } else { - Method valueOfMethod = getValueOfMethod(type); - if (valueOfMethod != null) { - Formatter formatter = createFormatter(valueOfMethod); - addFormatterByType(type, formatter); - return findFormatterHolderForType(type); - } else { - return null; - } + return null; } } @@ -331,31 +324,6 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC formatterClass) : BeanUtils.instantiate(formatterClass)); } - private Method getValueOfMethod(Class type) { - Method[] methods = type.getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; - if ("valueOf".equals(method.getName()) && acceptsSingleStringParameterType(method) - && Modifier.isPublic(method.getModifiers()) && Modifier.isStatic(method.getModifiers())) { - return method; - } - } - return null; - } - - private boolean acceptsSingleStringParameterType(Method method) { - Class[] paramTypes = method.getParameterTypes(); - if (paramTypes == null) { - return false; - } else { - return paramTypes.length == 1 && paramTypes[0] == String.class; - } - } - - private Formatter createFormatter(Method valueOfMethod) { - return new ValueOfMethodFormatter(valueOfMethod); - } - private abstract static class AbstractFormatterHolder { private Class formattedObjectType; diff --git a/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java b/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java index 9bd4141e54..d4dcc8e653 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java @@ -17,6 +17,7 @@ package org.springframework.ui.format; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -104,10 +105,8 @@ public class GenericFormatterRegistryTests { } @Test - public void testGetDefaultFormatterForTypeValueOfMethod() throws ParseException { - Formatter formatter = registry.getFormatter(TypeDescriptor.valueOf(Integer.class)); - assertEquals("3", formatter.format(new Integer(3), null)); - assertEquals(new Integer(3), formatter.parse("3", null)); + public void testGetDefaultFormatterNull() throws ParseException { + assertNull(registry.getFormatter(TypeDescriptor.valueOf(Integer.class))); } @Test(expected = IllegalArgumentException.class) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java index a81d881d92..b9fa55dcc6 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java @@ -28,14 +28,6 @@ import org.springframework.core.convert.converter.Converter; */ final class ObjectToStringConverter implements Converter { - public Class getSourceType() { - return Object.class; - } - - public Class getTargetType() { - return String.class; - } - public String convert(Object source) { return source.toString(); }