01: // Copyright (c) 2006 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.bytecode.*;
07: import gnu.mapping.*;
08: import gnu.expr.*;
09: import gnu.lists.*;
10: import gnu.xml.*;
11:
12: /** A Procedure to create an included entity object, or
13: * set the base-uri property for a document or fragment.
14: * This procedure takes two paramaters: The base-uri, and the "contents".
15: */
16:
17: public class MakeWithBaseUri extends NodeConstructor {
18: public static final MakeWithBaseUri makeWithBaseUri = new MakeWithBaseUri();
19:
20: public int numArgs() {
21: return 0x2002;
22: }
23:
24: public void apply(CallContext ctx) {
25: Consumer saved = ctx.consumer;
26: Consumer out = NodeConstructor.pushNodeContext(ctx);
27: Object baseUri = ctx.getNextArg();
28: Object node = ctx.getNextArg();
29: if (out instanceof XConsumer)
30: ((XConsumer) out).beginEntity(baseUri);
31: try {
32: Values.writeValues(node, out);
33: } finally {
34: if (out instanceof XConsumer)
35: ((XConsumer) out).endEntity();
36: if (out instanceof TreeList)
37: ((TreeList) out).dump();
38: NodeConstructor.popNodeContext(saved, ctx);
39: }
40: }
41:
42: public void compileToNode(ApplyExp exp, Compilation comp,
43: ConsumerTarget target) {
44: Variable consumer = target.getConsumerVariable();
45: Expression[] args = exp.getArgs();
46: int nargs = args.length;
47: CodeAttr code = comp.getCode();
48: code.emitLoad(consumer);
49: args[0].compile(comp, Target.pushObject);
50: code.emitInvokeInterface(beginEntityMethod);
51: compileChild(args[1], comp, target);
52: code.emitLoad(consumer);
53: code.emitInvokeInterface(endEntityMethod);
54: }
55:
56: static final ClassType typeXConsumer = ClassType
57: .make("gnu.lists.XConsumer");
58: static final Method beginEntityMethod = typeXConsumer
59: .getDeclaredMethod("beginEntity", 1);
60: static final Method endEntityMethod = typeXConsumer
61: .getDeclaredMethod("endEntity", 0);
62: }
|