View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.context.servlet;
20  
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import javax.faces.application.FacesMessage;
25  import javax.faces.context.ExceptionHandler;
26  import javax.faces.context.ExternalContext;
27  import javax.faces.context.PartialViewContext;
28  import javax.faces.context.ResponseStream;
29  import javax.faces.context.ResponseWriter;
30  import javax.faces.event.PhaseId;
31  
32  import org.apache.myfaces.context.ReleaseableExternalContext;
33  
34  /**
35   * A FacesContext implementation which will be set as the current instance
36   * during container startup and shutdown and which provides a basic set of
37   * FacesContext functionality.
38   * 
39   * @author Jakob Korherr (latest modification by $Author$)
40   * @version $Revision$ $Date$
41   */
42  public class StartupFacesContextImpl extends FacesContextImplBase
43  {
44      
45      public static final String EXCEPTION_TEXT = "This method is not supported during ";
46  
47      private boolean _startup;
48      
49      public StartupFacesContextImpl(
50              ExternalContext externalContext, 
51              ReleaseableExternalContext defaultExternalContext,
52              ExceptionHandler exceptionHandler,
53              boolean startup)
54      {
55          // setCurrentInstance is called in constructor of super class
56          super(externalContext, defaultExternalContext);
57          
58          _startup = startup;
59          setExceptionHandler(exceptionHandler);
60      }
61  
62      // ~ Methods which are valid by spec to be called during startup and shutdown------
63      
64      // public final UIViewRoot getViewRoot() implemented in super-class
65      // public void release() implemented in super-class
66      // public final ExternalContext getExternalContext() implemented in super-class
67      // public Application getApplication() implemented in super-class
68      // public boolean isProjectStage(ProjectStage stage) implemented in super-class
69      
70      // ~ Methods which can be called during startup and shutdown, but are not
71      //   officially supported by the spec--------------------------------------
72      
73      // all other methods on FacesContextImplBase
74      
75      // ~ Methods which are unsupported during startup and shutdown-------------
76  
77      @Override
78      public final FacesMessage.Severity getMaximumSeverity()
79      {
80          assertNotReleased();
81          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
82      }
83      
84      @Override
85      public List<FacesMessage> getMessageList()
86      {
87          assertNotReleased();
88          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
89      }
90  
91      @Override
92      public List<FacesMessage> getMessageList(String clientId)
93      {
94          assertNotReleased();
95          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
96      }
97  
98      @Override
99      public final Iterator<FacesMessage> getMessages()
100     {
101         assertNotReleased();
102         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
103     }
104     
105     
106     @Override
107     public final Iterator<String> getClientIdsWithMessages()
108     {
109         assertNotReleased();
110         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
111     }
112 
113     @Override
114     public final Iterator<FacesMessage> getMessages(final String clientId)
115     {
116         assertNotReleased();
117         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
118     }
119 
120     @Override
121     public final void addMessage(final String clientId, final FacesMessage message)
122     {
123         assertNotReleased();
124         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
125     }
126 
127     @Override
128     public PartialViewContext getPartialViewContext()
129     {
130         assertNotReleased();
131         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
132     }
133     
134     @Override
135     public boolean isPostback()
136     {
137         assertNotReleased();
138         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
139     }
140     
141     @Override
142     public void validationFailed()
143     {
144         assertNotReleased();
145         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
146     }
147 
148     @Override
149     public boolean isValidationFailed()
150     {
151         assertNotReleased();
152         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
153     }
154 
155     @Override
156     public final void renderResponse()
157     {
158         assertNotReleased();
159         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
160     }
161 
162     @Override
163     public final void responseComplete()
164     {
165         assertNotReleased();
166         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
167     }
168 
169     @Override
170     public PhaseId getCurrentPhaseId()
171     {
172         assertNotReleased();
173         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
174     }
175    
176     @Override
177     public void setCurrentPhaseId(PhaseId currentPhaseId)
178     {
179         assertNotReleased();
180         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
181     }
182         
183     @Override
184     public final boolean getRenderResponse()
185     {
186         assertNotReleased();
187         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
188     }
189 
190     @Override
191     public final boolean getResponseComplete()
192     {
193         assertNotReleased();
194         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
195     }
196 
197     @Override
198     public final void setResponseStream(final ResponseStream responseStream)
199     {
200         assertNotReleased();
201         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
202     }
203 
204     @Override
205     public final ResponseStream getResponseStream()
206     {
207         assertNotReleased();
208         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
209     }
210 
211     @Override
212     public final void setResponseWriter(final ResponseWriter responseWriter)
213     {
214         assertNotReleased();
215         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
216     }
217 
218     @Override
219     public final ResponseWriter getResponseWriter()
220     {
221         assertNotReleased();
222         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
223     }
224     
225     // ~ private Methods ------------------------------------------------------
226     
227     /**
228      * Returns startup or shutdown as String according to the field _startup.
229      * @return
230      */
231     private String _getTime()
232     {
233         return _startup ? "startup" : "shutdown";
234     }
235     
236 }