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: 1.5 $ $Date: 2004/02/25 00:01:06 $
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  
49  
50      /***
51       * <p>Construct a {@link FacesWebContext} instance that is initialized
52       * with the specified JavaServer Faces API objects.</p>
53       *
54       * @param context The <code>FacesContext</code> for this request
55       */
56      public FacesWebContext(FacesContext context) {
57  
58          initialize(context);
59  
60      }
61  
62  
63      // ------------------------------------------------------ Instance Variables
64  
65  
66      /***
67       * <p>The <code>FacesContext</code> instance for the request represented
68       * by this {@link WebContext}.</p>
69       */
70      private FacesContext context = null;
71  
72  
73      // ---------------------------------------------------------- Public Methods
74  
75  
76      /***
77       * <p>Return the <code>FacesContext</code> instance for the request
78       * associated with this {@link FacesWebContext}.</p>
79       */
80      public FacesContext getContext() {
81  
82      return (this.context);
83  
84      }
85  
86  
87      /***
88       * <p>Initialize (or reinitialize) this {@link FacesWebContext} instance
89       * for the specified JavaServer Faces API objects.</p>
90       *
91       * @param context The <code>FacesContext</code> for this request
92       */
93      public void initialize(FacesContext context) {
94  
95          this.context = context;
96  
97      }
98  
99  
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     public Map getApplicationScope() {
118 
119     return (context.getExternalContext().getApplicationMap());
120 
121     }
122 
123 
124     public Map getHeader() {
125 
126     return (context.getExternalContext().getRequestHeaderMap());
127 
128     }
129 
130 
131     public Map getHeaderValues() {
132 
133     return (context.getExternalContext().getRequestHeaderValuesMap());
134 
135     }
136 
137 
138     public Map getInitParam() {
139 
140     return (context.getExternalContext().getInitParameterMap());
141 
142     }
143 
144 
145     public Map getParam() {
146 
147     return (context.getExternalContext().getRequestParameterMap());
148 
149     }
150 
151 
152     public Map getParamValues() {
153 
154     return (context.getExternalContext().getRequestParameterValuesMap());
155 
156     }
157 
158 
159     public Map getRequestScope() {
160 
161     return (context.getExternalContext().getRequestMap());
162 
163     }
164 
165 
166     public Map getSessionScope() {
167 
168     return (context.getExternalContext().getSessionMap());
169 
170     }
171 
172 
173 
174 }