01: package org.geotools.xml.impl.jxpath;
02:
03: import java.util.HashSet;
04:
05: import org.apache.commons.jxpath.DynamicPropertyHandler;
06: import org.geotools.feature.Feature;
07: import org.geotools.feature.FeatureType;
08: import org.geotools.feature.IllegalAttributeException;
09:
10: /**
11: * JXPath property handler for features.
12: * <p>
13: *
14: * </p>
15: * @author Justin Deoliveira, The Open Planning Project
16: *
17: */
18: public class FeaturePropertyHandler implements DynamicPropertyHandler {
19:
20: public String[] getPropertyNames(Object object) {
21: Feature feature = (Feature) object;
22: FeatureType featureType = feature.getFeatureType();
23:
24: //set is ok because jxpath ignores order
25: String[] propertyNames = new String[featureType
26: .getAttributeCount()];
27: for (int i = 0; i < propertyNames.length; i++) {
28: propertyNames[i] = featureType.getAttributeType(i)
29: .getName();
30: }
31:
32: return propertyNames;
33: }
34:
35: public Object getProperty(Object object, String property) {
36: Feature feature = (Feature) object;
37: Object value = feature.getAttribute(property(property));
38: if (value != null) {
39: return value;
40: }
41:
42: //check additional properties
43: if ("fid".equals(property) || property.matches("(\\w+:)?id")) {
44: return feature.getID();
45: }
46:
47: return null;
48: }
49:
50: public void setProperty(Object object, String property, Object value) {
51: Feature feature = (Feature) object;
52: try {
53: feature.setAttribute(property(property), value);
54: } catch (IllegalAttributeException e) {
55: throw new RuntimeException(e);
56: }
57: }
58:
59: String property(String property) {
60: //strip of namesapce prefix
61: int i = property.indexOf(":");
62: if (i != -1) {
63: property = property.substring(i + 1);
64: }
65:
66: return property;
67: }
68:
69: }
|