Top Description Inners Fields Constructors Methods
com.sun.faces.context.flash

public Class ELFlash

extends Flash
Class Inheritance
Static Imports
com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.EnableDistributable, .WebConfiguration.BooleanWebContextInitParameter.ForceAlwaysWriteFlashCookie

How this implementation works

This class is an application singleton. It has one ivar, innerMap. Entries are added to and removed from this map as needed according to how the flash scope is defined in the spec. This implementation never touches the session, nor does it cause the session to be created.

Most of the hairy logic is encapsulated with in the inner class PreviousNextFlashInfoManager. An instance of this class is obtained by calling one of the variants of getCurrentFlashManager(). When the instance is no longer needed for this request, call releaseCurrentFlashManager().

Two very important methods are getPhaseMapForWriting() and getPhaseMapForReading(). These methods are the basis for the Map implementation methods. Methods that need to write to the map use getPhaseMapForWriting(), those that need to read use getPhaseMapForReading(). These methods allow for the laziness that allows us to only incur a cost when the flash is actually written to.

The operation of this class is intimately tied to the request processing lifecycle. Let's break down every run thru the request processing lifecycle into two parts called "previous" and "next". We use the names "previous" and "next" to indicate the persistence and timing of the data that is stored in the flash. Consider two runs through the requset processing lifecle: N and N+1. On request N, there is no "previous" request. On Request N, any writes to the flash that happen during RENDER RESPONSE go to the "next" flash map. This means they are available for the ENTIRE run though the request processing lifecycle on request N+1. Any entries put into the "next" flash map on request N will be expired at the end of request N+1. Now, when we get into request N+1 what was considered "next" on request N, is now called "previous" from the perspective of request N+1. Any reads from the flash during request N+1 come from the "previous" map. Any writes to the flash before RENDER RESPONSE go to the "previous" map. Any writes to the flash during RENDER RESPNOSE go to the "next" map.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private static class
ELFlash.FlashInfo

Encapsulate one of the two maps that back the flash for the current request.

private static enum
private static class
ELFlash.PreviousNextFlashInfoManager

On any given request, there are actually two maps behind the flash.

Field Summary

Modifier and TypeField and Description
public static final String
private final boolean
private static final String
pack-priv static final String
FLASH_ATTRIBUTE_NAME

This constant is used as the key in the application map that stores the singleton ELFlash instance.

pack-priv static final String
FLASH_NOW_REQUEST_KEY

This constant is used as the key the request map used, in the FlashELResolver, to convey the name of the property being accessed via 'now'.

private Map<String, Map<String, Object>>
flashInnerMap

Keys in this map are the string version of sequence numbers obtained via calls to getNewSequenceNumber.

private ByteArrayGuardAESCTR
private static final Logger
private int
private long
pack-priv static final String
PREFIX

These constants are referenced from other source files in this package.

private final AtomicLong
Inherited from javax.faces.context.Flash:
NULL_VALUE

Constructor Summary

AccessConstructor and Description
private
ELFlash(ExternalContext extContext)

Creates a new instance of ELFlash

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
pack-priv void
protected Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.
public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.
public void
doLastPhaseActions(FacesContext context, boolean outgoingResponseIsRedirect)

This is the most magic of methods.

public void
doPostPhaseActions(FacesContext
the FacesContext for this request.
context
)

Implements abstract javax.faces.context.Flash.doPostPhaseActions.

Called after the execution of every lifecycle phase, this method allows implementations to take the necessary actions to provide the Flash scope contract as it applies to the request procesing lifecycle.

public void
doPrePhaseActions(FacesContext
the FacesContext for this request.
context
)

Implements abstract javax.faces.context.Flash.doPrePhaseActions.

Called before the execution of every lifecycle phase, this method allows implementations to take the necessary actions to provide the Flash scope contract as it applies to the request procesing lifecycle.

public Set<Map.Entry<String, Object>>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public Object
get(Object
the key whose associated value is to be returned
key
)

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
private Cookie
getCookie(ExternalContext extContext)

Return the cookie that came from the browser, if any.

private ELFlash.PreviousNextFlashInfoManager
getCurrentFlashManager(Map<Object, Object> contextMap, boolean create)

Called when you need to get access to the flashManager.

private ELFlash.PreviousNextFlashInfoManager
getCurrentFlashManager(FacesContext context, Map<Object, Object> contextMap, Cookie cookie)

Called on the preRestoreView phase if the browser sent us a cookie.

public static Map<String, Object>

Returns:

The flash Map for this session.
getFlash
()

Returns the flash Map for this application.

pack-priv static ELFlash

Returns:

The flash Map for this session.
getFlash
(ExternalContext
the ExternalContext for this request.
extContext
,
boolean
true to create a new instance for this request if necessary; false to return null if there's no instance in the current session.
create
)

pack-priv Map<String, Map<String, Object>>
private static String
private long
private Map<String, Object>
getPhaseMapForReading()

Always return the map for the "previous" request.

private Map<String, Object>
getPhaseMapForWriting()

If the current phase is earlier than RENDER_RESPONSE, return the map for the "previous" request.

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.
pack-priv boolean
public boolean
isKeepMessages()

Implements abstract javax.faces.context.Flash.isKeepMessages.

Return the value of this JavaBeans property for the flash for this session.

public boolean
isRedirect()

Implements abstract javax.faces.context.Flash.isRedirect.

Return the value of this property for the flash for this session.

public void
keep(String
if argument key is the name of an entry previously stored to the flash on this traversal through the lifecycle via a call to putNow, or to a set to the EL expression #{flash.now.<key>}, or to the request Map, to be promoted to the flash as if a call to put() or a set to the expression #{flash.<key>} was being called.
key
)

Implements abstract javax.faces.context.Flash.keep.

Causes a value stored with a previous call to putNow, its EL equivalent, or to the request Map, to be promoted to the flash so that is available on the next traversal through the lifecycle on this session.

public Set<String>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.
private Map<String, Object>
loggingGetPhaseMapForReading(boolean loggingEnabled)

private Map<String, Object>
loggingGetPhaseMapForWriting(boolean loggingEnabled)

private void
public Object
put(String
key with which the specified value is to be associated
key
,
Object
value to be associated with the specified key
value
)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
public void
putAll(Map<? extends String, ?>
mappings to be stored in this map
t
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
public void
putNow(String
the key for this entry
key
,
Object
the value for this entry
value
)

Implements abstract javax.faces.context.Flash.putNow.

Puts a value in the flash so that it can be accessed on this traversal of the lifecycle, rather than on the next traversal.

private void
private void
public Object
remove(Object
key whose mapping is to be removed from the map
key
)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).
private void
removeCookie(ExternalContext extContext, Cookie toRemove)

private boolean
pack-priv void
pack-priv void
private void
setCookie(FacesContext context, ELFlash.PreviousNextFlashInfoManager flashManager, Cookie toSet, boolean forceWrite)

Set the cookie iff the response was not yet committed.

pack-priv void
pack-priv static void
public void
setKeepMessages(boolean
the new value for this property on this session.
newValue
)

Implements abstract javax.faces.context.Flash.setKeepMessages.

Setter for keepMessages JavaBeans property.

public void
setRedirect(boolean
the new value for this property on this session.
newValue
)

Implements abstract javax.faces.context.Flash.setRedirect.

Setting this property to true indicates that the next request on this session will be a redirect.

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Collection<Object>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.