001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.chain.web.faces;
018
019
020 import java.util.Map;
021 import javax.faces.context.FacesContext;
022 import org.apache.commons.chain.web.WebContext;
023
024
025 /**
026 * <p>Concrete implementation of {@link WebContext} suitable for use in
027 * JavaServer Faces apps. The abstract methods are mapped to the appropriate
028 * collections of the underlying <code>FacesContext</code> instance
029 * that is passed to the constructor (or the initialize method).</p>
030 *
031 * @author Craig R. McClanahan
032 * @version $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
033 */
034
035 public class FacesWebContext extends WebContext {
036
037
038 // ------------------------------------------------------------ Constructors
039
040
041 /**
042 * <p>Construct an uninitialized {@link FacesWebContext} instance.</p>
043 */
044 public FacesWebContext() {
045 }
046
047
048 /**
049 * <p>Construct a {@link FacesWebContext} instance that is initialized
050 * with the specified JavaServer Faces API objects.</p>
051 *
052 * @param context The <code>FacesContext</code> for this request
053 */
054 public FacesWebContext(FacesContext context) {
055
056 initialize(context);
057
058 }
059
060
061 // ------------------------------------------------------ Instance Variables
062
063
064 /**
065 * <p>The <code>FacesContext</code> instance for the request represented
066 * by this {@link WebContext}.</p>
067 */
068 private FacesContext context = null;
069
070
071 // ---------------------------------------------------------- Public Methods
072
073
074 /**
075 * <p>Return the <code>FacesContext</code> instance for the request
076 * associated with this {@link FacesWebContext}.</p>
077 *
078 * @return The <code>FacesContext</code> for this request
079 */
080 public FacesContext getContext() {
081
082 return (this.context);
083
084 }
085
086
087 /**
088 * <p>Initialize (or reinitialize) this {@link FacesWebContext} instance
089 * for the specified JavaServer Faces API objects.</p>
090 *
091 * @param context The <code>FacesContext</code> for this request
092 */
093 public void initialize(FacesContext context) {
094
095 this.context = context;
096
097 }
098
099
100 /**
101 * <p>Release references to allocated resources acquired in
102 * <code>initialize()</code> of via subsequent processing. After this
103 * method is called, subsequent calls to any other method than
104 * <code>initialize()</code> will return undefined results.</p>
105 */
106 public void release() {
107
108 context = null;
109
110 }
111
112
113
114 // ------------------------------------------------------ WebContext Methods
115
116
117 /**
118 * See the {@link WebContext}'s Javadoc.
119 *
120 * @return Application scope Map.
121 */
122 public Map getApplicationScope() {
123
124 return (context.getExternalContext().getApplicationMap());
125
126 }
127
128
129 /**
130 * See the {@link WebContext}'s Javadoc.
131 *
132 * @return Header values Map.
133 */
134 public Map getHeader() {
135
136 return (context.getExternalContext().getRequestHeaderMap());
137
138 }
139
140
141 /**
142 * See the {@link WebContext}'s Javadoc.
143 *
144 * @return Header values Map.
145 */
146 public Map getHeaderValues() {
147
148 return (context.getExternalContext().getRequestHeaderValuesMap());
149
150 }
151
152
153 /**
154 * See the {@link WebContext}'s Javadoc.
155 *
156 * @return Initialization parameter Map.
157 */
158 public Map getInitParam() {
159
160 return (context.getExternalContext().getInitParameterMap());
161
162 }
163
164
165 /**
166 * See the {@link WebContext}'s Javadoc.
167 *
168 * @return Request parameter Map.
169 */
170 public Map getParam() {
171
172 return (context.getExternalContext().getRequestParameterMap());
173
174 }
175
176
177 /**
178 * See the {@link WebContext}'s Javadoc.
179 *
180 * @return Request parameter Map.
181 */
182 public Map getParamValues() {
183
184 return (context.getExternalContext().getRequestParameterValuesMap());
185
186 }
187
188
189 /**
190 * See the {@link WebContext}'s Javadoc.
191 *
192 * @return Map of Cookies.
193 * @since Chain 1.1
194 */
195 public Map getCookies() {
196
197 return (context.getExternalContext().getRequestCookieMap());
198
199 }
200
201
202 /**
203 * See the {@link WebContext}'s Javadoc.
204 *
205 * @return Request scope Map.
206 */
207 public Map getRequestScope() {
208
209 return (context.getExternalContext().getRequestMap());
210
211 }
212
213
214 /**
215 * See the {@link WebContext}'s Javadoc.
216 *
217 * @return Session scope Map.
218 */
219 public Map getSessionScope() {
220
221 return (context.getExternalContext().getSessionMap());
222
223 }
224
225
226
227 }