org.apache.turbine.services.session
Class SessionTool

java.lang.Object
  extended byorg.apache.turbine.services.session.SessionTool
All Implemented Interfaces:
ApplicationTool

public class SessionTool
extends java.lang.Object
implements ApplicationTool

A pull tool for accessing the SessionService from a velocity template.

Version:
$Id: SessionTool.java 534527 2007-05-02 16:10:59Z tv $
Author:
Quinton McCombs

Constructor Summary
SessionTool()
           
 
Method Summary
 void addSession(javax.servlet.http.HttpSession session)
          Adds a session to the current list.
 java.util.Collection getActiveSessions()
          Gets a list of the active sessions
 java.util.Collection getActiveUsers()
          Gets a collection of all user objects representing the users currently logged in.
 java.util.Collection getSessionsForUser(User user)
          Get a collection of all session on which the given user is logged in.
 User getUserFromSession(javax.servlet.http.HttpSession session)
          Gets the User object of the the specified HttpSession.
 void init(java.lang.Object o)
          Initialize the application tool.
 boolean isUserLoggedIn(User user)
          Determines if a given user is currently logged in.
 void refresh()
          Refresh the application tool.
 void removeSession(javax.servlet.http.HttpSession session)
          Removes a session from the current list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionTool

public SessionTool()
Method Detail

init

public void init(java.lang.Object o)
Description copied from interface: ApplicationTool
Initialize the application tool. The data parameter holds a different type depending on how the tool is being instantiated:

It is possible that session scope tools will be initialized with a null User object. This happens when the first request on a session happens to the be login action.

If your session tool depends on having a User object, you should look at implementing the RunDataApplicationTool interface instead.

Specified by:
init in interface ApplicationTool
Parameters:
o - initialization data

refresh

public void refresh()
Description copied from interface: ApplicationTool
Refresh the application tool. This is necessary for development work where you probably want the tool to refresh itself if it is using configuration information that is typically cached after initialization

Specified by:
refresh in interface ApplicationTool

getActiveSessions

public java.util.Collection getActiveSessions()
Gets a list of the active sessions

Returns:
List of HttpSession objects

addSession

public void addSession(javax.servlet.http.HttpSession session)
Adds a session to the current list. This method should only be called by the listener.

Parameters:
session - Session to add

removeSession

public void removeSession(javax.servlet.http.HttpSession session)
Removes a session from the current list. This method should only be called by the listener.

Parameters:
session - Session to remove

isUserLoggedIn

public boolean isUserLoggedIn(User user)
Determines if a given user is currently logged in. The actual implementation of the User object must implement the equals() method. By default, Torque based objects (liek TurbineUser) have an implementation of equals() that will compare the result of getPrimaryKey().

Parameters:
user - User to check for
Returns:
true if the user is logged in on one of the active sessions.

getActiveUsers

public java.util.Collection getActiveUsers()
Gets a collection of all user objects representing the users currently logged in. This will exclude any instances of anonymous user that Turbine will use before the user actually logs on.

Returns:
collection of org.apache.turbine.om.security.User objects

getUserFromSession

public User getUserFromSession(javax.servlet.http.HttpSession session)
Gets the User object of the the specified HttpSession.

Parameters:
session -
Returns:

getSessionsForUser

public java.util.Collection getSessionsForUser(User user)
Get a collection of all session on which the given user is logged in.

Parameters:
user - the user
Returns:
Collection of HtttSession objects


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