KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > xml > AncestorOrSelfAxis


1 // Copyright (c) 2003 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.xml;
5 import gnu.lists.*;
6
7 /** Used to implement a ancestor-or-self:: step in a path expression. */
8
9 public class AncestorOrSelfAxis extends TreeScanner
10 {
11   public static AncestorOrSelfAxis make (NodePredicate type)
12   {
13     AncestorOrSelfAxis axis = new AncestorOrSelfAxis();
14     axis.type = type;
15     return axis;
16   }
17
18   private static void scan (AbstractSequence seq, int ipos, int end,
19                 NodePredicate type, PositionConsumer out)
20   {
21     if (ipos != end)
22       {
23     scan(seq, seq.parentPos(ipos), end, type, out);
24         if (type.isInstancePos(seq, ipos))
25           out.writePosition(seq, ipos);
26       }
27   }
28
29   public void scan (AbstractSequence seq, int ipos, PositionConsumer out)
30   {
31     int end = seq.endPos();
32     scan(seq, ipos, end, type, out);
33   }
34 }
35
Popular Tags