org.apache.struts2.dispatcher
Class SessionMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.apache.struts2.dispatcher.SessionMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.util.Map<K,V>

public class SessionMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.io.Serializable

A simple implementation of the Map interface to handle a collection of HTTP session attributes. The entrySet() method enumerates over all session attributes and creates a Set of entries. Note, this will occur lazily - only when the entry set is asked for.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  java.util.Set<java.util.Map.Entry<K,V>> entries
           
protected  javax.servlet.http.HttpServletRequest request
           
protected  javax.servlet.http.HttpSession session
           
 
Constructor Summary
SessionMap(javax.servlet.http.HttpServletRequest request)
          Creates a new session map given a http servlet request.
 
Method Summary
 void clear()
          Removes all attributes from the session as well as clears entries in this map.
 boolean containsKey(java.lang.Object key)
          Checks if the specified session attribute with the given key exists.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns a Set of attributes from the http session.
 V get(java.lang.Object key)
          Returns the session attribute associated with the given key or null if it doesn't exist.
 void invalidate()
          Invalidate the http session.
 V put(K key, V value)
          Saves an attribute in the session.
 V remove(java.lang.Object key)
          Removes the specified session attribute.
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

session

protected javax.servlet.http.HttpSession session

entries

protected java.util.Set<java.util.Map.Entry<K,V>> entries

request

protected javax.servlet.http.HttpServletRequest request
Constructor Detail

SessionMap

public SessionMap(javax.servlet.http.HttpServletRequest request)
Creates a new session map given a http servlet request. Note, ths enumeration of request attributes will occur when the map entries are asked for.

Parameters:
request - the http servlet request object.
Method Detail

invalidate

public void invalidate()
Invalidate the http session.


clear

public void clear()
Removes all attributes from the session as well as clears entries in this map.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.AbstractMap<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns a Set of attributes from the http session.

Specified by:
entrySet in interface java.util.Map<K,V>
Specified by:
entrySet in class java.util.AbstractMap<K,V>
Returns:
a Set of attributes from the http session.

get

public V get(java.lang.Object key)
Returns the session attribute associated with the given key or null if it doesn't exist.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>
Parameters:
key - the name of the session attribute.
Returns:
the session attribute or null if it doesn't exist.

put

public V put(K key,
             V value)
Saves an attribute in the session.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>
Parameters:
key - the name of the session attribute.
value - the value to set.
Returns:
the object that was just set.

remove

public V remove(java.lang.Object key)
Removes the specified session attribute.

Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.AbstractMap<K,V>
Parameters:
key - the name of the attribute to remove.
Returns:
the value that was removed or null if the value was not found (and hence, not removed).

containsKey

public boolean containsKey(java.lang.Object key)
Checks if the specified session attribute with the given key exists.

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>
Parameters:
key - the name of the session attribute.
Returns:
true if the session attribute exits or false if it doesn't exist.


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.