01: // Copyright (c) 2004 Per M.A. Bothner
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: import gnu.xml.TextUtils;
09:
10: public class CommentConstructor extends MethodProc // NodeConstructor
11: {
12: public static final CommentConstructor commentConstructor = new CommentConstructor();
13:
14: public int numArgs() {
15: return 0x1001;
16: }
17:
18: public void apply(CallContext ctx) {
19: Consumer saved = ctx.consumer;
20: XConsumer out = NodeConstructor.pushNodeContext(ctx);
21: try {
22: StringBuffer sbuf = new StringBuffer();
23: Object endMarker = Location.UNBOUND;
24: boolean first = true;
25: for (int i = 0;; i++) {
26: Object arg = ctx.getNextArg(endMarker);
27: if (arg == endMarker)
28: break;
29: if (arg instanceof Values) {
30: Values vals = (Values) arg;
31: for (int it = 0; (it = vals.nextPos(it)) != 0;) {
32: if (!first)
33: sbuf.append(' ');
34: first = false;
35: TextUtils.stringValue(vals.getPosPrevious(it),
36: sbuf);
37: }
38: } else {
39: if (!first)
40: sbuf.append(' ');
41: first = false;
42: TextUtils.stringValue(arg, sbuf);
43: }
44: }
45: int len = sbuf.length();
46: char[] buf = new char[len];
47: sbuf.getChars(0, len, buf, 0);
48: out.writeComment(buf, 0, len);
49: } finally {
50: NodeConstructor.popNodeContext(saved, ctx);
51: }
52: }
53: }
|