From 6651ff0c5528bf60eed3a3382846ba8d59415b02 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Sep 2009 01:35:36 +0000 Subject: [PATCH] fixed formatter annotation lookup --- .../FormattingConversionServiceAdapter.java | 18 +++++++++--------- .../support/GenericConversionService.java | 16 ++++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java index 4cf55e896f6..c0b7346aa1d 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java @@ -18,6 +18,7 @@ package org.springframework.ui.format.support; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.GenericConversionService; @@ -53,28 +54,27 @@ public class FormattingConversionServiceAdapter extends GenericConversionService } } - @Override - protected Converter findRegisteredConverter(Class sourceType, Class targetType) { + protected Converter findConverter(Class sourceType, TypeDescriptor targetType) { if (String.class.equals(sourceType)) { - Formatter formatter = this.formatterRegistry.getFormatter(targetType); + Formatter formatter = this.formatterRegistry.getFormatter(targetType); if (formatter != null) { - return new FormattingConverter(formatter); + return new FormattingConverter(formatter); } } - return super.findRegisteredConverter(sourceType, targetType); + return super.findConverter(sourceType, targetType); } - private static class FormattingConverter implements Converter { + private static class FormattingConverter implements Converter { - private final Formatter formatter; + private final Formatter formatter; - public FormattingConverter(Formatter formatter) { + public FormattingConverter(Formatter formatter) { this.formatter = formatter; } - public T convert(String source) throws Exception { + public Object convert(String source) throws Exception { return this.formatter.parse(source, LocaleContextHolder.getLocale()); } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index b195186ffd7..d7e264a43df 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -161,8 +161,8 @@ public class GenericConversionService implements ConversionService, ConverterReg ConversionExecutor getConversionExecutor(final Class sourceClass, final TypeDescriptor targetType) throws ConverterNotFoundException { - Assert.notNull(sourceClass, "The sourceType to convert from is required"); - Assert.notNull(targetType, "The targetType to convert to is required"); + Assert.notNull(sourceClass, "Source type to convert from is required"); + Assert.notNull(targetType, "Target type to convert to is required"); if (targetType.getType() == null) { return NoOpConversionExecutor.INSTANCE; } @@ -281,9 +281,7 @@ public class GenericConversionService implements ConversionService, ConverterReg if (sourceType.isAssignableTo(targetType)) { return NoOpConversionExecutor.INSTANCE; } - Converter converter = findRegisteredConverter( - ClassUtils.resolvePrimitiveIfNecessary(sourceClass), - ClassUtils.resolvePrimitiveIfNecessary(targetType.getType())); + Converter converter = findConverter(sourceClass, targetType); if (converter != null) { return new StaticConversionExecutor(sourceType, targetType, converter); } @@ -368,7 +366,13 @@ public class GenericConversionService implements ConversionService, ConverterReg return sourceMap; } - protected Converter findRegisteredConverter(Class sourceType, Class targetType) { + protected Converter findConverter(Class sourceType, TypeDescriptor targetType) { + return findRegisteredConverter( + ClassUtils.resolvePrimitiveIfNecessary(sourceType), + ClassUtils.resolvePrimitiveIfNecessary(targetType.getType())); + } + + private Converter findRegisteredConverter(Class sourceType, Class targetType) { if (sourceType.isInterface()) { LinkedList classQueue = new LinkedList(); classQueue.addFirst(sourceType);