01: package org.vraptor.converter.joda;
02:
03: import org.joda.time.YearMonthDay;
04: import org.vraptor.LogicRequest;
05: import org.vraptor.converter.ConversionException;
06: import org.vraptor.converter.Converter;
07: import org.vraptor.converter.basic.LocaleCalendarDateConverter;
08:
09: import java.util.Calendar;
10:
11: /**
12: * <p>
13: * Locale based joda-time {@link YearMonthDay} converter. Uses the error key
14: * invalid_date if unable to parse its information.
15: * </p>
16: * <p>
17: * Same semantics as {@link LocaleCalendarDateConverter}.
18: * </p>
19: *
20: * @author Fabio Kung
21: */
22: @Deprecated
23: public class YearMonthDayConverter implements Converter {
24: private Converter internal = new LocaleCalendarDateConverter();
25:
26: public Object convert(String value, Class<?> type,
27: LogicRequest context) throws ConversionException {
28: if (value == null || value.equals("")) {
29: return null;
30: }
31:
32: Calendar converted = (Calendar) internal.convert(value,
33: Calendar.class, context);
34: YearMonthDay date;
35: try {
36: date = YearMonthDay.fromCalendarFields(converted);
37: } catch (Exception e) {
38: throw new ConversionException("invalid_date",
39: "Unable to parse string " + value, e);
40: }
41: return date;
42: }
43:
44: public Class<?>[] getSupportedTypes() {
45: return new Class<?>[] { YearMonthDay.class };
46: }
47: }
|