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 following:: step in a path expression. */
09:
10: public class PrecedingAxis extends TreeScanner {
11: public static PrecedingAxis make(NodePredicate type) {
12: PrecedingAxis axis = new PrecedingAxis();
13: axis.type = type;
14: return axis;
15: }
16:
17: private static void scan(AbstractSequence seq, int ipos, int end,
18: NodePredicate type, PositionConsumer out) {
19: int parent = seq.parentPos(ipos);
20: if (parent == end)
21: return;
22: scan(seq, parent, end, type, out);
23: int child = seq.firstChildPos(parent);
24: if (child == 0)
25: return;
26: if (type.isInstancePos(seq, child))
27: out.writePosition(seq, child);
28: for (;;) {
29: child = seq.nextMatching(child, type, ipos, true);
30: if (child == 0)
31: break;
32: out.writePosition(seq, child);
33: }
34: }
35:
36: public void scan(AbstractSequence seq, int ipos,
37: PositionConsumer out) {
38: scan(seq, ipos, seq.endPos(), type, out);
39: }
40: }
|