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