01: package org.vraptor.converter.joda;
02:
03: import org.joda.time.TimeOfDay;
04: import org.vraptor.LogicRequest;
05: import org.vraptor.converter.ConversionException;
06: import org.vraptor.converter.Converter;
07: import org.vraptor.converter.LocaleCalendarTimeConverter;
08:
09: import java.util.Calendar;
10:
11: /**
12: * <p>
13: * Locale based joda-time {@link TimeOfDay} converter. Uses the error key
14: * invalid_time if unable to parse its information.
15: * </p>
16: * <p>
17: * Same semantics as {@link LocaleCalendarTimeConverter}.
18: * </p>
19: *
20: * @author Fabio Kung
21: */
22: @Deprecated
23: public class TimeOfDayConverter implements Converter {
24: private Converter internal = new LocaleCalendarTimeConverter();
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: try {
35: return TimeOfDay.fromCalendarFields(converted);
36: } catch (Exception e) {
37: throw new ConversionException("invalid_time",
38: "Unable to parse string " + value, e);
39: }
40: }
41:
42: public Class<?>[] getSupportedTypes() {
43: return new Class<?>[] { TimeOfDay.class };
44: }
45: }
|