KickJava   Java API By Example, From Geeks To Geeks.

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


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:: step in a path expression. */
8
9 public class AncestorAxis extends TreeScanner
10 {
11   public static AncestorAxis make (NodePredicate type)
12   {
13     AncestorAxis axis = new AncestorAxis();
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     ipos = seq.parentPos(ipos);
22     if (ipos != end)
23       {
24     scan(seq, ipos, end, type, out);
25         if (type.isInstancePos(seq, ipos))
26           out.writePosition(seq, ipos);
27       }
28   }
29
30   public void scan (AbstractSequence seq, int ipos, PositionConsumer out)
31   {
32     scan(seq, ipos, seq.endPos(), type, out);
33   }
34 }
35
Popular Tags