removed valueOf convention b/c of unwanted side effects

This commit is contained in:
Keith Donald
2009-10-14 21:37:57 +00:00
parent dc076ee6fe
commit 4d9bf3a45f
3 changed files with 5 additions and 46 deletions

View File

@@ -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;