org.mentawai.core
Class SessionContext

java.lang.Object
  extended by org.mentawai.core.SessionContext
All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>, Context

public class SessionContext
extends java.lang.Object
implements Context, java.util.Map<java.lang.String,java.lang.Object>

Encapsulates a HttpSession as a context for Mentawai actions.

Author:
Sergio Oliveira

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
SessionContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Calls getSession(true) to get the session from this request and creates a context for that session.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object getAttribute(java.lang.String name)
          Gets an attribute value associated with the given name.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the HttpServletRequest associated with this context.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the HttpServletResponse associated with this context.
 javax.servlet.http.HttpSession getSession()
          Returns the HttpSession associated with this context.
 boolean hasAttribute(java.lang.String name)
          Returns true is an attribute exists with this name.
 boolean isEmpty()
          The implementation is not efficient as it loops through all session values to calculate the size.
 java.util.Iterator<java.lang.String> keys()
          Return an iterator with all the attribute names in this context.
 java.util.Set<java.lang.String> keySet()
           
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> t)
           
 java.lang.Object remove(java.lang.Object key)
           
 void removeAttribute(java.lang.String name)
          Removes an attribute associated with the given name.
 void reset()
          Resets this context.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets an attribute value associated with the given name.
 int size()
           
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

SessionContext

public SessionContext(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
Calls getSession(true) to get the session from this request and creates a context for that session.

Parameters:
req - The request from where to get the session.
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: Context
Gets an attribute value associated with the given name.

Specified by:
getAttribute in interface Context
Parameters:
name - The name of the attribute.
Returns:
The value of the attribute or null if it doesn't exist.

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from interface: Context
Sets an attribute value associated with the given name. If the attribute already exists, overwrite it.

Specified by:
setAttribute in interface Context
Parameters:
name - The name of the attribute.
value - The value of the attribute.

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: Context
Removes an attribute associated with the given name.

Specified by:
removeAttribute in interface Context
Parameters:
name - The name of the attribute.

reset

public void reset()
Description copied from interface: Context
Resets this context. All values are discarded and a new context is internally created.

Specified by:
reset in interface Context

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the HttpServletRequest associated with this context.

Returns:
The HttpServletRequest associated with this context.

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the HttpServletResponse associated with this context.

Returns:
The HttpServletResponse associated with this context.

getSession

public javax.servlet.http.HttpSession getSession()
Returns the HttpSession associated with this context.

Returns:
The session associated with this context.

keys

public java.util.Iterator<java.lang.String> keys()
Description copied from interface: Context
Return an iterator with all the attribute names in this context.

Specified by:
keys in interface Context
Returns:
an iterator with the attribute names

hasAttribute

public boolean hasAttribute(java.lang.String name)
Description copied from interface: Context
Returns true is an attribute exists with this name.

Specified by:
hasAttribute in interface Context
Parameters:
name - The name of the attribute.
Returns:
true if the attribute exists

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>

isEmpty

public boolean isEmpty()
The implementation is not efficient as it loops through all session values to calculate the size.

Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>

keySet

public java.util.Set<java.lang.String> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> t)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<java.lang.String,java.lang.Object>

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>


Copyright © 2005 Mentawai Team. All Rights Reserved.