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: * <p>
09: * Simple Boolean (wrapper class) converter. For primitive boolean see
10: * {@link PrimitiveBooleanConverter}.
11: * </p>
12: * <p>
13: * Uses the error key invalid_boolean if unable to parse its information.
14: * </p>
15: *
16: * @author Guilherme Silveira
17: * @author Fabio Kung
18: *
19: * @see PrimitiveBooleanConverter
20: */
21: public class SimpleBooleanConverter implements Converter {
22:
23: /**
24: *
25: * @see org.vraptor.converter.Converter#convert(java.lang.String,
26: * java.lang.Class, org.vraptor.scope.LogicRequest)
27: */
28: public Object convert(String value, Class<?> type,
29: LogicRequest context) throws ConversionException {
30: if (value == null || value.equals("")) {
31: return null;
32: }
33: return Boolean.valueOf(value);
34: }
35:
36: /**
37: * Returns the list of supported types
38: *
39: * @see org.vraptor.converter.Converter#getSupportedTypes()
40: */
41: public Class<?>[] getSupportedTypes() {
42: return new Class[] { Boolean.class };
43: }
44:
45: }
|