From 4342f509469233d96910185b97a236cfbc1eef29 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 18 Sep 2009 20:08:45 +0000 Subject: [PATCH] generic converter updates git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1933 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../support/FormattingConversionServiceAdapter.java | 11 ++++++++--- .../convert/support/MatchableGenericConverter.java | 9 --------- 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java 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 006fe1b2b3c..4750024ad4d 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 @@ -55,8 +55,8 @@ public class FormattingConversionServiceAdapter extends GenericConversionService } @Override - protected GenericConverter getConverter(Class sourceType, TypeDescriptor targetType) { - if (String.class.equals(sourceType)) { + protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { + if (String.class.equals(sourceType.getType())) { Formatter formatter = this.formatterRegistry.getFormatter(targetType); if (formatter != null) { return new FormattingConverter(formatter); @@ -76,13 +76,18 @@ public class FormattingConversionServiceAdapter extends GenericConversionService this.formatter = formatter; } - public Object convert(Object source, TypeDescriptor targetType) { + public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) { + throw new UnsupportedOperationException("Should not be called"); + } + + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { try { return this.formatter.parse((String) source, LocaleContextHolder.getLocale()); } catch (ParseException ex) { throw new IllegalArgumentException("Could not convert formatted value '" + source + "'", ex); } } + } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java deleted file mode 100644 index 3898392541a..00000000000 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.springframework.core.convert.support; - -import org.springframework.core.convert.TypeDescriptor; - -public interface MatchableGenericConverter extends GenericConverter { - - boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType); - -}