View Javadoc

1   /*
2    * Copyright 1999-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.chain.web.faces;
17  
18  
19  import java.util.Map;
20  import javax.faces.context.FacesContext;
21  import org.apache.commons.chain.web.WebContext;
22  
23  
24  /***
25   * <p>Concrete implementation of {@link WebContext} suitable for use in
26   * JavaServer Faces apps.  The abstract methods are mapped to the appropriate
27   * collections of the underlying <code>FacesContext</code> instance
28   * that is passed to the constructor (or the initialize method).</p>
29   *
30   * @author Craig R. McClanahan
31   * @version $Revision: 411948 $ $Date: 2006-06-06 00:29:02 +0100 (Tue, 06 Jun 2006) $
32   */
33  
34  public class FacesWebContext extends WebContext {
35  
36  
37      // ------------------------------------------------------------ Constructors
38  
39  
40      /***
41       * <p>Construct an uninitialized {@link FacesWebContext} instance.</p>
42       */
43      public FacesWebContext() {
44      }
45  
46  
47      /***
48       * <p>Construct a {@link FacesWebContext} instance that is initialized
49       * with the specified JavaServer Faces API objects.</p>
50       *
51       * @param context The <code>FacesContext</code> for this request
52       */
53      public FacesWebContext(FacesContext context) {
54  
55          initialize(context);
56  
57      }
58  
59  
60      // ------------------------------------------------------ Instance Variables
61  
62  
63      /***
64       * <p>The <code>FacesContext</code> instance for the request represented
65       * by this {@link WebContext}.</p>
66       */
67      private FacesContext context = null;
68  
69  
70      // ---------------------------------------------------------- Public Methods
71  
72  
73      /***
74       * <p>Return the <code>FacesContext</code> instance for the request
75       * associated with this {@link FacesWebContext}.</p>
76       *
77       * @return The <code>FacesContext</code> for this request
78       */
79      public FacesContext getContext() {
80  
81      return (this.context);
82  
83      }
84  
85  
86      /***
87       * <p>Initialize (or reinitialize) this {@link FacesWebContext} instance
88       * for the specified JavaServer Faces API objects.</p>
89       *
90       * @param context The <code>FacesContext</code> for this request
91       */
92      public void initialize(FacesContext context) {
93  
94          this.context = context;
95  
96      }
97  
98  
99      /***
100      * <p>Release references to allocated resources acquired in
101      * <code>initialize()</code> of via subsequent processing.  After this
102      * method is called, subsequent calls to any other method than
103      * <code>initialize()</code> will return undefined results.</p>
104      */
105     public void release() {
106 
107         context = null;
108 
109     }
110 
111 
112 
113     // ------------------------------------------------------ WebContext Methods
114 
115 
116     /***
117      * See the {@link WebContext}'s Javadoc.
118      *
119      * @return Application scope Map.
120      */
121     public Map getApplicationScope() {
122 
123     return (context.getExternalContext().getApplicationMap());
124 
125     }
126 
127 
128     /***
129      * See the {@link WebContext}'s Javadoc.
130      *
131      * @return Header values Map.
132      */
133     public Map getHeader() {
134 
135     return (context.getExternalContext().getRequestHeaderMap());
136 
137     }
138 
139 
140     /***
141      * See the {@link WebContext}'s Javadoc.
142      *
143      * @return Header values Map.
144      */
145     public Map getHeaderValues() {
146 
147     return (context.getExternalContext().getRequestHeaderValuesMap());
148 
149     }
150 
151 
152     /***
153      * See the {@link WebContext}'s Javadoc.
154      *
155      * @return Initialization parameter Map.
156      */
157     public Map getInitParam() {
158 
159     return (context.getExternalContext().getInitParameterMap());
160 
161     }
162 
163 
164     /***
165      * See the {@link WebContext}'s Javadoc.
166      *
167      * @return Request parameter Map.
168      */
169     public Map getParam() {
170 
171     return (context.getExternalContext().getRequestParameterMap());
172 
173     }
174 
175 
176     /***
177      * See the {@link WebContext}'s Javadoc.
178      *
179      * @return Request parameter Map.
180      */
181     public Map getParamValues() {
182 
183     return (context.getExternalContext().getRequestParameterValuesMap());
184 
185     }
186 
187 
188     /***
189      * See the {@link WebContext}'s Javadoc.
190      *
191      * @return Map of Cookies.
192      * @since Chain 1.1
193      */
194     public Map getCookies() {
195 
196         return (context.getExternalContext().getRequestCookieMap());
197 
198     }
199 
200 
201     /***
202      * See the {@link WebContext}'s Javadoc.
203      *
204      * @return Request scope Map.
205      */
206     public Map getRequestScope() {
207 
208     return (context.getExternalContext().getRequestMap());
209 
210     }
211 
212 
213     /***
214      * See the {@link WebContext}'s Javadoc.
215      *
216      * @return Session scope Map.
217      */
218     public Map getSessionScope() {
219 
220     return (context.getExternalContext().getSessionMap());
221 
222     }
223 
224 
225 
226 }