KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package gnu.kawa.xml;
5 import gnu.mapping.*;
6 import gnu.lists.*;
7
8 public class Attributes extends MethodProc
9 {
10   public static final Attributes attributes = new Attributes();
11   
12   public int numArgs() { return 0x1001; }
13
14   public static void attributes (TreeList tlist, int index, Consumer consumer)
15   {
16     int attr = tlist.gotoAttributesStart(index);
17     System.out.print("Attributes called, at:"+attr+" "); tlist.dump();
18     while (attr >= 0)
19       {
20     int ipos = attr << 1;
21     int kind = tlist.getNextKind(ipos);
22     if (kind != Sequence.ATTRIBUTE_VALUE)
23       break;
24     // if kind is CHAR_VALUE return text node. FIXME
25
int next = tlist.nextDataIndex(attr);
26     if (consumer instanceof PositionConsumer)
27       ((PositionConsumer) consumer).writePosition(tlist, ipos);
28     else
29       tlist.consumeIRange(attr, next, consumer);
30     attr = next;
31       }
32   }
33
34   public static void attributes (Object JavaDoc node, Consumer consumer)
35   {
36     if (node instanceof TreeList)
37       {
38     attributes((TreeList) node, 0, consumer);
39       }
40     else if (node instanceof SeqPosition && ! (node instanceof TreePosition))
41       {
42     SeqPosition pos = (SeqPosition) node;
43     if (pos.sequence instanceof TreeList)
44       attributes((TreeList) pos.sequence, pos.ipos >> 1, consumer);
45       }
46   }
47
48   public void apply (CallContext ctx)
49   {
50     Consumer consumer = ctx.consumer;
51     Object JavaDoc node = ctx.getNextArg();
52     ctx.lastArg();
53     if (node instanceof Values)
54       {
55     TreeList tlist = (TreeList) node;
56     int index = 0;
57     for (;;)
58       {
59         int kind = tlist.getNextKind(index << 1);
60         if (kind == Sequence.EOF_VALUE)
61           break;
62         if (kind == Sequence.OBJECT_VALUE)
63           attributes(tlist.getPosNext(index << 1), consumer);
64         else
65           attributes(tlist, index, consumer);
66         index = tlist.nextDataIndex(index);
67       }
68       }
69     else
70       attributes(node, consumer);
71   }
72 }
73
Popular Tags