public class GenericConversionService extends Object implements ConversionService
| Constructor and Description |
|---|
GenericConversionService() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAlias(String alias,
Class targetType)
Add an alias for given target type.
|
void |
addConverter(Converter converter)
Add given converter to this conversion service.
|
void |
addConverter(String id,
Converter converter)
Add given custom converter to this conversion service.
|
Object |
executeConversion(Object source,
Class targetClass)
Execute a conversion of the source object provided to the specified
targetClass |
Object |
executeConversion(String converterId,
Object source,
Class targetClass)
Execute a conversion using the custom converter with the provided id.
|
Class |
getClassForAlias(String name)
Lookup a class by its well-known alias.
|
ConversionExecutor |
getConversionExecutor(Class sourceClass,
Class targetClass)
Return the default conversion executor capable of converting source objects of the specified
sourceClass to instances of the targetClass. |
ConversionExecutor |
getConversionExecutor(String id,
Class sourceClass,
Class targetClass)
Return the custom conversion executor capable of converting source objects of the specified
sourceClass to instances of the targetClass. |
Set |
getConversionExecutors(Class sourceClass)
Return all conversion executors capable of converting from the provided
sourceClass. |
ConversionService |
getParent()
Returns the parent of this conversion service.
|
void |
setParent(ConversionService parent)
Set the parent of this conversion service.
|
public ConversionService getParent()
public void setParent(ConversionService parent)
public void addConverter(Converter converter)
converter - the converterpublic void addConverter(String id, Converter converter)
id - the id of the custom converter instanceconverter - the converterpublic ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass) throws ConversionExecutorNotFoundException
ConversionServicesourceClass to instances of the targetClass.
The returned ConversionExecutor is thread-safe and may safely be cached for use in client code.
getConversionExecutor in interface ConversionServicesourceClass - the source class to convert from (required)targetClass - the target class to convert to (required)ConversionExecutorNotFoundException - when no suitable conversion executor could be foundpublic ConversionExecutor getConversionExecutor(String id, Class sourceClass, Class targetClass) throws ConversionExecutorNotFoundException
ConversionServicesourceClass to instances of the targetClass.
The returned ConversionExecutor is thread-safe and may safely be cached for use in client code.
getConversionExecutor in interface ConversionServiceid - the id of the custom conversion executor (required)sourceClass - the source class to convert from (required)targetClass - the target class to convert to (required)ConversionExecutorNotFoundException - when no suitable conversion executor could be foundpublic Object executeConversion(Object source, Class targetClass) throws ConversionException
ConversionServicetargetClassexecuteConversion in interface ConversionServicesource - the source to convert from (may be null)targetClass - the target class to convert totargetClassConversionException - if an exception occurred during the conversion processpublic Object executeConversion(String converterId, Object source, Class targetClass) throws ConversionException
ConversionServiceexecuteConversion in interface ConversionServiceconverterId - the id of the custom converter, which must be registered with this conversion service and
capable of converting to the target classsource - the source to convert from (may be null)targetClass - the target class to convert totargetClassConversionException - if an exception occurred during the conversion processpublic Class getClassForAlias(String name) throws IllegalArgumentException
ConversionServicelong for java.lang.LonggetClassForAlias in interface ConversionServicename - the class aliasnull if no alias existsIllegalArgumentExceptionpublic Set getConversionExecutors(Class sourceClass)
ConversionServicesourceClass. For
example, getConversionExecutor(String.class) would return all converters that convert from String to
some other Object. Mainly useful for adapting a set of converters to some other environment.getConversionExecutors in interface ConversionServicesourceClass - the source class converting from