org.mentawai.core
Class SessionContext

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

public class SessionContext
extends Object
implements Context, Map<String,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
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.
SessionContext(javax.servlet.http.HttpSession session)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<String,Object>> entrySet()
           
 Object get(Object key)
           
 Object getAttribute(String name)
          Gets an attribute value associated with the given name.
 String getId()
          Get the session ID, internaly is call HttpSession.getId()
 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(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.
 Iterator<String> keys()
          Return an iterator with all the attribute names in this context.
 Set<String> keySet()
           
 Object put(String key, Object value)
           
 void putAll(Map<? extends String,? extends Object> t)
           
 Object remove(Object key)
           
 void removeAttribute(String name)
          Removes an attribute associated with the given name.
 void reset()
          Resets this context.
 void setAttribute(String name, Object value)
          Sets an attribute value associated with the given name.
 int size()
           
 Collection<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.HttpSession session)

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 Object getAttribute(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(String name,
                         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(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

getId

public String getId()
Get the session ID, internaly is call HttpSession.getId()

Returns:
this session ID

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 Iterator<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(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 Map<String,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 Map<String,Object>

containsKey

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

containsValue

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

entrySet

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

get

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

keySet

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

put

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

putAll

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

remove

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

size

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

values

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


Copyright © 2013. All Rights Reserved.