org.springframework.richclient.application.session
Class ApplicationSession

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.application.session.ApplicationSession
All Implemented Interfaces:
EventListener, ApplicationListener

public final class ApplicationSession
extends Object
implements ApplicationListener

This object is a singleton that will: act as a storage for session and user variables, registers itself on ApplicationEvents and can be used to monitor changes on the contained variables.

Author:
Jan Hoskens

Field Summary
static String SESSION_ATTRIBUTES
          Property that can be monitored.
static String USER
          Property that can be monitored.
static String USER_ATTRIBUTES
          Property that can be monitored.
 
Method Summary
 void addPropertyChangeListener(String property, PropertyChangeListener listener)
          Register a listener on the specified property.
 void clearSession()
          Clear all session attributes.
 void clearUser()
          Clear all user attributes.
 ApplicationSessionInitializer getApplicationSessionInitializer()
           
 Object getAttribute(String key)
          Get a value from the user OR session attributes map.
 Object getAttribute(String key, Object defaultValue)
          Get a value from the user OR session attributes map.
static ApplicationSession getSession()
          Get the instance: Singleton Pattern.
 Object getSessionAttribute(String key)
          Get a value from the session attributes map.
 Object getSessionAttribute(String key, Object defaultValue)
          Get a value from the session attributes map.
 Object getUserAttribute(String key)
          gets a named attribute of the user associated to this context
 Object getUserAttribute(String key, Object defaultValue)
          Get a value from the user attributes map.
protected  void handleLoginEvent(LoginEvent event)
          When a correct login occurs, read all relevant userinformation into session.
protected  void handleLogoutEvent(LogoutEvent event)
          When a logout occurs, remove all user related information from the session.
 void initializeSession()
          Initialize the session attributes.
 void onApplicationEvent(ApplicationEvent event)
          Handle events that influence the session/user context.
 void removePropertyChangeListener(String property, PropertyChangeListener listener)
          Unregister a listener from the specified property.
 void setApplicationSessionInitializer(ApplicationSessionInitializer applicationSessionInitializer)
          Set an initializer object containing vars/commands and custom init code.
 void setSessionAttribute(String key, Object newValue)
          Add a key/value pair to the session attributes map.
 void setSessionAttributes(Map<String,Object> attributes)
          Add the given key/value pairs to the session attributes.
 void setUserAttribute(String key, Object newValue)
          Add a key/value pair to the user attributes map.
 void setUserAttributes(Map<String,Object> attributes)
          Add the given key/value pairs to the user attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER

public static final String USER
Property that can be monitored.

See Also:
Constant Field Values

USER_ATTRIBUTES

public static final String USER_ATTRIBUTES
Property that can be monitored.

See Also:
Constant Field Values

SESSION_ATTRIBUTES

public static final String SESSION_ATTRIBUTES
Property that can be monitored.

See Also:
Constant Field Values
Method Detail

getSession

public static ApplicationSession getSession()
Get the instance: Singleton Pattern.

Returns:
the ApplicationSession.

onApplicationEvent

public void onApplicationEvent(ApplicationEvent event)
Handle events that influence the session/user context.

Specified by:
onApplicationEvent in interface ApplicationListener

handleLoginEvent

protected void handleLoginEvent(LoginEvent event)
When a correct login occurs, read all relevant userinformation into session.

Parameters:
event - the loginEvent that triggered this handler.

handleLogoutEvent

protected void handleLogoutEvent(LogoutEvent event)
When a logout occurs, remove all user related information from the session.

Parameters:
event - the logoutEvent that triggered this handler.

setApplicationSessionInitializer

public void setApplicationSessionInitializer(ApplicationSessionInitializer applicationSessionInitializer)
Set an initializer object containing vars/commands and custom init code.

Parameters:
applicationSessionInitializer - The application session initializer

getApplicationSessionInitializer

public ApplicationSessionInitializer getApplicationSessionInitializer()
Returns:
the applicationSessionInitializer.

addPropertyChangeListener

public void addPropertyChangeListener(String property,
                                      PropertyChangeListener listener)
Register a listener on the specified property.

Parameters:
property - Property to monitor.
listener - PropertyChangeListener to add.

removePropertyChangeListener

public void removePropertyChangeListener(String property,
                                         PropertyChangeListener listener)
Unregister a listener from the specified property.

Parameters:
property - Property that currently is being monitored.
listener - PropertyChangeListener to remove.

initializeSession

public void initializeSession()
Initialize the session attributes.


getUserAttribute

public Object getUserAttribute(String key)
gets a named attribute of the user associated to this context

Parameters:
key - name of the attribute
Returns:
the attribute value (attribute values are strings)

getUserAttribute

public Object getUserAttribute(String key,
                               Object defaultValue)
Get a value from the user attributes map.

Parameters:
key - name of the attribute
defaultValue - a default value to return if no value is found.
Returns:
the attribute value

setUserAttribute

public void setUserAttribute(String key,
                             Object newValue)
Add a key/value pair to the user attributes map.

Parameters:
key - a unique string code.
newValue - the associated value.

setUserAttributes

public void setUserAttributes(Map<String,Object> attributes)
Add the given key/value pairs to the user attributes.

Parameters:
attributes - a map of key/value pairs.

clearUser

public void clearUser()
Clear all user attributes.


getSessionAttribute

public Object getSessionAttribute(String key)
Get a value from the session attributes map.

Parameters:
key - name of the attribute
Returns:
the attribute value

getSessionAttribute

public Object getSessionAttribute(String key,
                                  Object defaultValue)
Get a value from the session attributes map.

Parameters:
key - a unique string code
defaultValue - the default value if not found
Returns:
The session attibute or the default value if not found

setSessionAttribute

public void setSessionAttribute(String key,
                                Object newValue)
Add a key/value pair to the session attributes map.

Parameters:
key - a unique string code.
newValue - the associated value.

setSessionAttributes

public void setSessionAttributes(Map<String,Object> attributes)
Add the given key/value pairs to the session attributes.

Parameters:
attributes - a map of key/value pairs.

clearSession

public void clearSession()
Clear all session attributes.


getAttribute

public Object getAttribute(String key)
Get a value from the user OR session attributes map.

Parameters:
key - name of the attribute
Returns:
the attribute value

getAttribute

public Object getAttribute(String key,
                           Object defaultValue)
Get a value from the user OR session attributes map.

Parameters:
key - name of the attribute
defaultValue - a default value to return if no value is found.
Returns:
the attribute value


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.