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.SequenceIterator; 5 import net.sf.saxon.pattern.NodeTest; 6 import net.sf.saxon.style.StandardNames; 7 8 14 15 final class DescendantEnumeration extends AxisIteratorImpl { 16 17 private TinyTree tree; 18 private TinyNodeImpl startNode; 19 private boolean includeSelf; 20 private int nextNodeNr; 21 private int startDepth; 22 private NodeTest test; 23 24 31 32 DescendantEnumeration(TinyTree doc, TinyNodeImpl node, NodeTest nodeTest, boolean includeSelf) { 33 tree = doc; 34 startNode = node; 35 this.includeSelf = includeSelf; 36 test = nodeTest; 37 nextNodeNr = node.nodeNr; 38 startDepth = doc.depth[nextNodeNr]; 39 } 40 41 public Item next() { 42 if (position==0 && includeSelf && test.matches(startNode)) { 43 current = startNode; 44 position++; 45 return current; 46 } 47 48 do { 49 nextNodeNr++; 50 try { 51 if (tree.depth[nextNodeNr] <= startDepth) { 52 nextNodeNr = -1; 53 current = null; 54 position = -1; 55 return null; 56 } 57 } catch (ArrayIndexOutOfBoundsException e) { 58 nextNodeNr = -1; 62 current = null; 63 position = -1; 64 return null; 65 } 66 } while (!test.matches(tree, nextNodeNr)); 67 68 position++; 69 if (isAtomizing() && tree.getTypeAnnotation(nextNodeNr) == StandardNames.XDT_UNTYPED) { 70 current = tree.getUntypedAtomicValue(nextNodeNr); 71 } else { 72 current = tree.getNode(nextNodeNr); 73 } 74 75 return current; 76 } 77 78 81 82 public SequenceIterator getAnother() { 83 return new DescendantEnumeration(tree, startNode, test, includeSelf); 84 } 85 } 86 87 88 | Popular Tags |