|
|
@ -74,7 +74,7 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
} |
|
|
|
} |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "null"; |
|
|
|
return "NO_MATCH"; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -85,13 +85,6 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
|
|
|
|
|
|
|
|
// implementing ConverterRegistry
|
|
|
|
// implementing ConverterRegistry
|
|
|
|
|
|
|
|
|
|
|
|
public void addConverter(GenericConverter converter) { |
|
|
|
|
|
|
|
Set<GenericConverter.ConvertiblePair> convertibleTypes = converter.getConvertibleTypes(); |
|
|
|
|
|
|
|
for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) { |
|
|
|
|
|
|
|
getMatchableConvertersList(convertibleType.getSourceType(), convertibleType.getTargetType()).add(converter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addConverter(Converter<?, ?> converter) { |
|
|
|
public void addConverter(Converter<?, ?> converter) { |
|
|
|
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converter, Converter.class); |
|
|
|
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converter, Converter.class); |
|
|
|
if (typeInfo == null) { |
|
|
|
if (typeInfo == null) { |
|
|
@ -110,11 +103,19 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory)); |
|
|
|
addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addConverter(GenericConverter converter) { |
|
|
|
|
|
|
|
Set<GenericConverter.ConvertiblePair> convertibleTypes = converter.getConvertibleTypes(); |
|
|
|
|
|
|
|
for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) { |
|
|
|
|
|
|
|
getMatchableConverters(convertibleType.getSourceType(), convertibleType.getTargetType()).add(converter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invalidateCache(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void removeConvertible(Class<?> sourceType, Class<?> targetType) { |
|
|
|
public void removeConvertible(Class<?> sourceType, Class<?> targetType) { |
|
|
|
getSourceConverterMap(sourceType).remove(targetType); |
|
|
|
getSourceConverterMap(sourceType).remove(targetType); |
|
|
|
|
|
|
|
invalidateCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// implementing ConversionService
|
|
|
|
// implementing ConversionService
|
|
|
|
|
|
|
|
|
|
|
|
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { |
|
|
|
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { |
|
|
@ -210,7 +211,6 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
return builder.toString(); |
|
|
|
return builder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// subclassing hooks
|
|
|
|
// subclassing hooks
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -295,7 +295,6 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// internal helpers
|
|
|
|
// internal helpers
|
|
|
|
|
|
|
|
|
|
|
|
private GenericConverter.ConvertiblePair getRequiredTypeInfo(Object converter, Class<?> genericIfc) { |
|
|
|
private GenericConverter.ConvertiblePair getRequiredTypeInfo(Object converter, Class<?> genericIfc) { |
|
|
@ -303,7 +302,7 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
return (args != null ? new GenericConverter.ConvertiblePair(args[0], args[1]) : null); |
|
|
|
return (args != null ? new GenericConverter.ConvertiblePair(args[0], args[1]) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MatchableConverters getMatchableConvertersList(Class<?> sourceType, Class<?> targetType) { |
|
|
|
private MatchableConverters getMatchableConverters(Class<?> sourceType, Class<?> targetType) { |
|
|
|
Map<Class<?>, MatchableConverters> sourceMap = getSourceConverterMap(sourceType); |
|
|
|
Map<Class<?>, MatchableConverters> sourceMap = getSourceConverterMap(sourceType); |
|
|
|
MatchableConverters matchable = sourceMap.get(targetType); |
|
|
|
MatchableConverters matchable = sourceMap.get(targetType); |
|
|
|
if (matchable == null) { |
|
|
|
if (matchable == null) { |
|
|
@ -313,6 +312,10 @@ public class GenericConversionService implements ConversionService, ConverterReg |
|
|
|
return matchable; |
|
|
|
return matchable; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void invalidateCache() { |
|
|
|
|
|
|
|
this.converterCache.clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<Class<?>, MatchableConverters> getSourceConverterMap(Class<?> sourceType) { |
|
|
|
private Map<Class<?>, MatchableConverters> getSourceConverterMap(Class<?> sourceType) { |
|
|
|
Map<Class<?>, MatchableConverters> sourceMap = converters.get(sourceType); |
|
|
|
Map<Class<?>, MatchableConverters> sourceMap = converters.get(sourceType); |
|
|
|
if (sourceMap == null) { |
|
|
|
if (sourceMap == null) { |
|
|
|