01: package org.vraptor.scope;
02:
03: import javax.servlet.http.HttpSession;
04:
05: /**
06: * Simple decorator for the session, builds up some basic functionality.
07: *
08: * @author Guilherme Silveira
09: */
10: public class SessionContext implements Context {
11:
12: private HttpSession session;
13:
14: /**
15: * Constructor for this decorator
16: *
17: * @param session
18: * session
19: */
20: public SessionContext(HttpSession session) {
21: this .session = session;
22: }
23:
24: /**
25: * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
26: */
27: public Object getAttribute(String arg0) {
28: return this .session.getAttribute(arg0);
29: }
30:
31: /**
32: * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String,
33: * java.lang.Object)
34: */
35: public void setAttribute(String arg0, Object arg1) {
36: this .session.setAttribute(arg0, arg1);
37: }
38:
39: /**
40: * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
41: */
42: public void setMaxInactiveInterval(int arg0) {
43: this .session.setMaxInactiveInterval(arg0);
44: }
45:
46: /**
47: * Whether it has an attribute
48: *
49: * @see org.vraptor.scope.Context#hasAttribute(java.lang.String)
50: */
51: public boolean hasAttribute(String key) {
52: return this .session.getAttribute(key) != null;
53: }
54:
55: /**
56: * Removes an attribute
57: *
58: * @see org.vraptor.scope.Context#removeAttribute(java.lang.String)
59: */
60: public Object removeAttribute(String name) {
61: Object obj = getAttribute(name);
62: this.session.removeAttribute(name);
63: return obj;
64: }
65:
66: }
|