1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.event;
20
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.context.FacesContext;
28
29
30
31
32
33
34
35 public class ExceptionQueuedEventContext implements SystemEventListenerHolder
36 {
37
38
39 public static final String IN_AFTER_PHASE_KEY = ExceptionQueuedEventContext.class.getName() + ".IN_AFTER_PHASE";
40 public static final String IN_BEFORE_PHASE_KEY = ExceptionQueuedEventContext.class.getName() + ".IN_BEFORE_PHASE";
41
42 private Map<Object, Object> _attributes;
43 private UIComponent _component;
44 private FacesContext _context;
45 private PhaseId _phase;
46 private Throwable _thrown;
47
48 public ExceptionQueuedEventContext(FacesContext context, Throwable thrown)
49 {
50 this(context, thrown, null);
51 }
52
53 public ExceptionQueuedEventContext(FacesContext context, Throwable thrown, UIComponent component)
54 {
55 this(context, thrown, component, null);
56 }
57
58 public ExceptionQueuedEventContext(FacesContext context, Throwable thrown, UIComponent component, PhaseId phaseId)
59 {
60 _context = context;
61 _thrown = thrown;
62 _component = component;
63 _phase = (phaseId == null ? context.getCurrentPhaseId() : phaseId);
64 }
65
66 public Map<Object,Object> getAttributes()
67 {
68 if (_attributes == null)
69 {
70 _attributes = new HashMap<Object, Object>();
71 }
72
73 return _attributes;
74 }
75
76 public UIComponent getComponent()
77 {
78 return _component;
79 }
80
81 public FacesContext getContext()
82 {
83 return _context;
84 }
85
86 public Throwable getException()
87 {
88 return _thrown;
89 }
90
91
92
93
94 public List<SystemEventListener> getListenersForEventClass(Class<? extends SystemEvent> facesEventClass)
95 {
96 return Collections.singletonList((SystemEventListener)getContext().getExceptionHandler());
97 }
98
99 public PhaseId getPhaseId()
100 {
101 return _phase;
102 }
103
104 public boolean inAfterPhase()
105 {
106 return (_attributes != null && _attributes.containsKey(IN_AFTER_PHASE_KEY));
107 }
108
109 public boolean inBeforePhase()
110 {
111 return (_attributes != null && _attributes.containsKey(IN_BEFORE_PHASE_KEY));
112 }
113 }