|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.core.convert.support.GenericConversionService
public class GenericConversionService
Base ConversionService implementation suitable for use in most environments.
Implements ConverterRegistry as registration API.
| 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. |
|
boolean |
canConvert(Class<?> sourceType,
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(Object source,
Class<T> targetType)
Convert the source to targetType. |
|
Object |
convert(Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert the source to targetType. |
|
protected Object |
convertNullSource(TypeDescriptor sourceType,
TypeDescriptor targetType)
Template method to convert a null source. |
|
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. |
|
void |
removeConvertible(Class<?> sourceType,
Class<?> targetType)
Remove any converters from sourceType to targetType. |
|
String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GenericConversionService()
| Method Detail |
|---|
public void addConverter(Converter<?,?> converter)
ConverterRegistry
addConverter in interface ConverterRegistrypublic void addConverterFactory(ConverterFactory<?,?> converterFactory)
ConverterRegistry
addConverterFactory in interface ConverterRegistrypublic void addConverter(GenericConverter converter)
ConverterRegistry
addConverter in interface ConverterRegistry
public void removeConvertible(Class<?> sourceType,
Class<?> targetType)
ConverterRegistry
removeConvertible in interface ConverterRegistrysourceType - the source typetargetType - the target type
public boolean canConvert(Class<?> sourceType,
Class<?> targetType)
ConversionService
canConvert in interface ConversionServicesourceType - the source type to convert from (required)targetType - the target type to convert to (required)
public <T> T convert(Object source,
Class<T> targetType)
ConversionService
convert in interface ConversionServicesource - 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 ConversionServicesourceType - context about the source type to convert from (required)targetType - context about the target type to convert to (required)
public Object convert(Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
ConversionService
convert in interface ConversionServicesource - 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)
targetTypepublic String toString()
toString in class Object
protected 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
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||