01: /*
02: * @(#)getSession.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.servlet;
10:
11: import pnuts.servlet.*;
12: import pnuts.lang.*;
13: import pnuts.servlet.*;
14: import javax.servlet.*;
15: import javax.servlet.http.*;
16: import java.util.*;
17:
18: /*
19: * function getSession()
20: * function getSession(boolean)
21: */
22: public class getSession extends PnutsFunction {
23: public getSession() {
24: super ("getSession");
25: }
26:
27: public boolean defined(int nargs) {
28: return nargs < 2;
29: }
30:
31: static HttpSession getSession(Context context, boolean create) {
32: HttpServletRequest request = (HttpServletRequest) context
33: .get(PnutsServlet.SERVLET_REQUEST);
34: if (request == null) {
35: throw new IllegalStateException();
36: }
37: return request.getSession(create);
38: }
39:
40: protected Object exec(Object args[], Context context) {
41: int nargs = args.length;
42: boolean create;
43: if (nargs == 1) {
44: create = ((Boolean) args[0]).booleanValue();
45: } else if (nargs == 0) {
46: create = true;
47: } else {
48: undefined(args, context);
49: return null;
50: }
51: return getSession(context, create);
52: }
53:
54: public String toString() {
55: return "function getSession( { create } )";
56: }
57: }
|