org.springframework.core.convert
Class TypeDescriptor

java.lang.Object
  extended by org.springframework.core.convert.TypeDescriptor

public class TypeDescriptor
extends java.lang.Object

Type metadata about a bindable target value.

Author:
Keith Donald, Andy Clement

Field Summary
static TypeDescriptor NULL_TYPE_DESCRIPTOR
          Constant value typeDescriptor for the type of a null value
 
Constructor Summary
TypeDescriptor(java.lang.Class<?> type)
          Creates a new descriptor for the given type.
TypeDescriptor(java.lang.reflect.Field field)
          Create a new descriptor for a field.
TypeDescriptor(MethodParameter methodParameter)
          Create a new descriptor for a method or constructor parameter.
 
Method Summary
 java.lang.String asString()
           
static TypeDescriptor forObject(java.lang.Object object)
          Creates a new type descriptor for the class of the given object.
 java.lang.annotation.Annotation[] getAnnotations()
          Obtain the annotations associated with the wrapped parameter/field, if any.
 java.lang.Class<?> getElementType()
          If this type is an array type or Collection type, returns the underlying element type.
 java.lang.reflect.Field getField()
          Return the wrapped Field, if any.
 java.lang.Class<?> getMapKeyType()
          Determine the generic key type of the wrapped Map parameter/field, if any.
 java.lang.Class<?> getMapValueType()
          Determine the generic value type of the wrapped Map parameter/field, if any.
 MethodParameter getMethodParameter()
          Return the wrapped MethodParameter, if any.
 java.lang.String getName()
          Returns the name of this type; the fully qualified classname.
 java.lang.Class<?> getType()
          Determine the declared (non-generic) type of the wrapped parameter/field.
 boolean isAbstractClass()
          Returns true if this type is an abstract class.
 boolean isArray()
          Is this type an array type?
 boolean isAssignableTo(TypeDescriptor targetType)
          Returns true if an object this type can be assigned to a rereference of given targetType.
 boolean isCollection()
          Is this type a Collection type?
 boolean isInstance(java.lang.Object obj)
          Is the obj an instance of this type?
 boolean isMap()
          Is this type a Map type?
 boolean isMapEntryTypeKnown()
          Is this descriptor for a map where the key type and value type are known?
static TypeDescriptor valueOf(java.lang.Class<? extends java.lang.Object> type)
          Creates a new type descriptor for the given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_TYPE_DESCRIPTOR

public static final TypeDescriptor NULL_TYPE_DESCRIPTOR
Constant value typeDescriptor for the type of a null value

Constructor Detail

TypeDescriptor

public TypeDescriptor(java.lang.Class<?> type)
Creates a new descriptor for the given type. Use this constructor when a bound value comes from a source such as a Map or collection, where no additional binding metadata is available.

Parameters:
type - the actual type

TypeDescriptor

public TypeDescriptor(MethodParameter methodParameter)
Create a new descriptor for a method or constructor parameter. Use this constructor when a bound value originates from a method parameter, such as a setter method argument.

Parameters:
methodParameter - the MethodParameter to wrap

TypeDescriptor

public TypeDescriptor(java.lang.reflect.Field field)
Create a new descriptor for a field. Use this constructor when a bound value originates from a field.

Parameters:
field - the field to wrap
Method Detail

getType

public java.lang.Class<?> getType()
Determine the declared (non-generic) type of the wrapped parameter/field.

Returns:
the declared type (never null)

getName

public java.lang.String getName()
Returns the name of this type; the fully qualified classname.


isArray

public boolean isArray()
Is this type an array type?


isCollection

public boolean isCollection()
Is this type a Collection type?


getElementType

public java.lang.Class<?> getElementType()
If this type is an array type or Collection type, returns the underlying element type. Returns null if the type is neither an array or collection.


isMap

public boolean isMap()
Is this type a Map type?


isMapEntryTypeKnown

public boolean isMapEntryTypeKnown()
Is this descriptor for a map where the key type and value type are known?


getMapKeyType

public java.lang.Class<?> getMapKeyType()
Determine the generic key type of the wrapped Map parameter/field, if any.

Returns:
the generic type, or null if none

getMapValueType

public java.lang.Class<?> getMapValueType()
Determine the generic value type of the wrapped Map parameter/field, if any.

Returns:
the generic type, or null if none

getAnnotations

public java.lang.annotation.Annotation[] getAnnotations()
Obtain the annotations associated with the wrapped parameter/field, if any.


getMethodParameter

public MethodParameter getMethodParameter()
Return the wrapped MethodParameter, if any.

Note: Either MethodParameter or Field is available.

Returns:
the MethodParameter, or null if none

getField

public java.lang.reflect.Field getField()
Return the wrapped Field, if any.

Note: Either MethodParameter or Field is available.

Returns:
the Field, or null if none

isAbstractClass

public boolean isAbstractClass()
Returns true if this type is an abstract class.


isInstance

public boolean isInstance(java.lang.Object obj)
Is the obj an instance of this type?


isAssignableTo

public boolean isAssignableTo(TypeDescriptor targetType)
Returns true if an object this type can be assigned to a rereference of given targetType.

Parameters:
targetType - the target type
Returns:
true if this type is assignable to the target

valueOf

public static TypeDescriptor valueOf(java.lang.Class<? extends java.lang.Object> type)
Creates a new type descriptor for the given class.

Parameters:
type - the class
Returns:
the type descriptor

forObject

public static TypeDescriptor forObject(java.lang.Object object)
Creates a new type descriptor for the class of the given object.

Parameters:
object - the object
Returns:
the type descriptor

asString

public java.lang.String asString()
Returns:
a textual representation of the type descriptor (eg. Map) for use in messages