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  
23  import javax.faces.application.FacesMessage;
24  import javax.faces.context.ExternalContext;
25  import javax.faces.context.ResponseStream;
26  import javax.faces.context.ResponseWriter;
27  
28  import org.apache.myfaces.context.ReleaseableExternalContext;
29  
30  /**
31   * A FacesContext implementation which will be set as the current instance
32   * during container startup and shutdown and which provides a basic set of
33   * FacesContext functionality.
34   * 
35   * @author Jakob Korherr (latest modification by $Author: jakobk $)
36   * @version $Revision: 963629 $ $Date: 2010-07-13 04:29:07 -0500 (Mar, 13 Jul 2010) $
37   */
38  public class StartupFacesContextImpl extends FacesContextImplBase
39  {
40      
41      public static final String EXCEPTION_TEXT = "This method is not supported during ";
42  
43      private boolean _startup;
44      
45      public StartupFacesContextImpl(
46              ExternalContext externalContext, 
47              ReleaseableExternalContext defaultExternalContext,
48              boolean startup)
49      {
50          // setCurrentInstance is called in constructor of super class
51          super(externalContext, defaultExternalContext);
52          
53          _startup = startup;
54      }
55  
56      // ~ Methods which are valid by spec to be called during startup and shutdown------
57      
58      // public final UIViewRoot getViewRoot() implemented in super-class
59      // public void release() implemented in super-class
60      // public final ExternalContext getExternalContext() implemented in super-class
61      // public Application getApplication() implemented in super-class
62      // public boolean isProjectStage(ProjectStage stage) implemented in super-class
63      
64      // ~ Methods which can be called during startup and shutdown, but are not
65      //   officially supported by the spec--------------------------------------
66      
67      // all other methods on FacesContextImplBase
68      
69      // ~ Methods which are unsupported during startup and shutdown-------------
70  
71      @Override
72      public final FacesMessage.Severity getMaximumSeverity()
73      {
74          assertNotReleased();
75          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
76      }
77      
78      @Override
79      public final Iterator<FacesMessage> getMessages()
80      {
81          assertNotReleased();
82          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
83      }
84      
85      
86      @Override
87      public final Iterator<String> getClientIdsWithMessages()
88      {
89          assertNotReleased();
90          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
91      }
92  
93      @Override
94      public final Iterator<FacesMessage> getMessages(final String clientId)
95      {
96          assertNotReleased();
97          throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
98      }
99  
100     @Override
101     public final void addMessage(final String clientId, final FacesMessage message)
102     {
103         assertNotReleased();
104         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
105     }
106 
107     @Override
108     public final void renderResponse()
109     {
110         assertNotReleased();
111         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
112     }
113 
114     @Override
115     public final void responseComplete()
116     {
117         assertNotReleased();
118         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
119     }
120 
121     @Override
122     public final boolean getRenderResponse()
123     {
124         assertNotReleased();
125         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
126     }
127 
128     @Override
129     public final boolean getResponseComplete()
130     {
131         assertNotReleased();
132         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
133     }
134 
135     @Override
136     public final void setResponseStream(final ResponseStream responseStream)
137     {
138         assertNotReleased();
139         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
140     }
141 
142     @Override
143     public final ResponseStream getResponseStream()
144     {
145         assertNotReleased();
146         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
147     }
148 
149     @Override
150     public final void setResponseWriter(final ResponseWriter responseWriter)
151     {
152         assertNotReleased();
153         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
154     }
155 
156     @Override
157     public final ResponseWriter getResponseWriter()
158     {
159         assertNotReleased();
160         throw new UnsupportedOperationException(EXCEPTION_TEXT + _getTime());
161     }
162     
163     // ~ private Methods ------------------------------------------------------
164     
165     /**
166      * Returns startup or shutdown as String according to the field _startup.
167      * @return
168      */
169     private String _getTime()
170     {
171         return _startup ? "startup" : "shutdown";
172     }
173     
174 }