01: /**
02: *
03: */package org.geotools.feature.iso.xpath;
04:
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: import org.apache.commons.jxpath.DynamicPropertyHandler;
09: import org.geotools.feature.iso.Types;
10: import org.opengis.feature.type.AttributeDescriptor;
11: import org.opengis.feature.type.AttributeType;
12: import org.opengis.feature.type.ComplexType;
13:
14: /**
15: * JXPath property handler that works on AttributeDescriptor/type
16: *
17: * @author Gabriel Roldan
18: */
19: public class AttributeDescriptorPropertyHandler implements
20: DynamicPropertyHandler {
21:
22: public String[] getPropertyNames(java.lang.Object o) {
23: AttributeType att = (AttributeType) o;
24: String[] propNames = null;
25: if (att instanceof ComplexType) {
26: ComplexType complexType = (ComplexType) att;
27: List/*<AttributeDescriptor>*/childTypes = new ArrayList(
28: complexType.attributes());
29: propNames = new String[childTypes.size()];
30: for (int i = 0; i < propNames.length; i++) {
31: propNames[i] = ((AttributeDescriptor) childTypes.get(i))
32: .getName().getLocalPart();
33: }
34: }
35: return propNames;
36: }
37:
38: /**
39: * Returns the {@linkplain AttributeDescriptor} contained by the
40: * {@linkplain org.geotools.feature.iso.impl.ComplexAttributeImpl}
41: * <code>o</code>.
42: */
43: public Object getProperty(Object o, String propName) {
44: AttributeDescriptor value = null;
45: AttributeDescriptor node = (AttributeDescriptor) o;
46: if (node.getName().getLocalPart().equals(propName)) {
47: return node;
48: }
49: if (!(node.type() instanceof ComplexType)) {
50: throw new IllegalArgumentException(
51: "can't ask for property " + propName
52: + " of a non complex type: " + node.type());
53: }
54: ComplexType complex = (ComplexType) node.type();
55: value = (AttributeDescriptor) Types.descriptor(complex,
56: propName);
57: //value = Descriptors.node(complex, propName);
58: return value;
59: }
60:
61: public void setProperty(Object feature, String propertyName,
62: Object value) {
63: throw new UnsupportedOperationException("not yet implemented");
64: /*
65: * try { ((Feature) feature).setAttribute(propertyName, value); } catch
66: * (IllegalAttributeException e) { throw new JXPathException("Setting
67: * attribute " + propertyName + ": " + e.getMessage(), e); }
68: */
69: }
70: }
|