KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > WebWorkMockPageContext


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.mockobjects.servlet.MockPageContext;
8
9 import javax.servlet.ServletResponse JavaDoc;
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.http.HttpSession JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15
16 /**
17  * Created by IntelliJ IDEA.
18  * User: Administrator
19  * Date: 14-Mar-2003
20  * Time: 5:52:36 PM
21  * To change this template use Options | File Templates.
22  */

23 public class WebWorkMockPageContext extends MockPageContext {
24     //~ Instance fields ////////////////////////////////////////////////////////
25

26     private Map JavaDoc attributes = new HashMap JavaDoc();
27     private ServletResponse JavaDoc response;
28
29     //~ Methods ////////////////////////////////////////////////////////////////
30

31     public void setAttribute(String JavaDoc s, Object JavaDoc o) {
32         if ((s == null) || (o == null)) {
33             throw new NullPointerException JavaDoc("PageContext does not accept null attributes");
34         }
35
36         this.attributes.put(s, o);
37     }
38
39     public Object JavaDoc getAttribute(String JavaDoc key) {
40         return attributes.get(key);
41     }
42
43     public Object JavaDoc getAttributes(String JavaDoc key) {
44         return this.attributes.get(key);
45     }
46
47     public void setResponse(ServletResponse JavaDoc response) {
48         this.response = response;
49     }
50
51     public ServletResponse JavaDoc getResponse() {
52         return response;
53     }
54
55     public HttpSession JavaDoc getSession() {
56         HttpSession JavaDoc session = super.getSession();
57
58         if (session == null) {
59             session = ((HttpServletRequest JavaDoc) getRequest()).getSession(true);
60         }
61
62         return session;
63     }
64
65     public Object JavaDoc findAttribute(String JavaDoc s) {
66         return attributes.get(s);
67     }
68
69     public void removeAttribute(String JavaDoc key) {
70         this.attributes.remove(key);
71     }
72 }
73
Popular Tags