fixed formatter annotation lookup
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1841 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
1abf0698b6
commit
7626f8f69d
|
|
@ -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 <T> Converter findRegisteredConverter(Class<?> sourceType, Class<T> targetType) {
|
||||
protected Converter findConverter(Class<?> sourceType, TypeDescriptor targetType) {
|
||||
if (String.class.equals(sourceType)) {
|
||||
Formatter<T> formatter = this.formatterRegistry.getFormatter(targetType);
|
||||
Formatter formatter = this.formatterRegistry.getFormatter(targetType);
|
||||
if (formatter != null) {
|
||||
return new FormattingConverter<T>(formatter);
|
||||
return new FormattingConverter(formatter);
|
||||
}
|
||||
}
|
||||
return super.findRegisteredConverter(sourceType, targetType);
|
||||
return super.findConverter(sourceType, targetType);
|
||||
}
|
||||
|
||||
|
||||
private static class FormattingConverter<T> implements Converter<String, T> {
|
||||
private static class FormattingConverter implements Converter<String, Object> {
|
||||
|
||||
private final Formatter<T> formatter;
|
||||
private final Formatter formatter;
|
||||
|
||||
public FormattingConverter(Formatter<T> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <T> Converter findRegisteredConverter(Class<?> sourceType, Class<T> 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<Class> classQueue = new LinkedList<Class>();
|
||||
classQueue.addFirst(sourceType);
|
||||
|
|
|
|||
Loading…
Reference in New Issue