/* * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, * version 2 with the GNU Classpath Exception, which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ package javax.faces.context; import java.util.Iterator; import java.util.Map; /** *

FacesContext contains all of the * per-request state information related to the processing of a single * Jakarta Server 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 Jakarta Servlet container * executing this web application utilizes for the processing of this request. *

* *

A FacesContext can be injected into a request * scoped bean using @Inject FacesContext facesContext; *

*/ public abstract class FacesContext { public FacesContext() { } /** *

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 Jakarta 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.

* *
* * @return mutable Map representing the attributes associated wth this * FacesContext instance. * * @throws IllegalStateException if this method is called after * this instance has been released * * @since 2.0 */ public Map getAttributes() { return null; } /** *

Return an Iterator over the client identifiers for * which at least one {@link javax.faces.application.FacesMessage} has been queued. If there are no * such client identifiers, an empty Iterator is returned. * If any messages have been queued that were not associated with any * specific client identifier, a null value will be included * in the iterated values. The elements in the Iterator must * be returned in the order in which they were added with {@link #addMessage}.

* * @return the Iterator over the client identifiers for * which at least one {@link javax.faces.application.FacesMessage} has been queued. * * @throws IllegalStateException if this method is called after * this instance has been released */ public abstract Iterator getClientIdsWithMessages(); /** *

Return the {@link * ExternalContext} instance for this FacesContext * instance.

*

It is valid to call this method * during application startup or shutdown. If called during application * startup or shutdown, this method returns an {@link ExternalContext} instance * with the special behaviors indicated in the javadoc for that * class. Methods document as being valid to call during * application startup or shutdown must be supported.

* * @return instance of ExternalContext * * @throws IllegalStateException if this method is called after * this instance has been released */ public abstract ExternalContext getExternalContext(); /** *

Return the {@link ResponseStream} to which components should * direct their binary output. Within a given response, components * can use either the ResponseStream or the ResponseWriter, * but not both. * * @return ResponseStream instance. * * @throws IllegalStateException if this method is called after * this instance has been released */ public abstract ResponseStream getResponseStream(); /** *

Set the {@link ResponseStream} to which components should * direct their binary output. * * @param responseStream The new ResponseStream for this response * * @throws NullPointerException if responseStream * is null * * @throws IllegalStateException if this method is called after * this instance has been released */ public abstract void setResponseStream(ResponseStream responseStream); /** *

Return the {@link ResponseWriter} to which components should * direct their character-based output. Within a given response, * components can use either the ResponseStream or the ResponseWriter, * but not both.

* * @return ResponseWriter instance. * * @throws IllegalStateException if this method is called after * this instance has been released */ public abstract ResponseWriter getResponseWriter(); /** *

Set the {@link ResponseWriter} to which components should * direct their character-based output. * * @param responseWriter The new ResponseWriter for this response * * @throws IllegalStateException if this method is called after * this instance has been released * @throws NullPointerException if responseWriter * is null */ public abstract void setResponseWriter(ResponseWriter responseWriter); /** *

Return the {@link FacesContext} * instance for the request that is being processed by the current * thread. If called during application initialization or shutdown, * any method documented as "valid to call this method during * application startup or shutdown" must be supported during * application startup or shutdown time. The result of calling a * method during application startup or shutdown time that does not * have this designation is undefined.

* * @return the instance of FacesContext. */ public static FacesContext getCurrentInstance() { return null; } }