generic converter updates

This commit is contained in:
Keith Donald 2009-09-18 20:08:45 +00:00
parent d3b43ebccb
commit f1f4bd9fb4
2 changed files with 8 additions and 12 deletions

View File

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

View File

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