1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.context;
20
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.el.ELContext;
26 import javax.faces.application.Application;
27 import javax.faces.application.FacesMessage;
28 import javax.faces.application.ProjectStage;
29 import javax.faces.component.UIViewRoot;
30 import javax.faces.event.PhaseId;
31 import javax.faces.render.RenderKit;
32
33
34
35
36
37
38
39 public abstract class FacesContext
40 {
41 private static ThreadLocal<FacesContext> currentInstance = new ThreadLocal<FacesContext>();
42
43 private static ThreadLocal<FacesContext> firstInstance = new ThreadLocal<FacesContext>();
44
45 public abstract void addMessage(String clientId, FacesMessage message);
46
47 public abstract Application getApplication();
48
49
50
51
52
53
54
55 public Map<Object, Object> getAttributes()
56 {
57 FacesContext ctx = firstInstance.get();
58
59 if (ctx == null)
60 {
61 throw new UnsupportedOperationException();
62 }
63
64 return ctx.getAttributes();
65 }
66
67 public abstract Iterator<String> getClientIdsWithMessages();
68
69 public static FacesContext getCurrentInstance()
70 {
71 return currentInstance.get();
72 }
73
74
75
76
77
78
79
80 public PhaseId getCurrentPhaseId()
81 {
82 FacesContext ctx = firstInstance.get();
83
84 if (ctx == null)
85 {
86 throw new UnsupportedOperationException();
87 }
88
89 return ctx.getCurrentPhaseId();
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 public ELContext getELContext()
117 {
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 FacesContext ctx = firstInstance.get();
133
134 if (ctx == null)
135 {
136 throw new NullPointerException(FacesContext.class.getName());
137 }
138
139 ELContext elctx = ctx.getELContext();
140 if (elctx == null)
141 {
142 throw new UnsupportedOperationException();
143 }
144
145 return elctx;
146 }
147
148
149
150
151
152
153
154 public ExceptionHandler getExceptionHandler()
155 {
156 FacesContext ctx = firstInstance.get();
157
158 if (ctx == null)
159 {
160 throw new UnsupportedOperationException();
161 }
162
163 return ctx.getExceptionHandler();
164 }
165
166 public abstract ExternalContext getExternalContext();
167
168 public abstract FacesMessage.Severity getMaximumSeverity();
169
170
171
172
173
174
175
176 public List<FacesMessage> getMessageList()
177 {
178 FacesContext ctx = firstInstance.get();
179
180 if (ctx == null)
181 {
182 throw new UnsupportedOperationException();
183 }
184
185 return ctx.getMessageList();
186 }
187
188
189
190
191
192
193
194
195 public List<FacesMessage> getMessageList(String clientId)
196 {
197 FacesContext ctx = firstInstance.get();
198
199 if (ctx == null)
200 {
201 throw new UnsupportedOperationException();
202 }
203
204 return ctx.getMessageList(clientId);
205 }
206
207 public abstract Iterator<FacesMessage> getMessages();
208
209 public abstract Iterator<FacesMessage> getMessages(String clientId);
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 public PartialViewContext getPartialViewContext()
226 {
227 FacesContext ctx = firstInstance.get();
228
229 if (ctx == null)
230 {
231 throw new UnsupportedOperationException();
232 }
233
234 return ctx.getPartialViewContext();
235 }
236
237 public abstract RenderKit getRenderKit();
238
239 public abstract boolean getRenderResponse();
240
241 public abstract boolean getResponseComplete();
242
243 public abstract ResponseStream getResponseStream();
244
245 public abstract ResponseWriter getResponseWriter();
246
247
248
249
250
251
252
253 public boolean isValidationFailed()
254 {
255 FacesContext ctx = firstInstance.get();
256
257 if (ctx == null)
258 {
259 throw new UnsupportedOperationException();
260 }
261
262 return ctx.isValidationFailed();
263 }
264
265 public abstract UIViewRoot getViewRoot();
266
267
268
269
270
271
272
273 public boolean isPostback()
274 {
275 FacesContext ctx = firstInstance.get();
276
277 if (ctx == null)
278 {
279 throw new UnsupportedOperationException();
280 }
281
282 return ctx.isPostback();
283 }
284
285
286
287
288
289
290
291 public boolean isProcessingEvents()
292 {
293 FacesContext ctx = firstInstance.get();
294
295 if (ctx == null)
296 {
297 throw new UnsupportedOperationException();
298 }
299
300 return ctx.isProcessingEvents();
301 }
302
303 public abstract void release();
304
305 public abstract void renderResponse();
306
307 public abstract void responseComplete();
308
309 protected static void setCurrentInstance(FacesContext context)
310 {
311 if (context == null)
312 {
313 currentInstance.remove();
314 firstInstance.remove();
315 }
316 else
317 {
318 currentInstance.set(context);
319
320 if (firstInstance.get() == null)
321 {
322 firstInstance.set(context);
323 }
324 }
325 }
326
327
328
329
330
331
332
333 public void setCurrentPhaseId(PhaseId currentPhaseId)
334 {
335 FacesContext ctx = firstInstance.get();
336
337 if (ctx == null)
338 {
339 throw new UnsupportedOperationException();
340 }
341
342 ctx.setCurrentPhaseId(currentPhaseId);
343 }
344
345
346
347
348
349
350
351 public void setExceptionHandler(ExceptionHandler exceptionHandler)
352 {
353 FacesContext ctx = firstInstance.get();
354
355 if (ctx == null)
356 {
357 throw new UnsupportedOperationException();
358 }
359
360 ctx.setExceptionHandler(exceptionHandler);
361 }
362
363
364
365
366
367
368
369 public void setProcessingEvents(boolean processingEvents)
370 {
371 FacesContext ctx = firstInstance.get();
372
373 if (ctx == null)
374 {
375 throw new UnsupportedOperationException();
376 }
377
378 ctx.setProcessingEvents(processingEvents);
379 }
380
381 public abstract void setResponseStream(ResponseStream responseStream);
382
383 public abstract void setResponseWriter(ResponseWriter responseWriter);
384
385 public abstract void setViewRoot(UIViewRoot root);
386
387
388
389
390
391
392 public void validationFailed()
393 {
394 FacesContext ctx = firstInstance.get();
395
396 if (ctx == null)
397 {
398 throw new UnsupportedOperationException();
399 }
400
401 ctx.validationFailed();
402 }
403
404 public boolean isProjectStage(ProjectStage stage)
405 {
406 if (stage == null)
407 {
408 throw new NullPointerException();
409 }
410
411 if (stage.equals(getApplication().getProjectStage()))
412 {
413 return true;
414 }
415 return false;
416 }
417
418
419
420
421
422
423 public boolean isReleased()
424 {
425 FacesContext ctx = firstInstance.get();
426
427 if (ctx == null)
428 {
429 throw new UnsupportedOperationException();
430 }
431
432 return ctx.isReleased();
433 }
434 }