KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright (c) 2006 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.bytecode.*;
6 import gnu.mapping.*;
7 import gnu.expr.*;
8 import gnu.lists.*;
9 import gnu.xml.*;
10
11 /** A Procedure to create an included entity object, or
12  * set the base-uri property for a document or fragment.
13  * This procedure takes two paramaters: The base-uri, and the "contents".
14  */

15
16 public class MakeWithBaseUri extends NodeConstructor
17 {
18   public static final MakeWithBaseUri makeWithBaseUri = new MakeWithBaseUri();
19
20   public int numArgs() { return 0x2002; }
21
22   public void apply (CallContext ctx)
23   {
24     Consumer saved = ctx.consumer;
25     Consumer out = NodeConstructor.pushNodeContext(ctx);
26     Object JavaDoc baseUri = ctx.getNextArg();
27     Object JavaDoc node = ctx.getNextArg();
28     if (out instanceof XConsumer)
29       ((XConsumer) out).beginEntity(baseUri);
30     try
31       {
32         Values.writeValues(node, out);
33       }
34     finally
35       {
36         if (out instanceof XConsumer)
37           ((XConsumer) out).endEntity();
38         if (out instanceof TreeList)
39           ((TreeList)out).dump();
40     NodeConstructor.popNodeContext(saved, ctx);
41       }
42   }
43
44
45   public void compileToNode (ApplyExp exp, Compilation comp,
46                       ConsumerTarget target)
47   {
48     Variable consumer = target.getConsumerVariable();
49     Expression[] args = exp.getArgs();
50     int nargs = args.length;
51     CodeAttr code = comp.getCode();
52     code.emitLoad(consumer);
53     args[0].compile(comp, Target.pushObject);
54     code.emitInvokeInterface(beginEntityMethod);
55     compileChild(args[1], comp, target);
56     code.emitLoad(consumer);
57     code.emitInvokeInterface(endEntityMethod);
58   }
59
60   static final ClassType typeXConsumer = ClassType.make("gnu.lists.XConsumer");
61   static final Method beginEntityMethod
62     = typeXConsumer.getDeclaredMethod("beginEntity", 1);
63   static final Method endEntityMethod
64     = typeXConsumer.getDeclaredMethod("endEntity", 0);
65 }
66
Popular Tags