1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.orchestra.lib.jsf;
20
21 import java.util.Iterator;
22
23 import javax.el.ELContext;
24 import javax.faces.application.Application;
25 import javax.faces.application.FacesMessage;
26 import javax.faces.component.UIViewRoot;
27 import javax.faces.context.ExternalContext;
28 import javax.faces.context.FacesContext;
29 import javax.faces.context.ResponseStream;
30 import javax.faces.context.ResponseWriter;
31 import javax.faces.render.RenderKit;
32
33
34 /**
35 * Convenient class to wrap the current FacesContext.
36 * <p>
37 * A class of this name is provided in JSF1.2, but not in JSF1.1.
38 * <p>
39 * Any methods that do not actually need to be overridden are declared final
40 * in order to improve performance (helps the JVM to optimise away the call).
41 * <p>
42 * Note that whether a newly-created instance immediately becomes the
43 * object that is returned by FacesContext.getCurrentInstance() depends
44 * upon the value of the "install" parameter for the constructor method.
45 * <p>
46 * This class is copied from the code in MyFaces Core Impl 1.2.x, but
47 * modified to be compatible with JSF1.1.
48 * <p>
49 * Note that this class must be public in order to support custom
50 * FacesContextFactory classes in other libraries that also wrap this
51 * instance, then use reflection to invoke methods on this object. In
52 * this case, an IllegalAccessException would occur if this class was
53 * package-scoped. However this class is NOT intended to be part of the
54 * public Orchestra API, and may change at any time.
55 *
56 * @since 1.1
57 *
58 * @author Manfred Geiler (latest modification by $Author: skitching $)
59 * @author Anton Koinov
60 * @version $Revision: 672906 $ $Date: 2008-06-30 15:45:16 -0500 (lun, 30 jun 2008) $
61 */
62 public class _FacesContextWrapper extends FacesContext
63 {
64 //~ Instance fields -------------------------------------------------------
65
66 private final FacesContext _facesContext;
67
68 //~ Constructors ----------------------------------------------------------
69
70 /**
71 * The install parameter controls whether this object will be configured as
72 * the object returned from calls to FacesContext.getCurrentInstance() or not.
73 * <p>
74 * When only overriding the release() method, then install=false is ok as that
75 * is called directly by the FacesServlet on the instance returned by the
76 * FacesContextFactory. However all other methods are invoked on the object
77 * that is returned from FacesContext.getCurrentInstance, so install=true is
78 * needed in order for any other method overrides to have any effect.
79 * <p>
80 * <b>IMPORTANT</b>: install=true should not be used until MYFACES-1820 is fixed.
81 */
82 public _FacesContextWrapper(FacesContext facesContext, boolean install)
83 {
84 _facesContext = facesContext;
85
86 if (install)
87 {
88 FacesContext.setCurrentInstance(this);
89 }
90 }
91
92 //~ Non-Final Methods -----------------------------------------------------
93
94 public void release()
95 {
96 _facesContext.release();
97 }
98
99 //~ Final Methods ---------------------------------------------------------
100
101 public final Application getApplication()
102 {
103 return _facesContext.getApplication();
104 }
105
106 public final Iterator getClientIdsWithMessages()
107 {
108 return _facesContext.getClientIdsWithMessages();
109 }
110
111 public final ExternalContext getExternalContext()
112 {
113 return _facesContext.getExternalContext();
114 }
115
116 public final FacesMessage.Severity getMaximumSeverity()
117 {
118 return _facesContext.getMaximumSeverity();
119 }
120
121 public final Iterator getMessages()
122 {
123 return _facesContext.getMessages();
124 }
125
126 public final Iterator getMessages(String clientId)
127 {
128 return _facesContext.getMessages(clientId);
129 }
130
131 public final RenderKit getRenderKit()
132 {
133 return _facesContext.getRenderKit();
134 }
135
136 public final boolean getRenderResponse()
137 {
138 return _facesContext.getRenderResponse();
139 }
140
141 public final boolean getResponseComplete()
142 {
143 return _facesContext.getResponseComplete();
144 }
145
146 public final void setResponseStream(ResponseStream responsestream)
147 {
148 _facesContext.setResponseStream(responsestream);
149 }
150
151 public final ResponseStream getResponseStream()
152 {
153 return _facesContext.getResponseStream();
154 }
155
156 public final void setResponseWriter(ResponseWriter responsewriter)
157 {
158 _facesContext.setResponseWriter(responsewriter);
159 }
160
161 public final ResponseWriter getResponseWriter()
162 {
163 return _facesContext.getResponseWriter();
164 }
165
166 public final void setViewRoot(UIViewRoot viewRoot)
167 {
168 _facesContext.setViewRoot(viewRoot);
169 }
170
171 public final UIViewRoot getViewRoot()
172 {
173 return _facesContext.getViewRoot();
174 }
175
176 public final void addMessage(String clientId, FacesMessage message)
177 {
178 _facesContext.addMessage(clientId, message);
179 }
180
181 public final void renderResponse()
182 {
183 _facesContext.renderResponse();
184 }
185
186 public final void responseComplete()
187 {
188 _facesContext.responseComplete();
189 }
190
191 /**
192 * Implement getELContext by delegating call to another instance.
193 */
194 public final ELContext getELContext()
195 {
196 return _facesContext.getELContext();
197 }
198 }