org.springframework.format.datetime.joda
Class JodaDateTimeFormatAnnotationFormatterFactory

java.lang.Object
  extended by org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory
All Implemented Interfaces:
Aware, EmbeddedValueResolverAware, AnnotationFormatterFactory<DateTimeFormat>

public class JodaDateTimeFormatAnnotationFormatterFactory
extends java.lang.Object
implements AnnotationFormatterFactory<DateTimeFormat>, EmbeddedValueResolverAware

Formats fields annotated with the DateTimeFormat annotation.

Since:
3.0
Author:
Keith Donald, Juergen Hoeller
See Also:
DateTimeFormat

Field Summary
private  StringValueResolver embeddedValueResolver
           
private  java.util.Set<java.lang.Class<?>> fieldTypes
           
 
Constructor Summary
JodaDateTimeFormatAnnotationFormatterFactory()
           
 
Method Summary
private  DateTimeFormatter configureDateTimeFormatterFrom(DateTimeFormat annotation)
           
private  java.util.Set<java.lang.Class<?>> createFieldTypes()
          Create the set of field types that may be annotated with @DateTimeFormat.
private  DateTimeFormatter forIso(DateTimeFormat.ISO iso)
           
private  DateTimeFormatter forPattern(java.lang.String pattern)
           
private  DateTimeFormatter forStyle(java.lang.String style)
           
 java.util.Set<java.lang.Class<?>> getFieldTypes()
          The types of fields that may be annotated with the <A> annotation.
 Parser<DateTime> getParser(DateTimeFormat annotation, java.lang.Class<?> fieldType)
          Get the Parser to parse a submitted value for a field of fieldType annotated with annotation.
 Printer<?> getPrinter(DateTimeFormat annotation, java.lang.Class<?> fieldType)
          Get the Printer to print the value of a field of fieldType annotated with annotation.
protected  java.lang.String resolveEmbeddedValue(java.lang.String value)
           
 void setEmbeddedValueResolver(StringValueResolver resolver)
          Set the StringValueResolver to use for resolving embedded definition values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldTypes

private final java.util.Set<java.lang.Class<?>> fieldTypes

embeddedValueResolver

private StringValueResolver embeddedValueResolver
Constructor Detail

JodaDateTimeFormatAnnotationFormatterFactory

public JodaDateTimeFormatAnnotationFormatterFactory()
Method Detail

getFieldTypes

public final java.util.Set<java.lang.Class<?>> getFieldTypes()
Description copied from interface: AnnotationFormatterFactory
The types of fields that may be annotated with the <A> annotation.

Specified by:
getFieldTypes in interface AnnotationFormatterFactory<DateTimeFormat>

setEmbeddedValueResolver

public void setEmbeddedValueResolver(StringValueResolver resolver)
Description copied from interface: EmbeddedValueResolverAware
Set the StringValueResolver to use for resolving embedded definition values.

Specified by:
setEmbeddedValueResolver in interface EmbeddedValueResolverAware

resolveEmbeddedValue

protected java.lang.String resolveEmbeddedValue(java.lang.String value)

getPrinter

public Printer<?> getPrinter(DateTimeFormat annotation,
                             java.lang.Class<?> fieldType)
Description copied from interface: AnnotationFormatterFactory
Get the Printer to print the value of a field of fieldType annotated with annotation. If the type <T> the printer accepts is not assignable to fieldType, a coersion from fieldType to <T> will be attempted before the Printer is invoked.

Specified by:
getPrinter in interface AnnotationFormatterFactory<DateTimeFormat>
Parameters:
annotation - the annotation instance
fieldType - the type of field that was annotated
Returns:
the printer

getParser

public Parser<DateTime> getParser(DateTimeFormat annotation,
                                  java.lang.Class<?> fieldType)
Description copied from interface: AnnotationFormatterFactory
Get the Parser to parse a submitted value for a field of fieldType annotated with annotation. If the object the parser returns is not assignable to fieldType, a coersion to fieldType will be attempted before the field is set.

Specified by:
getParser in interface AnnotationFormatterFactory<DateTimeFormat>
Parameters:
annotation - the annotation instance
fieldType - the type of field that was annotated
Returns:
the parser

createFieldTypes

private java.util.Set<java.lang.Class<?>> createFieldTypes()
Create the set of field types that may be annotated with @DateTimeFormat. Note: the 3 ReadablePartial concrete types are registered explicitly since addFormatterForFieldType rules exist for each of these types (if we did not do this, the default byType rules for LocalDate, LocalTime, and LocalDateTime would take precedence over the annotation rule, which is not what we want)

See Also:
JodaTimeFormatterRegistrar.registerFormatters(org.springframework.format.FormatterRegistry)

configureDateTimeFormatterFrom

private DateTimeFormatter configureDateTimeFormatterFrom(DateTimeFormat annotation)

forPattern

private DateTimeFormatter forPattern(java.lang.String pattern)

forStyle

private DateTimeFormatter forStyle(java.lang.String style)

forIso

private DateTimeFormatter forIso(DateTimeFormat.ISO iso)