01: /**
02: *
03: */package org.geotools.feature.iso.attribute;
04:
05: import org.geotools.feature.iso.AttributeImpl;
06: import org.opengis.feature.type.AttributeDescriptor;
07:
08: /**
09: * @author Gabriel Roldan
10: */
11: public class BooleanAttribute extends AttributeImpl implements
12: org.opengis.feature.simple.BooleanAttribute {
13:
14: public BooleanAttribute(Boolean content, AttributeDescriptor type) {
15: super (content, type, null);
16: }
17:
18: protected Object parse(Object value)
19: throws IllegalArgumentException {
20: Class type = getType().getBinding();
21:
22: // handle null values first
23: if (value == null) {
24: return value;
25: }
26:
27: // no parse needed here if types are compatable
28: if ((value.getClass() == type)
29: || type.isAssignableFrom(value.getClass())) {
30: return value;
31: }
32:
33: // if it is not 0 or 1, fails
34: if (value instanceof Number) {
35: Number num = (Number) value;
36: return Boolean.valueOf(DateUtil.parseBoolean(String
37: .valueOf(num.intValue())));
38: }
39:
40: if (value instanceof CharSequence) {
41: return Boolean.valueOf(DateUtil.parseBoolean(value
42: .toString()));
43: }
44:
45: // nothing else to do
46: throw new IllegalArgumentException("Cannot parse "
47: + value.getClass());
48: }
49:
50: public Boolean getBoolean() {
51: return (Boolean) getValue();
52: }
53:
54: public void setBoolean(Boolean newValue) {
55: setValue(newValue);
56: }
57:
58: }
|