01: /*
02: * @(#)getSessionMap.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 getSessionMap()
20: * function getSessionMap(boolean)
21: */
22: public class getSessionMap extends PnutsFunction {
23:
24: public getSessionMap() {
25: super ("getSessionMap");
26: }
27:
28: public boolean defined(int nargs) {
29: return nargs < 2;
30: }
31:
32: static Map getSessionMap(Context context, boolean create) {
33: HttpServletRequest request = (HttpServletRequest) context
34: .get(PnutsServlet.SERVLET_REQUEST);
35: if (request == null) {
36: throw new IllegalStateException();
37: }
38: return new SessionMap(request.getSession(create));
39: }
40:
41: protected Object exec(Object args[], Context context) {
42: int nargs = args.length;
43: boolean create;
44: if (nargs == 1) {
45: create = ((Boolean) args[0]).booleanValue();
46: } else if (nargs == 0) {
47: create = true;
48: } else {
49: undefined(args, context);
50: return null;
51: }
52: return getSessionMap(context, create);
53: }
54:
55: public String toString() {
56: return "function getSessionMap( { create } )";
57: }
58: }
|