Browse Source

generic converter updates

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1933 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 17 years ago
parent
commit
4342f50946
  1. 11
      org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java
  2. 9
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java

11
org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java

@ -55,8 +55,8 @@ public class FormattingConversionServiceAdapter extends GenericConversionService @@ -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 @@ -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);
}
}
}
}

9
org.springframework.core/src/main/java/org/springframework/core/convert/support/MatchableGenericConverter.java

@ -1,9 +0,0 @@ @@ -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);
}
Loading…
Cancel
Save