Polishing
This commit is contained in:
@@ -32,13 +32,13 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see #createDateTimeFormatter()
|
||||
* @see #createDateTimeFormatter(DateTimeFormatter)
|
||||
* @see #setPattern(String)
|
||||
* @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO)
|
||||
* @see #setStyle(String)
|
||||
* @see DateTimeFormatterFactoryBean
|
||||
* @since 3.2
|
||||
*/
|
||||
public class DateTimeFormatterFactory {
|
||||
|
||||
@@ -72,7 +72,6 @@ public class DateTimeFormatterFactory {
|
||||
* {@link #setPattern(String) pattern} have been defined the
|
||||
* {@link DateTimeFormat#mediumDateTime() medium date time format} will be used.
|
||||
* @return a new date time formatter
|
||||
* @see #getObject()
|
||||
* @see #createDateTimeFormatter(DateTimeFormatter)
|
||||
*/
|
||||
public DateTimeFormatter createDateTimeFormatter() {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.format.datetime.joda;
|
||||
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
@@ -26,23 +27,23 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see #setPattern(String)
|
||||
* @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO)
|
||||
* @see #setStyle(String)
|
||||
* @see DateTimeFormatterFactory
|
||||
* @since 3.2
|
||||
*/
|
||||
public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory implements
|
||||
FactoryBean<DateTimeFormatter>, InitializingBean {
|
||||
public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory
|
||||
implements FactoryBean<DateTimeFormatter>, InitializingBean {
|
||||
|
||||
private DateTimeFormatter dateTimeFormatter;
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
this.dateTimeFormatter = createDateTimeFormatter();
|
||||
}
|
||||
|
||||
public DateTimeFormatter getObject() throws Exception {
|
||||
public DateTimeFormatter getObject() {
|
||||
return this.dateTimeFormatter;
|
||||
}
|
||||
|
||||
@@ -53,4 +54,5 @@ public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory imple
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
||||
/**
|
||||
* Formats fields annotated with the {@link DateTimeFormat} annotation using Joda time.
|
||||
* Formats fields annotated with the {@link DateTimeFormat} annotation using Joda-Time.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
@@ -85,20 +85,16 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
||||
|
||||
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
|
||||
DateTimeFormatter formatter = getFormatter(annotation, fieldType);
|
||||
|
||||
if (ReadableInstant.class.isAssignableFrom(fieldType)) {
|
||||
return new ReadableInstantPrinter(formatter);
|
||||
}
|
||||
|
||||
if (ReadablePartial.class.isAssignableFrom(fieldType)) {
|
||||
return new ReadablePartialPrinter(formatter);
|
||||
}
|
||||
|
||||
if (Calendar.class.isAssignableFrom(fieldType)) {
|
||||
// assumes Calendar->ReadableInstant converter is registered
|
||||
return new ReadableInstantPrinter(formatter);
|
||||
}
|
||||
|
||||
// assumes Date->Long converter is registered
|
||||
return new MillisecondInstantPrinter(formatter);
|
||||
}
|
||||
@@ -121,4 +117,5 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
||||
factory.setPattern(resolveEmbeddedValue(annotation.pattern()));
|
||||
return factory.createDateTimeFormatter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user