1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.chain.web.javax.servlet;
18
19 import java.util.Map;
20
21 import javax.servlet.ServletContext;
22 import javax.servlet.http.Cookie;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.apache.commons.chain.web.javax.WebContext;
27
28
29
30
31
32
33
34
35
36 public class ServletWebContext extends WebContext {
37 private static final long serialVersionUID = 5302874006663111922L;
38
39
40
41
42
43
44
45 private transient Map<String, Object> applicationScope = null;
46
47
48
49
50 private transient ServletContext context = null;
51
52
53
54
55
56 private transient Map<String, String> header = null;
57
58
59
60
61
62 private transient Map<String, String[]> headerValues = null;
63
64
65
66
67
68 private transient Map<String, String> initParam = null;
69
70
71
72
73 private transient Map<String, Cookie> cookieValues = null;
74
75
76
77
78
79 private transient Map<String, String> param = null;
80
81
82
83
84
85 private transient Map<String, String[]> paramValues = null;
86
87
88
89
90 private transient HttpServletRequest request = null;
91
92
93
94
95
96 private transient Map<String, Object> requestScope = null;
97
98
99
100
101 private transient HttpServletResponse response = null;
102
103
104
105
106
107 private transient Map<String, Object> sessionScope = null;
108
109
110
111
112
113
114 public ServletWebContext() {
115 }
116
117
118
119
120
121
122
123
124
125 public ServletWebContext(ServletContext context,
126 HttpServletRequest request,
127 HttpServletResponse response) {
128
129 initialize(context, request, response);
130 }
131
132
133
134
135
136
137
138
139 public ServletContext getContext() {
140 return this.context;
141 }
142
143
144
145
146
147
148 public HttpServletRequest getRequest() {
149 return this.request;
150 }
151
152
153
154
155
156
157 public HttpServletResponse getResponse() {
158 return this.response;
159 }
160
161
162
163
164
165
166
167
168
169 public void initialize(ServletContext context,
170 HttpServletRequest request,
171 HttpServletResponse response) {
172
173
174 this.context = context;
175 this.request = request;
176 this.response = response;
177
178
179 }
180
181
182
183
184
185
186
187 public void release() {
188
189 applicationScope = null;
190 header = null;
191 headerValues = null;
192 initParam = null;
193 param = null;
194 paramValues = null;
195 cookieValues = null;
196 requestScope = null;
197 sessionScope = null;
198
199
200 context = null;
201 request = null;
202 response = null;
203 }
204
205
206
207
208
209
210
211
212 @Override
213 public Map<String, Object> getApplicationScope() {
214 if (applicationScope == null && context != null) {
215 applicationScope = new ServletApplicationScopeMap(context);
216 }
217 return applicationScope;
218 }
219
220
221
222
223
224
225 @Override
226 public Map<String, String> getHeader() {
227 if (header == null && request != null) {
228 header = new ServletHeaderMap(request);
229 }
230 return header;
231 }
232
233
234
235
236
237
238 @Override
239 public Map<String, String[]> getHeaderValues() {
240 if (headerValues == null && request != null) {
241 headerValues = new ServletHeaderValuesMap(request);
242 }
243 return headerValues;
244 }
245
246
247
248
249
250
251 @Override
252 public Map<String, String> getInitParam() {
253 if (initParam == null && context != null) {
254 initParam = new ServletInitParamMap(context);
255 }
256 return initParam;
257 }
258
259
260
261
262
263
264 @Override
265 public Map<String, String> getParam() {
266 if (param == null && request != null) {
267 param = new ServletParamMap(request);
268 }
269 return param;
270 }
271
272
273
274
275
276
277 @Override
278 public Map<String, String[]> getParamValues() {
279 if (paramValues == null && request != null) {
280 paramValues = new ServletParamValuesMap(request);
281 }
282 return paramValues;
283 }
284
285
286
287
288
289
290
291 @Override
292 public Map<String, Cookie> getCookies() {
293 if (cookieValues == null && request != null) {
294 cookieValues = new ServletCookieMap(request);
295 }
296 return cookieValues;
297 }
298
299
300
301
302
303
304 @Override
305 public Map<String, Object> getRequestScope() {
306 if (requestScope == null && request != null) {
307 requestScope = new ServletRequestScopeMap(request);
308 }
309 return requestScope;
310 }
311
312
313
314
315
316
317 @Override
318 public Map<String, Object> getSessionScope() {
319 if (sessionScope == null && request != null) {
320 sessionScope = new ServletSessionScopeMap(request);
321 }
322 return sessionScope;
323 }
324 }