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