javax.faces.context.FacesContext Maven / Gradle / Ivy
Show all versions of jsf-api Show documentation
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package javax.faces.context;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.application.ProjectStage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIViewRoot;
import javax.faces.render.RenderKit;
import javax.el.ELContext;
import javax.faces.FactoryFinder;
import javax.faces.component.UINamingContainer;
import javax.faces.event.PhaseId;
/**
* FacesContext contains all of the
* per-request state information related to the processing of a single
* JavaServer Faces request, and the rendering of the corresponding
* response. It is passed to, and potentially modified by, each phase
* of the request processing lifecycle.
*
* A {@link FacesContext} instance is associated with a particular
* request at the beginning of request processing, by a call to the
* getFacesContext()
method of the {@link FacesContextFactory}
* instance associated with the current web application. The instance
* remains active until its release()
method is called, after
* which no further references to this instance are allowed. While a
* {@link FacesContext} instance is active, it must not be referenced
* from any thread other than the one upon which the servlet container
* executing this web application utilizes for the processing of this request.
*
*/
public abstract class FacesContext {
@SuppressWarnings({"UnusedDeclaration"})
private FacesContext defaultFacesContext;
private boolean processingEvents = true;
private boolean isCreatedFromValidFactory = true;
private static ConcurrentHashMap threadInitContext = new ConcurrentHashMap(2);
private static ConcurrentHashMap initContextServletContext = new ConcurrentHashMap(2);
public FacesContext() {
Thread curThread = Thread.currentThread();
StackTraceElement[] callstack = curThread.getStackTrace();
if (null != callstack) {
String declaringClassName = callstack[3].getClassName();
try {
ClassLoader curLoader = curThread.getContextClassLoader();
Class declaringClass = curLoader.loadClass(declaringClassName);
if (!FacesContextFactory.class.isAssignableFrom(declaringClass)) {
isCreatedFromValidFactory = false;
}
} catch (ClassNotFoundException cnfe) {
}
}
}
// -------------------------------------------------------------- Properties
/**
* Return the {@link
* Application} instance associated with this web application.
* It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, returns the correct current {@link
* javax.faces.application.Application} instance.
* @throws IllegalStateException if this method is called after
* this instance has been released
*/
public abstract Application getApplication();
/**
* Return a mutable Map
* representing the attributes associated wth this
* FacesContext
instance. This Map
is
* useful to store attributes that you want to go out of scope when the
* Faces lifecycle for the current request ends, which is not always the same
* as the request ending, especially in the case of Servlet filters
* that are invoked after the Faces lifecycle for this
* request completes. Accessing this Map
does not cause any
* events to fire, as is the case with the other maps: for request, session, and
* application scope. When {@link #release()} is invoked, the attributes
* must be cleared.
*
*
*
* The Map
returned by this method is not associated with
* the request. If you would like to get or set request attributes,
* see {@link ExternalContext#getRequestMap}.
*
*
The default implementation throws
* UnsupportedOperationException
and is provided
* for the sole purpose of not breaking existing applications that extend
* this class.
*
*
*
* @throws IllegalStateException if this method is called after
* this instance has been released
*
* @since 2.0
*/
public Map