1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.lib.jsf;
20
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23 import java.util.Iterator;
24
25 import javax.el.ELContext;
26 import javax.faces.application.Application;
27 import javax.faces.application.FacesMessage;
28 import javax.faces.component.UIViewRoot;
29 import javax.faces.context.ExternalContext;
30 import javax.faces.context.FacesContext;
31 import javax.faces.context.ResponseStream;
32 import javax.faces.context.ResponseWriter;
33 import javax.faces.render.RenderKit;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 class FacesContextWrapper extends FacesContext
61 {
62
63
64 private final FacesContext _facesContext;
65 private Method methodGetELContext = null;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public FacesContextWrapper(FacesContext facesContext, boolean install)
82 {
83 _facesContext = facesContext;
84
85 if (install)
86 {
87 FacesContext.setCurrentInstance(this);
88 }
89 }
90
91
92
93 public void release()
94 {
95 _facesContext.release();
96 }
97
98
99
100 public final Application getApplication()
101 {
102 return _facesContext.getApplication();
103 }
104
105 public final Iterator getClientIdsWithMessages()
106 {
107 return _facesContext.getClientIdsWithMessages();
108 }
109
110 public final ExternalContext getExternalContext()
111 {
112 return _facesContext.getExternalContext();
113 }
114
115 public final FacesMessage.Severity getMaximumSeverity()
116 {
117 return _facesContext.getMaximumSeverity();
118 }
119
120 public final Iterator getMessages()
121 {
122 return _facesContext.getMessages();
123 }
124
125 public final Iterator getMessages(String clientId)
126 {
127 return _facesContext.getMessages(clientId);
128 }
129
130 public final RenderKit getRenderKit()
131 {
132 return _facesContext.getRenderKit();
133 }
134
135 public final boolean getRenderResponse()
136 {
137 return _facesContext.getRenderResponse();
138 }
139
140 public final boolean getResponseComplete()
141 {
142 return _facesContext.getResponseComplete();
143 }
144
145 public final void setResponseStream(ResponseStream responsestream)
146 {
147 _facesContext.setResponseStream(responsestream);
148 }
149
150 public final ResponseStream getResponseStream()
151 {
152 return _facesContext.getResponseStream();
153 }
154
155 public final void setResponseWriter(ResponseWriter responsewriter)
156 {
157 _facesContext.setResponseWriter(responsewriter);
158 }
159
160 public final ResponseWriter getResponseWriter()
161 {
162 return _facesContext.getResponseWriter();
163 }
164
165 public final void setViewRoot(UIViewRoot viewRoot)
166 {
167 _facesContext.setViewRoot(viewRoot);
168 }
169
170 public final UIViewRoot getViewRoot()
171 {
172 return _facesContext.getViewRoot();
173 }
174
175 public final void addMessage(String clientId, FacesMessage message)
176 {
177 _facesContext.addMessage(clientId, message);
178 }
179
180 public final void renderResponse()
181 {
182 _facesContext.renderResponse();
183 }
184
185 public final void responseComplete()
186 {
187 _facesContext.responseComplete();
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 public final ELContext getELContext()
219 {
220
221
222
223
224 try
225 {
226 if (methodGetELContext == null)
227 {
228
229 methodGetELContext = FacesContext.class.getDeclaredMethod("getELContext", (Class[]) null);
230 }
231 return (ELContext) methodGetELContext.invoke(_facesContext, (Object[]) null);
232 }
233 catch(NoSuchMethodException e)
234 {
235
236 Log log = LogFactory.getLog(this.getClass());
237 log.error("JSF1.2 method invoked in non-JSF-1.2 environment", e);
238 throw new IllegalStateException("JSF1.2 method invoked in non-JSF-1.2 environment");
239 }
240 catch(InvocationTargetException e)
241 {
242
243 Log log = LogFactory.getLog(this.getClass());
244 log.error("Method getELContext on wrapped instance threw exception", e);
245 throw new IllegalStateException("Method getELContext on wrapped instance threw exception");
246 }
247 catch(IllegalAccessException e)
248 {
249
250 Log log = LogFactory.getLog(this.getClass());
251 log.error("Method getElContext on wrapped instance is not accessable", e);
252 throw new IllegalStateException("Method getElContext on wrapped instance is not accessable");
253 }
254 }
255 }