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 char converter.
09: * Uses the error key invalid_character if unable to parse its information.
10: *
11: * @author Guilherme Silveira
12: */
13: public class PrimitiveCharConverter implements Converter {
14:
15: public Object convert(String value, Class<?> type,
16: LogicRequest context) throws ConversionException {
17: if (value.length() != 1) {
18: throw new ConversionException("invalid_character",
19: "Content is more than a single character");
20: }
21: return value.charAt(0);
22: }
23:
24: /**
25: * Returns the list of supported types
26: *
27: * @see org.vraptor.converter.Converter#getSupportedTypes()
28: */
29: public Class<?>[] getSupportedTypes() {
30: return new Class[] { char.class };
31: }
32:
33: }
|