01: // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.xml;
05:
06: import gnu.mapping.*;
07: import gnu.lists.*;
08:
09: public class Attributes extends MethodProc {
10: public static final Attributes attributes = new Attributes();
11:
12: public int numArgs() {
13: return 0x1001;
14: }
15:
16: public static void attributes(TreeList tlist, int index,
17: Consumer consumer) {
18: int attr = tlist.gotoAttributesStart(index);
19: System.out.print("Attributes called, at:" + attr + " ");
20: tlist.dump();
21: while (attr >= 0) {
22: int ipos = attr << 1;
23: int kind = tlist.getNextKind(ipos);
24: if (kind != Sequence.ATTRIBUTE_VALUE)
25: break;
26: // if kind is CHAR_VALUE return text node. FIXME
27: int next = tlist.nextDataIndex(attr);
28: if (consumer instanceof PositionConsumer)
29: ((PositionConsumer) consumer)
30: .writePosition(tlist, ipos);
31: else
32: tlist.consumeIRange(attr, next, consumer);
33: attr = next;
34: }
35: }
36:
37: public static void attributes(Object node, Consumer consumer) {
38: if (node instanceof TreeList) {
39: attributes((TreeList) node, 0, consumer);
40: } else if (node instanceof SeqPosition
41: && !(node instanceof TreePosition)) {
42: SeqPosition pos = (SeqPosition) node;
43: if (pos.sequence instanceof TreeList)
44: attributes((TreeList) pos.sequence, pos.ipos >> 1,
45: consumer);
46: }
47: }
48:
49: public void apply(CallContext ctx) {
50: Consumer consumer = ctx.consumer;
51: Object node = ctx.getNextArg();
52: ctx.lastArg();
53: if (node instanceof Values) {
54: TreeList tlist = (TreeList) node;
55: int index = 0;
56: for (;;) {
57: int kind = tlist.getNextKind(index << 1);
58: if (kind == Sequence.EOF_VALUE)
59: break;
60: if (kind == Sequence.OBJECT_VALUE)
61: attributes(tlist.getPosNext(index << 1), consumer);
62: else
63: attributes(tlist, index, consumer);
64: index = tlist.nextDataIndex(index);
65: }
66: } else
67: attributes(node, consumer);
68: }
69: }
|