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