001: package org.geotools.xml.impl.jxpath;
002:
003: import org.apache.commons.jxpath.ri.QName;
004: import org.apache.commons.jxpath.ri.model.NodePointer;
005: import org.geotools.feature.Feature;
006:
007: /**
008: * Pointer to a single property of a feature.
009: * <p>
010: * THe property of the feature is specified via index. Setting the index to
011: * -1 will cause the pointer to point at the feature id.
012: * </p>
013: * @author Justin Deoliveira, The Open Planning Project
014: *
015: */
016: public class FeaturePropertyPointer extends NodePointer {
017:
018: /**
019: * the feature
020: */
021: Feature feature;
022: /**
023: * The parent pointer
024: */
025: FeaturePointer parent;
026: /**
027: * the indedx of hte property being pointed at
028: */
029: int index;
030:
031: /**
032: * Creates the pointer.
033: *
034: * @param parent The parent pointer, pointer at the feature.
035: * @param index The index of hte property to point to, or -1 to point
036: * to the feature id.
037: */
038: public FeaturePropertyPointer(FeaturePointer parent, int index) {
039: super (parent);
040: this .index = index;
041: this .feature = (Feature) parent.getImmediateNode();
042: }
043:
044: /**
045: * Return <code>true</code>.
046: */
047: public boolean isLeaf() {
048: return true;
049: }
050:
051: /**
052: * Return <code>false</code>.
053: */
054: public boolean isCollection() {
055: return false;
056: }
057:
058: /**
059: * Return <code>1</code>
060: */
061: public int getLength() {
062: return 1;
063: }
064:
065: /**
066: * Returns the qname with prefix as <code>null</code>, and local part the name of the
067: * feature attribute.
068: */
069: public QName getName() {
070: return index != -1 ? new QName(null, feature.getFeatureType()
071: .getAttributeType(index).getName()) : new QName(null,
072: "fid");
073: }
074:
075: public Object getBaseValue() {
076: return feature;
077: }
078:
079: public Object getImmediateNode() {
080: return index != -1 ? feature.getAttribute(index) : feature
081: .getID();
082: }
083:
084: public void setValue(Object value) {
085: if (index == -1)
086: return; //fids arent settable
087:
088: try {
089: feature.setAttribute(index, value);
090: } catch (Exception e) {
091: throw new RuntimeException(e);
092: }
093: }
094:
095: /**
096: * Always return <code>0</code>, can never have child pointers.
097: */
098: public int compareChildNodePointers(NodePointer pointer1,
099: NodePointer pointer2) {
100: return 0;
101: }
102:
103: }
|