org.jaffa.presentation.portlet.session
Class UserSession

java.lang.Object
  extended byorg.jaffa.presentation.portlet.session.UserSession
All Implemented Interfaces:
EventListener, HttpSessionBindingListener

public class UserSession
extends Object
implements HttpSessionBindingListener

This UserSession Object maintains all the state about the a specific user within the context of the Web Server. This object could be adapted to other context stores (apart from HttpSession) if needed.


Field Summary
static String USER_ATTRIBUTE
          The key used to add the UserSession object to a HTTP Session.
 
Method Summary
 void addComponent(Component comp)
          Adds a component to the internal cache.
 void addImage(String key, byte[] imageContents, String mimeType)
          Adds the image and its mime-type to the UserSession.
 void dropSessionObject(String name)
          Drop a named attribute from the servlet session.
 void finalize()
          This ensures that a cleanup is performed at the time of garbage-collection.
 void garbageCollectIdleComponents(int timeOutMinutes)
          This will perform garbage collection of idle components.
 Component getComponent(String compId)
          Get a Component object based on a componentId from the list of created components that have been created by this user.
 Collection getComponents()
          Added for the administration tool to get data about the components
 HttpSession getHttpSession()
          Added for the administration tool to get data about the session
 byte[] getImageContents(String key)
          Returns the image for the input key.
 String getImageMimeType(String key)
          Returns the image mime-type for the input key.
 String getNextComponentId()
          Returns a new componentId.
 String getSessionId()
          Getter for property sessionId.
 Object getSessionObject(String name)
          Get a named attribute from the servlet session.
 Object getUserData()
          Returns an object that should contain user data useful to the consuming application.
 String getUserHostAddr()
          Get the host address of this user, this is based on the host obtained in the first request that was used to establish the session
 String getUserId()
          Getter for property userId.
static UserSession getUserSession(HttpServletRequest request)
          Get the UserSession object from the servlet session object.
 String getVariation()
          Getter for property variation.
 WidgetCache getWidgetCache(String key)
          Return an existing WidgetCache for the key.
static boolean isUserSession(HttpServletRequest request)
          Is there a user Session?
 boolean isValid()
          Check to see if the UserSession object is valid.
 void kill()
          This function kills the user session object.
 void killAllComponents()
          This function kills all related components.
 void removeComponent(Component comp)
          Remove the component from the internal cache.
 void removeImage(String key)
          Removes the image for the input key.
 void setSessionId(String sessionId)
          Setter for property sessionId.
 void setUserData(Object userData)
          This stores a user reslated object in the frameworks UserSession object.
 void setUserId(String userId)
          Setter for property userId.
 void setVariation(String variation)
          Setter for property variation.
 void showInfo()
          Display all internal Session Info in the System.out stream.
 void valueBound(HttpSessionBindingEvent httpSessionBindingEvent)
          This is invoked, whenever an instance of this class is added to the HttpSession object.
 void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent)
          This is invoked, whenever an instance of this class is removed from the HttpSession object.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_ATTRIBUTE

public static final String USER_ATTRIBUTE
The key used to add the UserSession object to a HTTP Session.

See Also:
Constant Field Values
Method Detail

isUserSession

public static boolean isUserSession(HttpServletRequest request)
Is there a user Session? Returns true if there is a user session.

Parameters:
request - The HTTP request we are processing.
Returns:
true if there is a user session.

getUserSession

public static UserSession getUserSession(HttpServletRequest request)
Get the UserSession object from the servlet session object. If this is the first time this routine is called, a new Session Object will be created and returned. This new object will be added to the session cache, so the next time this is called the same UserSession object will be returned.

Parameters:
request - The HTTP request we are processing.
Returns:
This returns either a new, or a current UserSession object.

getSessionId

public String getSessionId()
Getter for property sessionId.

Returns:
Value of property sessionId.

setSessionId

public void setSessionId(String sessionId)
Setter for property sessionId.

Parameters:
sessionId - New value of property sessionId.

getUserId

public String getUserId()
Getter for property userId.

Returns:
Value of property userId.

setUserId

public void setUserId(String userId)
Setter for property userId.

Parameters:
userId - New value of property userId.

isValid

public boolean isValid()
Check to see if the UserSession object is valid. A UserSession is valid if the userId is not null.

Returns:
true if the userId is not null.

getUserData

public Object getUserData()
Returns an object that should contain user data useful to the consuming application.

Returns:
an object that should contain user data useful to the consuming application.

setUserData

public void setUserData(Object userData)
This stores a user reslated object in the frameworks UserSession object.

Parameters:
userData - This is the application specific object that contains extra user information.

addComponent

public void addComponent(Component comp)
Adds a component to the internal cache.

Parameters:
comp - the component to be added.

getComponent

public Component getComponent(String compId)
Get a Component object based on a componentId from the list of created components that have been created by this user.

Parameters:
compId - the componentId.
Returns:
the Component object based on the componentId.

removeComponent

public void removeComponent(Component comp)
Remove the component from the internal cache.

Parameters:
comp - The component to be removed.

getSessionObject

public Object getSessionObject(String name)
Get a named attribute from the servlet session.

Parameters:
name - The attribute name.
Returns:
The named object from HttpSession associated to the UserSession. Returns null if named obejct is not found.

dropSessionObject

public void dropSessionObject(String name)
Drop a named attribute from the servlet session.

Parameters:
name - The attribute name.

kill

public void kill()
This function kills the user session object. It remove itself from the HttpSession cache. It will kill all related components. It will de-register from the Session Manager. It will null out all internal references.


killAllComponents

public void killAllComponents()
This function kills all related components.


getNextComponentId

public String getNextComponentId()
Returns a new componentId.

Returns:
a new componentId.

getWidgetCache

public WidgetCache getWidgetCache(String key)
Return an existing WidgetCache for the key. Create a new WidgetCache if it doesnt already exist. The key will preferrably be a componentId.

Parameters:
key - The key to be used for the widget cache.
Returns:
a WidgetCache for the key.

getImageContents

public byte[] getImageContents(String key)
Returns the image for the input key. The ImageModel may store the image contents into the UserSession (instead of the local filesystem). The getImage.jsp will then use this method to display the image.

Parameters:
key - The key.
Returns:
the image for the input key.

getImageMimeType

public String getImageMimeType(String key)
Returns the image mime-type for the input key. The ImageModel may store the image contents into the UserSession (instead of the local filesystem). The getImage.jsp will then use this method to display the image.

Parameters:
key - The key.
Returns:
the image mime-type for the input key.

addImage

public void addImage(String key,
                     byte[] imageContents,
                     String mimeType)
Adds the image and its mime-type to the UserSession. The ImageModel may store the image contents into the UserSession (instead of the local filesystem). The getImage.jsp will then use this method to display the image.

Parameters:
key - The key to be used for storing the image.
imageContents - The image.
mimeType - The mime-type.

removeImage

public void removeImage(String key)
Removes the image for the input key.

Parameters:
key - The key.

finalize

public void finalize()
              throws Throwable
This ensures that a cleanup is performed at the time of garbage-collection.

Throws:
Throwable - if any error occurs.

showInfo

public void showInfo()
Display all internal Session Info in the System.out stream.


getHttpSession

public HttpSession getHttpSession()
Added for the administration tool to get data about the session

Returns:
The HttpSession to which this object belongs.

getComponents

public Collection getComponents()
Added for the administration tool to get data about the components

Returns:
The list of components for the user.

getUserHostAddr

public String getUserHostAddr()
Get the host address of this user, this is based on the host obtained in the first request that was used to establish the session

Returns:
host address of this user.

garbageCollectIdleComponents

public void garbageCollectIdleComponents(int timeOutMinutes)
This will perform garbage collection of idle components. Idle components are those components which have had no activity performed in the last 'timeOutMinutes' minutes.

Parameters:
timeOutMinutes - The minutes used to determine idle components.

valueBound

public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent)
This is invoked, whenever an instance of this class is added to the HttpSession object. Currently, this method will do nothing.

Specified by:
valueBound in interface HttpSessionBindingListener
Parameters:
httpSessionBindingEvent - the event that identifies the session.

valueUnbound

public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent)
This is invoked, whenever an instance of this class is removed from the HttpSession object. This can happen by an explicit session.removeAttribute(), or if the HttpSession is invalidated or if the HttpSession times out. It will kill all related components. It will de-register from the Session Manager. It will null out all internal references.

Specified by:
valueUnbound in interface HttpSessionBindingListener
Parameters:
httpSessionBindingEvent - the event that identifies the session.

getVariation

public String getVariation()
Getter for property variation.

Returns:
Value of property variation.

setVariation

public void setVariation(String variation)
Setter for property variation.

Parameters:
variation - New value of property variation.


Copyright © 2002-2004 JAFFA Project.