01: package org.vraptor.converter.basic;
02:
03: import org.vraptor.LogicRequest;
04: import org.vraptor.converter.ConversionException;
05: import org.vraptor.converter.Converter;
06:
07: /**
08: * Simple long converter.
09: * Uses the error key invalid_time if unable to parse its information.
10: *
11: * @author Guilherme Silveira
12: */
13: public class SimpleLongConverter implements Converter {
14:
15: public Object convert(String value, Class<?> type,
16: LogicRequest context) throws ConversionException {
17: if (value == null || value.equals("")) {
18: return null;
19: }
20: try {
21: return Long.valueOf(value);
22: } catch (NumberFormatException e) {
23: throw new ConversionException("invalid_number", e
24: .getMessage(), e);
25: }
26:
27: }
28:
29: /**
30: * Returns the list of supported types
31: *
32: * @see org.vraptor.converter.Converter#getSupportedTypes()
33: */
34: public Class<?>[] getSupportedTypes() {
35: return new Class[] { Long.class };
36: }
37:
38: }
|