1 package net.sf.saxon.tinytree; 2 import net.sf.saxon.om.AxisIteratorImpl; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.om.NodeInfo; 5 import net.sf.saxon.om.SequenceIterator; 6 import net.sf.saxon.pattern.NodeTest; 7 8 12 13 final class AncestorEnumeration extends AxisIteratorImpl { 14 15 private TinyNodeImpl startNode; 16 private NodeTest test; 17 private boolean includeSelf; 18 19 public AncestorEnumeration(TinyNodeImpl node, NodeTest nodeTest, boolean includeSelf) { 20 test = nodeTest; 21 this.startNode = node; 22 this.includeSelf = includeSelf; 23 current = startNode; 24 } 25 26 public Item next() { 27 if (position==0 && includeSelf && test.matches(startNode)) { 28 current = startNode; 29 position = 1; 30 return current; 31 } else { 32 NodeInfo node = ((NodeInfo)current).getParent(); 33 while (node != null && !test.matches(node)) { 34 node = node.getParent(); 35 } 36 current = node; 37 if (node == null) { 38 position = -1; 39 } else { 40 position++; 41 } 42 return current; 43 } 44 } 45 46 49 50 public SequenceIterator getAnother() { 51 return new AncestorEnumeration(startNode, test, includeSelf); 52 } 53 54 } 55 56 | Popular Tags |