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