| 1 4 package gnu.kawa.xml; 5 import gnu.lists.*; 6 7 8 9 public class DescendantOrSelfAxis extends TreeScanner 10 { 11 public static final DescendantOrSelfAxis anyNode = 12 new DescendantOrSelfAxis(NodeType.anyNodeTest); 13 14 private DescendantOrSelfAxis (NodePredicate type) 15 { 16 this.type = type; 17 } 18 19 public static DescendantOrSelfAxis make (NodePredicate type) 20 { 21 if (type == NodeType.anyNodeTest) 22 return anyNode; 23 return new DescendantOrSelfAxis(type); 24 } 25 26 public void scan (AbstractSequence seq, int ipos, PositionConsumer out) 27 { 28 if (type.isInstancePos(seq, ipos)) 29 out.writePosition(seq, ipos); 30 if (! (seq instanceof TreeList)) 31 { ipos = seq.firstChildPos(ipos); 33 while (ipos != 0) 34 { 35 scan(seq, ipos, out); 36 ipos = seq.nextPos(ipos); 37 } 38 return; 39 } 40 int limit = seq.nextPos(ipos); 41 int child = ipos; 42 for (;;) 43 { 44 child = seq.nextMatching(child, type, limit, true); 45 if (child == 0) 46 break; 47 out.writePosition(seq, child); 48 } 49 } 50 } 51 | Popular Tags |