001: package org.geotools.xml.impl.jxpath;
002:
003: import org.apache.commons.jxpath.ri.Compiler;
004: import org.apache.commons.jxpath.ri.QName;
005: import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
006: import org.apache.commons.jxpath.ri.compiler.NodeTest;
007: import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
008: import org.apache.commons.jxpath.ri.model.NodeIterator;
009: import org.apache.commons.jxpath.ri.model.NodePointer;
010: import org.geotools.feature.Feature;
011:
012: /**
013: * Special node pointer for {@link org.geotools.feature.Feature}.
014: *
015: * @author Justin Deoliveira, The Open Planning Project
016: *
017: */
018: public class FeaturePointer extends NodePointer {
019:
020: /**
021: * The name of hte node.
022: */
023: QName name;
024:
025: /**
026: * The underlying feature
027: */
028: Feature feature;
029:
030: protected FeaturePointer(NodePointer parent, Feature feature,
031: QName name) {
032: super (parent);
033: this .name = name;
034: this .feature = feature;
035: }
036:
037: public boolean isLeaf() {
038: return false;
039: }
040:
041: public boolean isCollection() {
042: return true;
043: }
044:
045: public int getLength() {
046: return feature.getNumberOfAttributes();
047: }
048:
049: public QName getName() {
050: return name;
051: }
052:
053: public Object getBaseValue() {
054: return null;
055: }
056:
057: public Object getImmediateNode() {
058: return feature;
059: }
060:
061: public void setValue(Object value) {
062: feature = (Feature) value;
063: }
064:
065: public int compareChildNodePointers(NodePointer pointer1,
066: NodePointer pointer2) {
067:
068: return 0;
069: }
070:
071: public NodeIterator childIterator(NodeTest test, boolean reverse,
072: NodePointer startWith) {
073: if (test instanceof NodeNameTest) {
074: NodeNameTest nodeNameTest = (NodeNameTest) test;
075:
076: if (!nodeNameTest.isWildcard()) {
077: int index = feature.getFeatureType().find(
078: nodeNameTest.getNodeName().getName());
079: if (index > -1) {
080: return new SingleFeaturePropertyIterator(this ,
081: index);
082: }
083:
084: } else {
085: return new FeaturePropertyIterator(this );
086: }
087: }
088:
089: if (test instanceof NodeTypeTest) {
090: NodeTypeTest nodeTypeTest = (NodeTypeTest) test;
091: if (nodeTypeTest.getNodeType() == Compiler.NODE_TYPE_NODE) {
092: return new FeaturePropertyIterator(this );
093: }
094: }
095:
096: return super .childIterator(test, reverse, startWith);
097: }
098:
099: public NodeIterator attributeIterator(QName qname) {
100: if (qname.getName().equals("id")
101: || qname.getName().equals("fid")) {
102: return new SingleFeaturePropertyIterator(this , -1);
103: }
104:
105: return super.attributeIterator(qname);
106: }
107:
108: }
|