KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > servlet > GetRequest


1 // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.servlet;
5 import gnu.lists.*;
6 import gnu.mapping.*;
7 import gnu.bytecode.*;
8 import gnu.expr.*;
9
10 /** A 0-argument function that returns the current ServletRequest. */
11
12 public class GetRequest extends MethodProc implements Inlineable
13 {
14   public static final GetRequest getRequest = new GetRequest();
15
16   public int numArgs() { return 0; }
17
18   public static javax.servlet.http.HttpServletRequest JavaDoc getRequest(CallContext ctx)
19   {
20     return ((ServletCallContext) ctx).request;
21   }
22
23   public void apply (CallContext ctx)
24   {
25     ctx.lastArg();
26     ctx.consumer.writeObject(((ServletCallContext) ctx).request);
27   }
28
29   public void compile (ApplyExp exp, Compilation comp, Target target)
30   {
31     Expression[] args = exp.getArgs();
32     if (args.length != 0 || ! comp.curLambda.isHandlingTailCalls())
33       {
34     ApplyExp.compile(exp, comp, target);
35     return;
36       }
37
38     CodeAttr code = comp.getCode();
39     comp.loadCallContext();
40     code.emitInvokeStatic(typeGetRequest.getDeclaredMethod("getRequest", 1));
41     target.compileFromStack(comp, typeHttpServletRequest);
42   }
43
44   public Type getReturnType (Expression[] args)
45   {
46     return typeHttpServletRequest;
47   }
48
49   public static final ClassType typeGetRequest
50     = ClassType.make("gnu.kawa.servlet.GetRequest");
51
52   public static final ClassType typeHttpServletRequest
53   = ClassType.make("javax.servlet.http.HttpServletRequest");
54 }
55
Popular Tags