master
Juergen Hoeller 12 years ago
parent 786a20f9d0
commit 0614d312ed
  1. 3
      spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java
  2. 12
      spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryBean.java
  3. 7
      spring-context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java

@ -32,13 +32,13 @@ import org.springframework.util.StringUtils;
* *
* @author Phillip Webb * @author Phillip Webb
* @author Sam Brannen * @author Sam Brannen
* @since 3.2
* @see #createDateTimeFormatter() * @see #createDateTimeFormatter()
* @see #createDateTimeFormatter(DateTimeFormatter) * @see #createDateTimeFormatter(DateTimeFormatter)
* @see #setPattern(String) * @see #setPattern(String)
* @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO) * @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO)
* @see #setStyle(String) * @see #setStyle(String)
* @see DateTimeFormatterFactoryBean * @see DateTimeFormatterFactoryBean
* @since 3.2
*/ */
public class DateTimeFormatterFactory { public class DateTimeFormatterFactory {
@ -72,7 +72,6 @@ public class DateTimeFormatterFactory {
* {@link #setPattern(String) pattern} have been defined the * {@link #setPattern(String) pattern} have been defined the
* {@link DateTimeFormat#mediumDateTime() medium date time format} will be used. * {@link DateTimeFormat#mediumDateTime() medium date time format} will be used.
* @return a new date time formatter * @return a new date time formatter
* @see #getObject()
* @see #createDateTimeFormatter(DateTimeFormatter) * @see #createDateTimeFormatter(DateTimeFormatter)
*/ */
public DateTimeFormatter createDateTimeFormatter() { public DateTimeFormatter createDateTimeFormatter() {

@ -17,6 +17,7 @@
package org.springframework.format.datetime.joda; package org.springframework.format.datetime.joda;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@ -26,23 +27,23 @@ import org.springframework.beans.factory.InitializingBean;
* *
* @author Phillip Webb * @author Phillip Webb
* @author Sam Brannen * @author Sam Brannen
* @since 3.2
* @see #setPattern(String) * @see #setPattern(String)
* @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO) * @see #setIso(org.springframework.format.annotation.DateTimeFormat.ISO)
* @see #setStyle(String) * @see #setStyle(String)
* @see DateTimeFormatterFactory * @see DateTimeFormatterFactory
* @since 3.2
*/ */
public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory implements public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory
FactoryBean<DateTimeFormatter>, InitializingBean { implements FactoryBean<DateTimeFormatter>, InitializingBean {
private DateTimeFormatter dateTimeFormatter; private DateTimeFormatter dateTimeFormatter;
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
this.dateTimeFormatter = createDateTimeFormatter(); this.dateTimeFormatter = createDateTimeFormatter();
} }
public DateTimeFormatter getObject() throws Exception { public DateTimeFormatter getObject() {
return this.dateTimeFormatter; return this.dateTimeFormatter;
} }
@ -53,4 +54,5 @@ public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory imple
public boolean isSingleton() { public boolean isSingleton() {
return true; return true;
} }
} }

@ -38,7 +38,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringValueResolver; 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 Keith Donald
* @author Juergen Hoeller * @author Juergen Hoeller
@ -85,20 +85,16 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) { public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatter formatter = getFormatter(annotation, fieldType); DateTimeFormatter formatter = getFormatter(annotation, fieldType);
if (ReadableInstant.class.isAssignableFrom(fieldType)) { if (ReadableInstant.class.isAssignableFrom(fieldType)) {
return new ReadableInstantPrinter(formatter); return new ReadableInstantPrinter(formatter);
} }
if (ReadablePartial.class.isAssignableFrom(fieldType)) { if (ReadablePartial.class.isAssignableFrom(fieldType)) {
return new ReadablePartialPrinter(formatter); return new ReadablePartialPrinter(formatter);
} }
if (Calendar.class.isAssignableFrom(fieldType)) { if (Calendar.class.isAssignableFrom(fieldType)) {
// assumes Calendar->ReadableInstant converter is registered // assumes Calendar->ReadableInstant converter is registered
return new ReadableInstantPrinter(formatter); return new ReadableInstantPrinter(formatter);
} }
// assumes Date->Long converter is registered // assumes Date->Long converter is registered
return new MillisecondInstantPrinter(formatter); return new MillisecondInstantPrinter(formatter);
} }
@ -121,4 +117,5 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
factory.setPattern(resolveEmbeddedValue(annotation.pattern())); factory.setPattern(resolveEmbeddedValue(annotation.pattern()));
return factory.createDateTimeFormatter(); return factory.createDateTimeFormatter();
} }
} }

Loading…
Cancel
Save