KickJava   Java API By Example, From Geeks To Geeks.

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


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 descendant:: step in a path expression. */
8
9 public class DescendantAxis extends TreeScanner
10 {
11   public static DescendantAxis make (NodePredicate type)
12   {
13     DescendantAxis axis = new DescendantAxis();
14     axis.type = type;
15     return axis;
16   }
17
18   public void scan (AbstractSequence seq, int ipos, PositionConsumer out)
19   {
20     if (! (seq instanceof TreeList))
21       { // AbstractSequence's nextMatching does not support descend. FIXME.
22
ipos = seq.firstChildPos(ipos);
23     while (ipos != 0)
24       {
25         if (type.isInstancePos(seq, ipos))
26           out.writePosition(seq, ipos);
27         scan(seq, ipos, out);
28         ipos = seq.nextPos(ipos);
29       }
30     return;
31       }
32     int limit = seq.nextPos(ipos);
33     int child = ipos;
34     for (;;)
35       {
36     child = seq.nextMatching(child, type, limit, true);
37     if (child == 0)
38       break;
39     out.writePosition(seq, child);
40       }
41   }
42 }
43
Popular Tags