KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > mock > MockPageContext


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.mock;
38
39 import java.io.IOException JavaDoc;
40 import java.util.Enumeration JavaDoc;
41 import java.util.HashMap JavaDoc;
42 import javax.servlet.Servlet JavaDoc;
43 import javax.servlet.ServletConfig JavaDoc;
44 import javax.servlet.ServletContext JavaDoc;
45 import javax.servlet.ServletException JavaDoc;
46 import javax.servlet.ServletRequest JavaDoc;
47 import javax.servlet.ServletResponse JavaDoc;
48 import javax.servlet.http.HttpSession JavaDoc;
49 import javax.servlet.jsp.JspWriter JavaDoc;
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 /**
53  *
54  * @author <a HREF="mailto:robertdw@users.sourceforge.net">Robert Watkins</a>
55  */

56 public class MockPageContext extends PageContext JavaDoc {
57     private MockServletRequest request = new MockServletRequest();
58     private JspWriter JavaDoc out = new MockBodyContent();
59
60     private HashMap JavaDoc[] scopes = { new HashMap JavaDoc(), new HashMap JavaDoc(), new HashMap JavaDoc(), new HashMap JavaDoc() };
61     private MockServletContext servletContext = new MockServletContext();
62     private MockServletConfig servletConfig = new MockServletConfig();
63
64     public MockPageContext() {
65         servletConfig.setServletContext(servletContext);
66     }
67
68     public void initialize(Servlet JavaDoc servlet, ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse,
69                            String JavaDoc errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
70             throws IOException JavaDoc, IllegalStateException JavaDoc, IllegalArgumentException JavaDoc {
71     }
72
73     public void release() {
74     }
75
76     public void setAttribute(String JavaDoc name, Object JavaDoc attribute) {
77         setAttribute(name, attribute, PageContext.PAGE_SCOPE);
78     }
79
80     public void setAttribute(String JavaDoc name, Object JavaDoc attribute, int scope) {
81         scopeToMap(scope).put(name, attribute);
82     }
83
84     private HashMap JavaDoc scopeToMap(int scope) {
85         return scopes[scope - 1];
86     }
87
88     public Object JavaDoc getAttribute(String JavaDoc name) {
89         return getAttribute(name, PageContext.PAGE_SCOPE);
90     }
91
92     public Object JavaDoc getAttribute(String JavaDoc name, int scope) {
93         return scopeToMap(scope).get(name);
94     }
95
96     public Object JavaDoc findAttribute(String JavaDoc name) {
97         return null;
98     }
99
100     public void removeAttribute(String JavaDoc name) {
101         removeAttribute(name, PageContext.PAGE_SCOPE);
102     }
103
104     public void removeAttribute(String JavaDoc name, int scope) {
105     }
106
107     public int getAttributesScope(String JavaDoc name) {
108         return 0;
109     }
110
111     public Enumeration JavaDoc getAttributeNamesInScope(int scope) {
112         return null;
113     }
114
115     public JspWriter JavaDoc getOut() {
116         return out;
117     }
118
119     public HttpSession JavaDoc getSession() {
120         return null;
121     }
122
123     public Object JavaDoc getPage() {
124         return null;
125     }
126
127     public ServletRequest JavaDoc getRequest() {
128         return request;
129     }
130
131     public ServletResponse JavaDoc getResponse() {
132         return null;
133     }
134
135     public Exception JavaDoc getException() {
136         return null;
137     }
138
139     public ServletConfig JavaDoc getServletConfig() {
140         return servletConfig;
141     }
142
143     public ServletContext JavaDoc getServletContext() {
144         return servletContext;
145     }
146
147     public void forward(String JavaDoc relativeUrlPath) throws ServletException JavaDoc, IOException JavaDoc {
148     }
149
150     public void include(String JavaDoc relativeUrlPath) throws ServletException JavaDoc, IOException JavaDoc {
151     }
152
153     public void handlePageException(Exception JavaDoc e) throws ServletException JavaDoc, IOException JavaDoc {
154     }
155
156     public void setHttpServletRequest(MockServletRequest mockRequest) {
157         request = mockRequest;
158     }
159 }
160
Popular Tags