KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jstl > test > PageContextImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.lang.jstl.test;
18
19 import java.util.Collections JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.servlet.Servlet JavaDoc;
25 import javax.servlet.ServletConfig JavaDoc;
26 import javax.servlet.ServletContext JavaDoc;
27 import javax.servlet.ServletRequest JavaDoc;
28 import javax.servlet.ServletResponse JavaDoc;
29 import javax.servlet.http.HttpSession JavaDoc;
30 import javax.servlet.jsp.JspWriter JavaDoc;
31 import javax.servlet.jsp.PageContext JavaDoc;
32 import javax.servlet.jsp.el.ExpressionEvaluator JavaDoc;
33 import javax.servlet.jsp.el.VariableResolver JavaDoc;
34
35 /**
36  *
37  * <p>This is a "dummy" implementation of PageContext whose only
38  * purpose is to serve the attribute getter/setter API's.
39  *
40  * @author Nathan Abramson - Art Technology Group
41  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: pierred $
42  **/

43
44 public class PageContextImpl
45   extends PageContext JavaDoc
46 {
47   //-------------------------------------
48
// Properties
49
//-------------------------------------
50

51   //-------------------------------------
52
// Member variables
53
//-------------------------------------
54

55   Map JavaDoc mPage = Collections.synchronizedMap (new HashMap JavaDoc ());
56   Map JavaDoc mRequest = Collections.synchronizedMap (new HashMap JavaDoc ());
57   Map JavaDoc mSession = Collections.synchronizedMap (new HashMap JavaDoc ());
58   Map JavaDoc mApp = Collections.synchronizedMap (new HashMap JavaDoc ());
59
60   //-------------------------------------
61
/**
62    *
63    * Constructor
64    **/

65   public PageContextImpl ()
66   {
67   }
68
69   //-------------------------------------
70
// PageContext methods
71
//-------------------------------------
72
public void initialize (Servlet JavaDoc servlet,
73               ServletRequest JavaDoc request,
74               ServletResponse JavaDoc response,
75               String JavaDoc errorPageURL,
76               boolean needSession,
77               int bufferSize,
78               boolean autoFlush)
79   {
80   }
81
82   //-------------------------------------
83
public void release ()
84   {
85   }
86
87   //-------------------------------------
88
public void setAttribute (String JavaDoc name,
89                 Object JavaDoc attribute)
90   {
91     mPage.put (name, attribute);
92   }
93
94   //-------------------------------------
95
public void setAttribute (String JavaDoc name,
96                 Object JavaDoc attribute,
97                 int scope)
98   {
99     switch (scope) {
100     case PAGE_SCOPE:
101       mPage.put (name, attribute);
102       break;
103     case REQUEST_SCOPE:
104       mRequest.put (name, attribute);
105       break;
106     case SESSION_SCOPE:
107       mSession.put (name, attribute);
108       break;
109     case APPLICATION_SCOPE:
110       mApp.put (name, attribute);
111       break;
112     default:
113       throw new IllegalArgumentException JavaDoc ("Bad scope " + scope);
114     }
115   }
116
117   //-------------------------------------
118
public Object JavaDoc getAttribute (String JavaDoc name)
119   {
120     return mPage.get (name);
121   }
122
123   //-------------------------------------
124
public Object JavaDoc getAttribute (String JavaDoc name,
125                   int scope)
126   {
127     switch (scope) {
128     case PAGE_SCOPE:
129       return mPage.get (name);
130     case REQUEST_SCOPE:
131       return mRequest.get (name);
132     case SESSION_SCOPE:
133       return mSession.get (name);
134     case APPLICATION_SCOPE:
135       return mApp.get (name);
136     default:
137       throw new IllegalArgumentException JavaDoc ("Bad scope " + scope);
138     }
139   }
140
141   //-------------------------------------
142
public Object JavaDoc findAttribute (String JavaDoc name)
143   {
144     if (mPage.containsKey (name)) {
145       return mPage.get (name);
146     }
147     else if (mRequest.containsKey (name)) {
148       return mRequest.get (name);
149     }
150     else if (mSession.containsKey (name)) {
151       return mSession.get (name);
152     }
153     else if (mApp.containsKey (name)) {
154       return mApp.get (name);
155     }
156     else {
157       return null;
158     }
159   }
160
161   //-------------------------------------
162
public void removeAttribute (String JavaDoc name)
163   {
164     if (mPage.containsKey (name)) {
165       mPage.remove (name);
166     }
167     else if (mRequest.containsKey (name)) {
168       mRequest.remove (name);
169     }
170     else if (mSession.containsKey (name)) {
171       mSession.remove (name);
172     }
173     else if (mApp.containsKey (name)) {
174       mApp.remove (name);
175     }
176   }
177
178   //-------------------------------------
179
public void removeAttribute (String JavaDoc name,
180                    int scope)
181   {
182     switch (scope) {
183     case PAGE_SCOPE:
184       mPage.remove (name);
185       break;
186     case REQUEST_SCOPE:
187       mRequest.remove (name);
188       break;
189     case SESSION_SCOPE:
190       mSession.remove (name);
191       break;
192     case APPLICATION_SCOPE:
193       mApp.remove (name);
194       break;
195     default:
196       throw new IllegalArgumentException JavaDoc ("Bad scope " + scope);
197     }
198   }
199
200   //-------------------------------------
201
public int getAttributesScope (String JavaDoc name)
202   {
203     if (mPage.containsKey (name)) {
204       return PAGE_SCOPE;
205     }
206     else if (mRequest.containsKey (name)) {
207       return REQUEST_SCOPE;
208     }
209     else if (mSession.containsKey (name)) {
210       return SESSION_SCOPE;
211     }
212     else if (mApp.containsKey (name)) {
213       return APPLICATION_SCOPE;
214     }
215     else {
216       return 0;
217     }
218   }
219
220   //-------------------------------------
221
public Enumeration JavaDoc getAttributeNamesInScope (int scope)
222   {
223     return null;
224   }
225
226   //-------------------------------------
227
public JspWriter JavaDoc getOut ()
228   {
229     return null;
230   }
231
232   //-------------------------------------
233
public HttpSession JavaDoc getSession ()
234   {
235     return null;
236   }
237
238   //-------------------------------------
239
public Object JavaDoc getPage ()
240   {
241     return null;
242   }
243
244   //-------------------------------------
245
public ServletRequest JavaDoc getRequest ()
246   {
247     return null;
248   }
249
250   //-------------------------------------
251
public ServletResponse JavaDoc getResponse ()
252   {
253     return null;
254   }
255
256   //-------------------------------------
257
public Exception JavaDoc getException ()
258   {
259     return null;
260   }
261
262   //-------------------------------------
263
public ServletConfig JavaDoc getServletConfig ()
264   {
265     return null;
266   }
267
268   //-------------------------------------
269
public ServletContext JavaDoc getServletContext ()
270   {
271     return null;
272   }
273
274   //-------------------------------------
275
public void forward (String JavaDoc path)
276   {
277   }
278
279   //-------------------------------------
280
public void include (String JavaDoc path)
281   {
282   }
283
284   //-------------------------------------
285
public void handlePageException (Exception JavaDoc exc)
286   {
287   }
288
289   //-------------------------------------
290
public void handlePageException (Throwable JavaDoc exc)
291   {
292   }
293
294   //-------------------------------------
295

296   // Since JSP 2.0
297
public void include(java.lang.String JavaDoc relativeUrlPath, boolean flush) {}
298   public ExpressionEvaluator JavaDoc getExpressionEvaluator() { return null; }
299   public VariableResolver JavaDoc getVariableResolver() { return null; }
300   
301 }
302
Popular Tags