org.apache.jetspeed.services.statemanager
Class BaseStateManagerService

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitable
      extended byorg.apache.turbine.services.BaseService
          extended byorg.apache.turbine.services.TurbineBaseService
              extended byorg.apache.jetspeed.services.statemanager.BaseStateManagerService
All Implemented Interfaces:
org.apache.turbine.services.Initable, org.apache.turbine.services.Service, StateManagerService
Direct Known Subclasses:
JetspeedHttpStateManagerService, JetspeedStateManagerService

public abstract class BaseStateManagerService
extends org.apache.turbine.services.TurbineBaseService
implements StateManagerService

BaseStateManagerService is a Turbine Service implementation of the StateManagerService.

Each SessionState is stored in a Map, storing the names and values of the state attributes.

The set of states managed is stored in some specific way by extension classes.

See the proposal: jakarta-jetspeed/proposals/StateManager.txt for more details.

Version:
$Revision: 1.5 $
Author:
Glenn R. Golden
See Also:
StateManagerService, SessionState

Field Summary
protected  java.util.Map m_httpSessions
          map of thread to http session for that thread.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.jetspeed.services.statemanager.StateManagerService
SERVICE_NAME
 
Fields inherited from interface org.apache.turbine.services.Service
SERVICE_NAME
 
Constructor Summary
BaseStateManagerService()
           
 
Method Summary
protected abstract  void addState(java.lang.String key, java.util.Map state)
          Add a new state to the states we are managing.
protected  void bindAttributeValue(java.lang.String stateKey, java.lang.String attributeName, java.lang.Object attribute)
          If the object is a SessionStateBindingListener, bind it
 void clear(java.lang.String key)
          Remove all state attribute of the keyed state.
 void clearCurrentContext()
          Clear the "current context for this thread - Call at the end of each request, balanced with calls to setCurrentContext()
 java.lang.Object getAttribute(java.lang.String key, java.lang.String name)
          Access the named attribute of the keyed state.
 java.lang.String[] getAttributeNames(java.lang.String key)
          Access an array of all names of attributes stored in the keyed state.
 SessionState getCurrentSessionState()
          Access the SessionState object associated with the current request's http session.
 SessionState getCurrentSessionState(java.lang.String key)
          Access the SessionState object associated with the current request's http session with the given key.
 SessionState getSessionState(java.lang.String key)
          Access an SessionState object with the given key.
protected abstract  java.util.Map getState(java.lang.String key)
          Access the Map which is the set of attributes for a state.
protected abstract  java.lang.String[] getStateKeys(java.lang.String start)
          Access an array of the keys of all states managed, those that start with the parameter.
 void init()
          Performs late initialization.
 void init(org.apache.turbine.util.RunData data)
          Performs early initialization.
 void init(javax.servlet.ServletConfig config)
          Performs early initialization.
protected abstract  void initStates()
          Initialize the states storage.
 void removeAttribute(java.lang.String key, java.lang.String name)
          Remove the named state attribute of the keyed state, if it exists.
protected abstract  void removeState(java.lang.String key)
          Remove a state from the states we are managing.
protected  void retireAttributes(java.lang.String key, java.util.Map state)
          retire the attributes of the state.
 void retireState(java.lang.String keyStart)
          Retire, forget about and clean up all states that start with the given key.
 void setAttribute(java.lang.String key, java.lang.String name, java.lang.Object value)
          Set the named state attribute of the keyed state with the provided object.
 void setCurrentContext(javax.servlet.http.HttpSession session)
          Set the "current" context for this thread - Call this at the start of each request, and call %%% at the end.
 void shutdown()
          Returns to uninitialized state.
protected abstract  void shutdownStates()
          Cleanup the states storage.
protected  void unBindAttributeValue(java.lang.String stateKey, java.lang.String attributeName, java.lang.Object attribute)
          If the object is a SessionStateBindingListener, unbind it
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, setInitableBroker
 

Field Detail

m_httpSessions

protected java.util.Map m_httpSessions
map of thread to http session for that thread.

Constructor Detail

BaseStateManagerService

public BaseStateManagerService()
Method Detail

initStates

protected abstract void initStates()
Initialize the states storage.


shutdownStates

protected abstract void shutdownStates()
Cleanup the states storage.


getState

protected abstract java.util.Map getState(java.lang.String key)
Access the Map which is the set of attributes for a state.

Parameters:
key - The state key.
Returns:
The Map which is the set of attributes for a state.

addState

protected abstract void addState(java.lang.String key,
                                 java.util.Map state)
Add a new state to the states we are managing.

Parameters:
key - The state key.
state - The Map which is the set of attributes for the state.

removeState

protected abstract void removeState(java.lang.String key)
Remove a state from the states we are managing.

Parameters:
key - The state key.

getStateKeys

protected abstract java.lang.String[] getStateKeys(java.lang.String start)
Access an array of the keys of all states managed, those that start with the parameter.

Parameters:
start - The starting string used to select the keys.
Returns:
an array of the keys of all states managed.

retireAttributes

protected void retireAttributes(java.lang.String key,
                                java.util.Map state)
retire the attributes of the state.

Parameters:
key - The state key.
state - The Map of attributes to retire.

unBindAttributeValue

protected void unBindAttributeValue(java.lang.String stateKey,
                                    java.lang.String attributeName,
                                    java.lang.Object attribute)
If the object is a SessionStateBindingListener, unbind it

Parameters:
stateKey - The state key.
attributeName - The attribute name.
attribute - The attribute object

bindAttributeValue

protected void bindAttributeValue(java.lang.String stateKey,
                                  java.lang.String attributeName,
                                  java.lang.Object attribute)
If the object is a SessionStateBindingListener, bind it

Parameters:
stateKey - The state key.
attributeName - The attribute name.
attribute - The attribute object

init

public void init(javax.servlet.ServletConfig config)
          throws org.apache.turbine.services.InitializationException
Performs early initialization.

Parameters:
config - A ServletConfing to use for initialization activities.
Throws:
InitializationException, - if initialization of this class was not successful.
org.apache.turbine.services.InitializationException

init

public void init(org.apache.turbine.util.RunData data)
          throws org.apache.turbine.services.InitializationException
Performs early initialization.

Parameters:
data - An RunData to use for initialization activities.
Throws:
InitializationException, - if initialization of this class was not successful.
org.apache.turbine.services.InitializationException

init

public void init()
          throws org.apache.turbine.services.InitializationException
Performs late initialization. If your class relies on early initialization, and the object it expects was not received, you can use late initialization to throw an exception and complain.

Specified by:
init in interface org.apache.turbine.services.Initable
Throws:
InitializationException, - if initialization of this class was not successful.
org.apache.turbine.services.InitializationException

shutdown

public void shutdown()
Returns to uninitialized state. You can use this method to release resources thet your Service allocated when Turbine shuts down.

Specified by:
shutdown in interface org.apache.turbine.services.Initable

getAttribute

public java.lang.Object getAttribute(java.lang.String key,
                                     java.lang.String name)
Access the named attribute of the keyed state.

Specified by:
getAttribute in interface StateManagerService
Parameters:
key - The state key.
name - The attribute name.
Returns:
The named attribute value of the keyed state.

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.String name,
                         java.lang.Object value)
Set the named state attribute of the keyed state with the provided object.

Specified by:
setAttribute in interface StateManagerService
Parameters:
key - The state key.
name - The attribute name.
value - The new value of the attribute (any object type).

removeAttribute

public void removeAttribute(java.lang.String key,
                            java.lang.String name)
Remove the named state attribute of the keyed state, if it exists.

Specified by:
removeAttribute in interface StateManagerService
Parameters:
key - The state key.
name - The attribute name.

clear

public void clear(java.lang.String key)
Remove all state attribute of the keyed state.

Specified by:
clear in interface StateManagerService
Parameters:
key - The state key.

getAttributeNames

public java.lang.String[] getAttributeNames(java.lang.String key)
Access an array of all names of attributes stored in the keyed state.

Specified by:
getAttributeNames in interface StateManagerService
Parameters:
key - The state key.
Returns:
An array of all names of attributes stored in the keyed state.

getSessionState

public SessionState getSessionState(java.lang.String key)
Access an SessionState object with the given key.

Specified by:
getSessionState in interface StateManagerService
Parameters:
key - The SessionState key.
Returns:
an SessionState object with the given key.

getCurrentSessionState

public SessionState getCurrentSessionState()
Access the SessionState object associated with the current request's http session. The session id is used as the key.

Specified by:
getCurrentSessionState in interface StateManagerService
Returns:
an SessionState object associated with the current request's http session.

getCurrentSessionState

public SessionState getCurrentSessionState(java.lang.String key)
Access the SessionState object associated with the current request's http session with the given key.

Specified by:
getCurrentSessionState in interface StateManagerService
Parameters:
key - The string to add to the session id to form the SessionState key.
Returns:
an SessionState object associated with the current request's http session with the given key.

retireState

public void retireState(java.lang.String keyStart)
Retire, forget about and clean up all states that start with the given key.

Specified by:
retireState in interface StateManagerService
Parameters:
keyStart - The beginning of the key of the states to clean up.

setCurrentContext

public void setCurrentContext(javax.servlet.http.HttpSession session)
Set the "current" context for this thread - Call this at the start of each request, and call %%% at the end. getCurrentSession() uses this for the session state key.

Specified by:
setCurrentContext in interface StateManagerService
Parameters:
session - the HttpSession of the current request.

clearCurrentContext

public void clearCurrentContext()
Clear the "current context for this thread - Call at the end of each request, balanced with calls to setCurrentContext()

Specified by:
clearCurrentContext in interface StateManagerService


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