KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright (c) 2001, 2004 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.lists.*;
6 import gnu.mapping.*;
7 import gnu.expr.*;
8 import gnu.bytecode.*;
9
10 public class MakeAttribute extends NodeConstructor
11 {
12   public static final MakeAttribute makeAttribute = new MakeAttribute();
13   public static final QuoteExp makeAttributeExp = new QuoteExp(makeAttribute);
14
15   public int numArgs() { return 0xFFFFF001; }
16
17   public static void beginAttribute(Consumer out, Object JavaDoc type)
18   {
19     out.beginAttribute(type);
20   }
21
22   public void apply (CallContext ctx)
23   {
24     Consumer saved = ctx.consumer;
25     Consumer out = pushNodeContext(ctx);
26     try
27       {
28     Object JavaDoc type = ctx.getNextArg();
29     beginAttribute(out, type);
30     Object JavaDoc endMarker = Special.dfault;
31     for (;;)
32       {
33         Object JavaDoc arg = ctx.getNextArg(endMarker);
34         if (arg == endMarker)
35           break;
36         if (arg instanceof Consumable)
37           ((Consumable) arg).consume(out);
38         else
39           ctx.writeValue(arg);
40       }
41     out.endAttribute();
42       }
43     finally
44       {
45     popNodeContext(saved, ctx);
46       }
47   }
48
49   public void compileToNode (ApplyExp exp, Compilation comp,
50                       ConsumerTarget target)
51   {
52     Variable consumer = ((ConsumerTarget) target).getConsumerVariable();
53     Expression[] args = exp.getArgs();
54     int nargs = args.length;
55     CodeAttr code = comp.getCode();
56     code.emitLoad(consumer);
57     code.emitDup();
58     args[0].compile(comp, Target.pushObject);
59     // Stack: consumer, consumer, tagtype
60
code.emitInvokeStatic(beginAttributeMethod);
61     for (int i = 1; i < nargs; i++)
62       compileChild(args[i], comp, target);
63     code.emitInvokeInterface(endAttributeMethod);
64   }
65
66   static final ClassType typeMakeAttribute
67     = ClassType.make("gnu.kawa.xml.MakeAttribute");
68   static final Method beginAttributeMethod
69     = typeMakeAttribute.getDeclaredMethod("beginAttribute", 2);
70   static final Method endAttributeMethod
71     = Compilation.typeConsumer.getDeclaredMethod("endAttribute", 0);
72
73   public Type getReturnType (Expression[] args)
74   {
75     return Compilation.typeObject;
76   }
77 }
78
Popular Tags