01: // Copyright (c) 2003 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.xml;
05:
06: import gnu.lists.*;
07:
08: /** Used to implement a descendant:: step in a path expression. */
09:
10: public class DescendantAxis extends TreeScanner {
11: public static DescendantAxis make(NodePredicate type) {
12: DescendantAxis axis = new DescendantAxis();
13: axis.type = type;
14: return axis;
15: }
16:
17: public void scan(AbstractSequence seq, int ipos,
18: PositionConsumer out) {
19: if (!(seq instanceof TreeList)) { // AbstractSequence's nextMatching does not support descend. FIXME.
20: ipos = seq.firstChildPos(ipos);
21: while (ipos != 0) {
22: if (type.isInstancePos(seq, ipos))
23: out.writePosition(seq, ipos);
24: scan(seq, ipos, out);
25: ipos = seq.nextPos(ipos);
26: }
27: return;
28: }
29: int limit = seq.nextPos(ipos);
30: int child = ipos;
31: for (;;) {
32: child = seq.nextMatching(child, type, limit, true);
33: if (child == 0)
34: break;
35: out.writePosition(seq, child);
36: }
37: }
38: }
|