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: * Primitive float converter. Uses the error key invalid_number if unable to
09: * parse its information.
10: *
11: * @author Guilherme Silveira
12: */
13: public class PrimitiveFloatConverter implements Converter {
14:
15: public Object convert(String value, Class<?> type,
16: LogicRequest context) throws ConversionException {
17: try {
18: return Float.parseFloat(value);
19: } catch (NumberFormatException e) {
20: throw new ConversionException("invalid_number", e
21: .getMessage(), e);
22: }
23: }
24:
25: /**
26: * Returns the list of supported types
27: *
28: * @see org.vraptor.converter.Converter#getSupportedTypes()
29: */
30: public Class<?>[] getSupportedTypes() {
31: return new Class[] { float.class };
32: }
33:
34: }
|