org.springframework.ui.format
Interface FormatterRegistry

All Known Implementing Classes:
GenericFormatterRegistry

public interface FormatterRegistry

A shared registry of Formatters.

Since:
3.0
Author:
Keith Donald

Method Summary
<A extends Annotation,T>
void
addFormatterByAnnotation(AnnotationFormatterFactory<A,T> factory)
          Adds a AnnotationFormatterFactory that returns the Formatter for properties annotated with a specific annotation.
 void addFormatterByAnnotation(Class<? extends Annotation> annotationType, Formatter<?> formatter)
          Adds a Formatter to this registry indexed by the given annotation type.
 void addFormatterByType(Class<?> type, Formatter<?> targetFormatter)
          Adds a Formatter to this registry indexed by type.
<T> void
addFormatterByType(Formatter<T> formatter)
          Adds a Formatter to this registry indexed by <T>.
<T> Formatter<T>
getFormatter(Class<T> targetType)
          Get the Formatter for the specified type.
 Formatter<Object> getFormatter(TypeDescriptor type)
          Get the Formatter for the type descriptor.
 

Method Detail

addFormatterByType

void addFormatterByType(Class<?> type,
                        Formatter<?> targetFormatter)
Adds a Formatter to this registry indexed by type.

Use this add method when type differs from <T>. Calling getFormatter(type) returns a decorator that wraps the targetFormatter instance.

On format, the decorator first coerses the instance of type to <T>, then delegates to targetFormatter to format the value.

On parse, the decorator first delegates to the formatter to parse a <T>, then coerces the parsed value to type.

Parameters:
type - the object type
targetFormatter - the target formatter

addFormatterByType

<T> void addFormatterByType(Formatter<T> formatter)
Adds a Formatter to this registry indexed by <T>. Calling getFormatter(<T>.class) returns formatter.

Type Parameters:
T - the type of object the formatter formats
Parameters:
formatter - the formatter

addFormatterByAnnotation

void addFormatterByAnnotation(Class<? extends Annotation> annotationType,
                              Formatter<?> formatter)
Adds a Formatter to this registry indexed by the given annotation type. Calling getFormatter(...) on a field or accessor method with the given annotation returns formatter.

Type Parameters:
T - the type of object the formatter formats
Parameters:
formatter - the formatter

addFormatterByAnnotation

<A extends Annotation,T> void addFormatterByAnnotation(AnnotationFormatterFactory<A,T> factory)
Adds a AnnotationFormatterFactory that returns the Formatter for properties annotated with a specific annotation. Calling getFormatter(...) on a field or accessor method with the given annotation returns formatter.

Type Parameters:
A - the type of Annotation this factory uses to create Formatter instances
T - the type of object that the factory's Formatters are dealing with
Parameters:
factory - the annotation formatter factory

getFormatter

<T> Formatter<T> getFormatter(Class<T> targetType)
Get the Formatter for the specified type.

Returns:
the Formatter, or null if no suitable one is registered

getFormatter

Formatter<Object> getFormatter(TypeDescriptor type)
Get the Formatter for the type descriptor.

Returns:
the Formatter, or null if no suitable one is registered