org.springframework.core.convert.support
Class IdToEntityConverter

java.lang.Object
  extended by org.springframework.core.convert.support.IdToEntityConverter
All Implemented Interfaces:
ConditionalGenericConverter, GenericConverter

final class IdToEntityConverter
extends java.lang.Object
implements ConditionalGenericConverter

Converts an entity identifier to a entity reference by calling a static finder method on the target entity type.

For this converter to match, the finder method must be public, static, have the signature find[EntityName]([IdType]), and return an instance of the desired entity type.

Since:
3.0
Author:
Keith Donald

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.springframework.core.convert.converter.GenericConverter
GenericConverter.ConvertiblePair
 
Field Summary
private  ConversionService conversionService
           
 
Constructor Summary
IdToEntityConverter(ConversionService conversionService)
           
 
Method Summary
 java.lang.Object convert(java.lang.Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
          Convert the source to the targetType described by the TypeDescriptor.
 java.util.Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
          Return the source and target types which this converter can convert between.
private  java.lang.String getEntityName(java.lang.Class<?> entityClass)
           
private  java.lang.reflect.Method getFinder(java.lang.Class<?> entityClass)
           
 boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType)
          Should the converter from sourceType to targetType currently under consideration be selected?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conversionService

private final ConversionService conversionService
Constructor Detail

IdToEntityConverter

public IdToEntityConverter(ConversionService conversionService)
Method Detail

getConvertibleTypes

public java.util.Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
Description copied from interface: GenericConverter
Return the source and target types which this converter can convert between.

Each entry is a convertible source-to-target type pair.

Specified by:
getConvertibleTypes in interface GenericConverter

matches

public boolean matches(TypeDescriptor sourceType,
                       TypeDescriptor targetType)
Description copied from interface: ConditionalGenericConverter
Should the converter from sourceType to targetType currently under consideration be selected?

Specified by:
matches in interface ConditionalGenericConverter
Parameters:
sourceType - the type descriptor of the field we are converting from
targetType - the type descriptor of the field we are converting to
Returns:
true if conversion should be performed, false otherwise

convert

public java.lang.Object convert(java.lang.Object source,
                                TypeDescriptor sourceType,
                                TypeDescriptor targetType)
Description copied from interface: GenericConverter
Convert the source to the targetType described by the TypeDescriptor.

Specified by:
convert in interface GenericConverter
Parameters:
source - the source object to convert (may be null)
sourceType - the type descriptor of the field we are converting from
targetType - the type descriptor of the field we are converting to
Returns:
the converted object

getFinder

private java.lang.reflect.Method getFinder(java.lang.Class<?> entityClass)

getEntityName

private java.lang.String getEntityName(java.lang.Class<?> entityClass)