|
Spring for Android | ||||||||
| 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.
Indirectly implements ConverterRegistry as registration API through the
ConfigurableConversionService interface.
| Constructor Summary | |
|---|---|
GenericConversionService()
|
|
| Method Summary | ||
|---|---|---|
void |
addConverter(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType,
Converter<?,?> converter)
Add a plain converter to this registry. |
|
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 |
canBypassConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
Returns true if conversion between the sourceType and targetType can be bypassed. |
|
boolean |
canConvert(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
Return true if objects of sourceType can be converted to the targetType. |
|
boolean |
canConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
Return true if objects of sourceType can be converted to the targetType. |
|
|
convert(java.lang.Object source,
java.lang.Class<T> targetType)
Convert the given source to the specified targetType. |
|
java.lang.Object |
convert(java.lang.Object source,
TypeDescriptor targetType)
Convenience operation for converting a source object to the specified targetType, where the targetType is a descriptor that provides additional conversion context. |
|
java.lang.Object |
convert(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert the given source to the specified targetType. |
|
protected java.lang.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(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 |
| Constructor Detail |
|---|
public GenericConversionService()
| Method Detail |
|---|
public void addConverter(Converter<?,?> converter)
ConverterRegistry
addConverter in interface ConverterRegistry
public void addConverter(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType,
Converter<?,?> converter)
ConverterRegistry
addConverter in interface ConverterRegistrypublic void addConverter(GenericConverter converter)
ConverterRegistry
addConverter in interface ConverterRegistrypublic void addConverterFactory(ConverterFactory<?,?> converterFactory)
ConverterRegistry
addConverterFactory in interface ConverterRegistry
public void removeConvertible(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
ConverterRegistry
removeConvertible in interface ConverterRegistrysourceType - the source typetargetType - the target type
public boolean canConvert(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType)
ConversionServicetrue if objects of sourceType can be converted to the targetType.
If this method returns true, it means ConversionService.convert(Object, Class) is capable
of converting an instance of sourceType to targetType.
Special note on collections, arrays, and maps types:
For conversion between collection, array, and map types, this method will return true
even though a convert invocation may still generate a ConversionException if the
underlying elements are not convertible. Callers are expected to handle this exceptional case
when working with collections and maps.
canConvert in interface ConversionServicesourceType - the source type to convert from (may be null if source is null)targetType - the target type to convert to (required)
true if a conversion can be performed, false if not
public boolean canConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
ConversionServicetrue if objects of sourceType can be converted to the targetType.
The TypeDescriptors provide additional context about the source and target locations
where conversion would occur, often object fields or property locations.
If this method returns true, it means ConversionService.convert(Object, TypeDescriptor, TypeDescriptor)
is capable of converting an instance of sourceType to targetType.
Special note on collections, arrays, and maps types:
For conversion between collection, array, and map types, this method will return true
even though a convert invocation may still generate a ConversionException if the
underlying elements are not convertible. Callers are expected to handle this exceptional case
when working with collections and maps.
canConvert in interface ConversionServicesourceType - context about the source type to convert from
(may be null if source is null)targetType - context about the target type to convert to (required)
true if a conversion can be performed between the source and target types,
false if not
public boolean canBypassConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
sourceType - context about the source type to convert from (may be null if source is null)targetType - context about the target type to convert to (required)
java.lang.IllegalArgumentException - if targetType is null
public <T> T convert(java.lang.Object source,
java.lang.Class<T> targetType)
ConversionServicesource to the specified targetType.
convert in interface ConversionServicesource - the source object to convert (may be null)targetType - the target type to convert to (required)
public java.lang.Object convert(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
ConversionServicesource to the specified targetType.
The TypeDescriptors provide additional context about the source and target locations
where conversion will occur, often object fields or property locations.
convert in interface ConversionServicesource - the source object to convert (may be null)sourceType - context about the source type to convert from
(may be null if source is null)targetType - context about the target type to convert to (required)
targetType
public java.lang.Object convert(java.lang.Object source,
TypeDescriptor targetType)
convert(Object, TypeDescriptor, TypeDescriptor) and
encapsulates the construction of the sourceType descriptor using
TypeDescriptor.forObject(Object).
source - the source objecttargetType - the target type
ConversionException - if a conversion exception occurred
java.lang.IllegalArgumentException - if targetType is null,
or sourceType is null but source is not nullpublic java.lang.String toString()
toString in class java.lang.Object
protected java.lang.Object convertNullSource(TypeDescriptor sourceType,
TypeDescriptor targetType)
Default implementation returns null.
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)
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
|
Spring for Android | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||