|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.convert.support.GenericConversionService
public class GenericConversionService
Base ConversionService
implementation suitable for use in most environments.
Implements ConverterRegistry
as registration API.
Nested Class Summary | |
---|---|
private class |
GenericConversionService.ConverterAdapter
|
private static class |
GenericConversionService.ConverterCacheKey
|
private class |
GenericConversionService.ConverterFactoryAdapter
|
private static class |
GenericConversionService.MatchableConverters
|
Field Summary | |
---|---|
private java.util.Map<GenericConversionService.ConverterCacheKey,GenericConverter> |
converterCache
|
private java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters>> |
converters
|
private static GenericConverter |
NO_MATCH
|
private static GenericConverter |
NO_OP_CONVERTER
|
Constructor Summary | |
---|---|
GenericConversionService()
|
Method Summary | ||
---|---|---|
void |
addConverter(Converter<?,?> converter)
Add a plain converter to this registry. |
|
void |
addConverter(GenericConverter converter)
Add a generic converter to this registry. |
|
void |
addConverterFactory(ConverterFactory<?,?> converterFactory)
Add a ranged converter factory to this registry. |
|
private void |
addInterfaceHierarchy(java.lang.Class<?> ifc,
java.util.LinkedList<java.lang.Class<?>> classQueue)
|
|
private void |
assertNotNull(TypeDescriptor sourceType,
TypeDescriptor targetType)
|
|
boolean |
canConvert(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
Returns true if objects of sourceType can be converted to targetType. |
|
boolean |
canConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
Returns true if objects of sourceType can be converted to the targetType. |
|
|
convert(java.lang.Object source,
java.lang.Class<T> targetType)
Convert the source to targetType. |
|
java.lang.Object |
convert(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert the source to targetType. |
|
protected java.lang.Object |
convertNullSource(TypeDescriptor sourceType,
TypeDescriptor targetType)
Template method to convert a null source. |
|
private GenericConverter |
findConverterForClassPair(TypeDescriptor sourceType,
TypeDescriptor targetType)
|
|
protected GenericConverter |
getConverter(TypeDescriptor sourceType,
TypeDescriptor targetType)
Hook method to lookup the converter for a given sourceType/targetType pair. |
|
protected GenericConverter |
getDefaultConverter(TypeDescriptor sourceType,
TypeDescriptor targetType)
Return the default converter if no converter is found for the given sourceType/targetType pair. |
|
private GenericConversionService.MatchableConverters |
getMatchableConverters(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
|
|
private GenericConverter |
getMatchingConverterForTarget(TypeDescriptor sourceType,
TypeDescriptor targetType,
java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> converters)
|
|
private GenericConverter.ConvertiblePair |
getRequiredTypeInfo(java.lang.Object converter,
java.lang.Class<?> genericIfc)
|
|
private java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> |
getSourceConverterMap(java.lang.Class<?> sourceType)
|
|
private java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> |
getTargetConvertersForSource(java.lang.Class<?> sourceType)
|
|
private void |
invalidateCache()
|
|
private GenericConverter |
matchConverter(GenericConversionService.MatchableConverters matchable,
TypeDescriptor sourceFieldType,
TypeDescriptor targetFieldType)
|
|
void |
removeConvertible(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
Remove any converters from sourceType to targetType. |
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final GenericConverter NO_OP_CONVERTER
private static final GenericConverter NO_MATCH
private final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters>> converters
private final java.util.Map<GenericConversionService.ConverterCacheKey,GenericConverter> converterCache
Constructor Detail |
---|
public GenericConversionService()
Method Detail |
---|
public void addConverter(Converter<?,?> converter)
ConverterRegistry
addConverter
in interface ConverterRegistry
public void addConverterFactory(ConverterFactory<?,?> converterFactory)
ConverterRegistry
addConverterFactory
in interface ConverterRegistry
public void addConverter(GenericConverter converter)
ConverterRegistry
addConverter
in interface ConverterRegistry
public void removeConvertible(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
ConverterRegistry
removeConvertible
in interface ConverterRegistry
sourceType
- the source typetargetType
- the target typepublic boolean canConvert(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
ConversionService
canConvert
in interface ConversionService
sourceType
- the source type to convert from (required)targetType
- the target type to convert to (required)
public <T> T convert(java.lang.Object source, java.lang.Class<T> targetType)
ConversionService
convert
in interface ConversionService
source
- the source object to convert (may be null)targetType
- the target type to convert to (required)
public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
ConversionService
canConvert
in interface ConversionService
sourceType
- context about the source type to convert from (required)targetType
- context about the target type to convert to (required)
public java.lang.Object convert(java.lang.Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
ConversionService
convert
in interface ConversionService
source
- the source object to convert (may be null)sourceType
- context about the source type converting from (required)targetType
- context about the target type to convert to (required)
targetType
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType)
Default implementation returns null
.
Throws a ConversionFailedException
if the targetType is a primitive type,
as null
cannot be assigned to a primitive type.
Subclasses may override to return custom null objects for specific target types.
sourceType
- the sourceType to convert fromtargetType
- the targetType to convert to
protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType)
First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter. Subclasses may override.
sourceType
- the source type to convert fromtargetType
- the target type to convert to
null
if no suitable converter was foundgetDefaultConverter(TypeDescriptor, TypeDescriptor)
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType)
null
otherwise, indicating no suitable converter could be found.
Subclasses may override.
sourceType
- the source type to convert fromtargetType
- the target type to convert to
private GenericConverter.ConvertiblePair getRequiredTypeInfo(java.lang.Object converter, java.lang.Class<?> genericIfc)
private GenericConversionService.MatchableConverters getMatchableConverters(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
private void invalidateCache()
private java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> getSourceConverterMap(java.lang.Class<?> sourceType)
private void assertNotNull(TypeDescriptor sourceType, TypeDescriptor targetType)
private GenericConverter findConverterForClassPair(TypeDescriptor sourceType, TypeDescriptor targetType)
private java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> getTargetConvertersForSource(java.lang.Class<?> sourceType)
private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType, java.util.Map<java.lang.Class<?>,GenericConversionService.MatchableConverters> converters)
private void addInterfaceHierarchy(java.lang.Class<?> ifc, java.util.LinkedList<java.lang.Class<?>> classQueue)
private GenericConverter matchConverter(GenericConversionService.MatchableConverters matchable, TypeDescriptor sourceFieldType, TypeDescriptor targetFieldType)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |