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 ancestor-or-self:: step in a path expression. */
09:
10: public class AncestorOrSelfAxis extends TreeScanner {
11: public static AncestorOrSelfAxis make(NodePredicate type) {
12: AncestorOrSelfAxis axis = new AncestorOrSelfAxis();
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: if (ipos != end) {
20: scan(seq, seq.parentPos(ipos), end, type, out);
21: if (type.isInstancePos(seq, ipos))
22: out.writePosition(seq, ipos);
23: }
24: }
25:
26: public void scan(AbstractSequence seq, int ipos,
27: PositionConsumer out) {
28: int end = seq.endPos();
29: scan(seq, ipos, end, type, out);
30: }
31: }
|