wt.session
Class SessionContext

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended bywt.session.SessionContext
All Implemented Interfaces:
Cloneable, Map, Serializable

public class SessionContext
extends Hashtable

A specialized Hashtable for maintaining static context partitioned by user session.

Supported API: true
Extendable: false

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
private  PropertyChangeSupport changeSupport
           
private static String RESOURCE
           
private static SessionCache sessionCache
           
private  String sessionId
           
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
SessionContext()
          Construct a new session context.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
private static void createSessionCache()
           
static void destroy(String prefix, String sessionId)
          Allow more timely expiration of sessions in conjunction with servlet session timeout.
static SessionContext getContext()
          Get current session context.
static SessionContext getContext(boolean authenticate)
          Get current session context.
static SessionContext getContext(String session_id)
          Get the session context corresponding to a given session id.
static SessionContext getContext(String prefix, String sessionId)
          Get current session context using a "prefix" and the JSP/Servlet Session Id as the key.
static WTPrincipal getEffectivePrincipal()
          Get the effective principal object associated with the current thread.
private static SessionCache getSessionCache()
           
 String getSessionId()
          Get the unique session id associated with this context.
static SessionContext newContext()
          Create a new SessionContext object associated with the current thread.
 Object put(Object key, Object value)
          Put a new value in this method context.
 void register()
          Register a session context in the session cache.
 Object remove(Object key)
          Remove a value from this session context.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
static SessionContext setContext(SessionContext session_context)
          Explicitly set the SessionContext object associated with the current thread.
static WTPrincipal setEffectivePrincipal(WTPrincipal principal)
          Set the effective principal object associated with the current thread.
(package private)  Object updateEntry(Object key, Object value)
          Put a new value in this session context without re-updating session cache.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

sessionCache

private static SessionCache sessionCache

sessionId

private String sessionId

changeSupport

private transient PropertyChangeSupport changeSupport
Constructor Detail

SessionContext

public SessionContext()
Construct a new session context. The new context is not added to the session cache until register is called. Until registered, there is no unique session id associated with this object.

Supported API: true

Method Detail

getSessionCache

private static SessionCache getSessionCache()

createSessionCache

private static void createSessionCache()

getSessionId

public String getSessionId()
Get the unique session id associated with this context.

Supported API: true

Returns:
the session id

register

public void register()
Register a session context in the session cache.

Supported API: true


getContext

public static SessionContext getContext()
Get current session context. Session context is determined by authentication information in the current Method context. If none exists, an unauthenticated session context will be established.

Supported API: true

Returns:
the session context
See Also:
MethodContext

getContext

public static SessionContext getContext(boolean authenticate)
Get current session context. Session context is determined by authentication information in the current Method context. If none exists, a new session context will be establised, optionally performing user authentication in the process.

Supported API: true

Parameters:
authenticate - perform user authentication if creating a new session context.
Returns:
the session context
See Also:
MethodContext

getContext

public static SessionContext getContext(String session_id)
Get the session context corresponding to a given session id.

Supported API: true

Parameters:
session_id - the session id
Returns:
the corresponging session context or null if not found in the session cache

put

public Object put(Object key,
                  Object value)
Put a new value in this method context. Overrides hashtable.put to update master session cache maintained in the server manager and add property change support.

Supported API: true


remove

public Object remove(Object key)
Remove a value from this session context. Overrides Hashtable.remove to update master session cache maintained in the server manager and add property change support.

Supported API: true


updateEntry

Object updateEntry(Object key,
                   Object value)
Put a new value in this session context without re-updating session cache. This is called by the session cache manager to update the local session context object when remote updates are received.

Supported API: true


setContext

public static SessionContext setContext(SessionContext session_context)
Explicitly set the SessionContext object associated with the current thread. This method will typically be used in conjunction with a try/finally block to reset the value later. Setting to null restores the default. For example:
    ...
    SessionContext new_context = ...
    SessionContext previous_context = SessionContext.setContext(new_context);
    try
    {
       SessionMgr.setPrincipal(AdministrativeDomainHelper.ADMINISTRATOR_NAME);
       doAdminStuff();
    }
    catch (...)
    {
       ...
    }
    finally
    {
       SessionContext.setContext(previous_context);
    }
 


Supported API: true

Parameters:
session_context - a SessionContext object or null
Returns:
previous value

newContext

public static SessionContext newContext()
Create a new SessionContext object associated with the current thread. This method will typically be used in conjunction with a try/finally block. For example:
    ...
    SessionContext previous_context = SessionContext.newContext();
    try
    {
       SessionMgr.setPrincipal(AdministrativeDomainHelper.ADMINISTRATOR_NAME);
       doAdminStuff();
    }
    catch (...)
    {
       ...
    }
    finally
    {
       SessionContext.setContext(previous_context);
    }
 


Supported API: true

Returns:
previous value

setEffectivePrincipal

public static WTPrincipal setEffectivePrincipal(WTPrincipal principal)
Set the effective principal object associated with the current thread. The effective principal is used for access control checks. If not explicitly set, access control will use the session principal. Setting to null restores the default.

This method will typically be used in conjunction with a try/finally block to reset the value later. For example:

    ...
    WTPrincipal principal = ...
    WTPrincipal previous = SessionContext.setEffectivePrincipal(principal);
    try
    {
       // Do special stuff
    }
    catch (...)
    {
       ...
    }
    finally
    {
       SessionContext.setEffectivePrincipal(previous);
    }
 


Supported API: true

Parameters:
principal - a WTPrincipal object or null
Returns:
previous value

getEffectivePrincipal

public static WTPrincipal getEffectivePrincipal()
Get the effective principal object associated with the current thread. If the effective principal has not explicitly been set, null is returned.

Supported API: true

Returns:
Principal object or null if not set.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. Property change events will be fired to all registered listeners whenever a value in this hashtable is added, changed, or removed.

Supported API: true

Parameters:
listener - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.

Supported API: true

Parameters:
listener - the PropertyChangeListener to be removed

getContext

public static SessionContext getContext(String prefix,
                                        String sessionId)
Get current session context using a "prefix" and the JSP/Servlet Session Id as the key.

Supported API: true

Parameters:
prefix - used guarentee uniqueness to the key
sessionId - session id of the JSP/Servlet engine calling the method server
Returns:
the session context
See Also:
MethodContext

destroy

public static void destroy(String prefix,
                           String sessionId)
Allow more timely expiration of sessions in conjunction with servlet session timeout.

Parameters:
prefix - used guarentee uniqueness to the key
sessionId - session id of the JSP/Servlet engine calling the method server