KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > context > ServletFacesContextImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.context;
30
31 import java.util.*;
32
33 import javax.el.*;
34
35 import javax.faces.*;
36 import javax.faces.application.*;
37 import javax.faces.context.*;
38 import javax.faces.component.*;
39 import javax.faces.render.*;
40
41 import javax.servlet.*;
42 import javax.servlet.http.*;
43
44 public class ServletFacesContextImpl extends FacesContext
45 {
46   private final FacesContextFactoryImpl _factory;
47
48   private ServletContext _webApp;
49   private HttpServletRequest _request;
50   private HttpServletResponse _response;
51
52   private ExternalContext _externalContext;
53   private FacesELContext _elContext;
54   
55   private boolean _isResponseComplete;
56   private boolean _isRenderResponse;
57   
58   private UIViewRoot _uiViewRoot;
59
60   private ResponseWriter _responseWriter;
61   private ResponseStream _responseStream;
62   
63   ServletFacesContextImpl(FacesContextFactoryImpl factory,
64               ServletContext webApp,
65               HttpServletRequest request,
66               HttpServletResponse response)
67   {
68     _factory = factory;
69
70     _webApp = webApp;
71     _request = request;
72     _response = response;
73   }
74   
75   public Application getApplication()
76   {
77     return _factory.getApplication();
78   }
79
80   public Iterator<String JavaDoc> getClientIdsWithMessages()
81   {
82     throw new UnsupportedOperationException JavaDoc();
83   }
84
85   public ExternalContext getExternalContext()
86   {
87     if (_externalContext == null) {
88       _externalContext
89     = new ServletExternalContext(_webApp, _request, _response);
90     }
91
92     return _externalContext;
93   }
94
95   public FacesMessage.Severity getMaximumSeverity()
96   {
97     throw new UnsupportedOperationException JavaDoc();
98   }
99
100   public Iterator<FacesMessage> getMessages()
101   {
102     throw new UnsupportedOperationException JavaDoc();
103   }
104
105   public Iterator<FacesMessage> getMessages(String JavaDoc clientId)
106   {
107     throw new UnsupportedOperationException JavaDoc();
108   }
109
110   public RenderKit getRenderKit()
111   {
112     UIViewRoot viewRoot = getViewRoot();
113
114     if (viewRoot == null)
115       return null;
116
117     String JavaDoc renderKitId = viewRoot.getRenderKitId();
118
119     if (renderKitId == null)
120       return null;
121
122     RenderKitFactory factory = (RenderKitFactory)
123       FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
124
125     return factory.getRenderKit(this, renderKitId);
126   }
127
128   public ResponseStream getResponseStream()
129   {
130     throw new UnsupportedOperationException JavaDoc();
131   }
132
133   public void setResponseStream(ResponseStream responseStream)
134   {
135     throw new UnsupportedOperationException JavaDoc();
136   }
137
138   public ResponseWriter getResponseWriter()
139   {
140     if (_responseWriter == null) {
141       try {
142     _responseWriter = new ResponseWriterImpl(_response,
143                          _response.getWriter());
144       } catch (RuntimeException JavaDoc e) {
145     throw e;
146       } catch (Exception JavaDoc e) {
147     throw new FacesException(e);
148       }
149     }
150
151     return _responseWriter;
152   }
153
154   public void setResponseWriter(ResponseWriter writer)
155   {
156     _responseWriter = writer;
157   }
158
159   /**
160    * Returns the root of the UI component tree.
161    */

162   public UIViewRoot getViewRoot()
163   {
164     if (_uiViewRoot == null) {
165       _uiViewRoot = getApplication().getViewHandler().createView(this,
166                                  null);
167     }
168     
169     return _uiViewRoot;
170   }
171
172   /**
173    * Sets the root of the UI component tree.
174    */

175   public void setViewRoot(UIViewRoot root)
176   {
177     _uiViewRoot = root;
178   }
179
180   /**
181    * If true the facelet will skip to the render phase.
182    */

183   @Override JavaDoc
184   public boolean getRenderResponse()
185   {
186     return _isRenderResponse;
187   }
188
189   /**
190    * Ask the lifecycle to skip to the render phase.
191    */

192   @Override JavaDoc
193   public void renderResponse()
194   {
195     _isRenderResponse = true;
196   }
197
198   /**
199    * Return true if the lifecycle should skip the response phase.
200    */

201   @Override JavaDoc
202   public boolean getResponseComplete()
203   {
204     return _isResponseComplete;
205   }
206
207   /**
208    * Ask the lifecycle to skip the response phase.
209    */

210   @Override JavaDoc
211   public void responseComplete()
212   {
213     _isResponseComplete = true;
214   }
215
216   public void addMessage(String JavaDoc clientId,
217                   FacesMessage message)
218   {
219     throw new UnsupportedOperationException JavaDoc();
220   }
221
222   /**
223    * @Since 1.2
224    */

225   public ELContext getELContext()
226   {
227     if (_elContext == null)
228       _elContext = new FacesELContext();
229
230     return _elContext;
231   }
232
233   public void release()
234   {
235   }
236 }
237
Popular Tags