Expresso 5-6

com.jcorporate.expresso.core.misc
Class CurrentLogin

java.lang.Object
  extended bycom.jcorporate.expresso.core.misc.CurrentLogin
All Implemented Interfaces:
EventListener, HttpSessionBindingListener, Serializable

public class CurrentLogin
extends Object
implements HttpSessionBindingListener, Serializable

Bean that stores current login info in session; implements session binding listener so that it can hear when session is terminated. This class be overriden and replaced with subclass by adding a line to expresso-config.xml under 'class-handlers', like class-handler name="CurrentLogin" classHandler="my.subclass.of.CurrentLogin" This override will allow custom handling in the session bind/unbind events.

Since:
Expresso 4.0
Author:
Michael Nash; Larry Hamel (CodeGuild)
See Also:
Serialized Form

Field Summary
static String LOGIN_KEY
          The session key that we can use to get the currentlogin from a person's session.
 
Constructor Summary
CurrentLogin()
          Default constructor.
CurrentLogin(String newSessionId, String newUserName, String newIPAddress, String newDataContext, long newLoggedInAt, int newUid)
          Deprecated. use newInstance() instead; 9/04 v5.5+
 
Method Summary
 void addMessage(String newMessage)
          Add message to the current login.
 ArrayList getAndClearMessages()
          Gets the current messages associated with this current login and then automatically removes them.
 Object getAttribute(String key)
          Get an attribute stored in hashtable in session.
 String getDBName()
          Bean method that gets the current database name.
 String getIPAddress()
           
static org.apache.log4j.Logger getLogger()
          Loads the Log4j Logger if necessary.
 long getLogInTime()
           
 String getSessionId()
          Bean method that gets the session id.
 int getUid()
          Bean method that gets the current uid.
 String getUserName()
          Bean method that gets the currently logged in user name.
static CurrentLogin newInstance(String newUserName, String newIPAddress, String dataContext, int newUid)
          Object construction.
static CurrentLogin newInstance(String newSessionId, String newUserName, String newIPAddress, String dataContext, long newLoggedInAt, int newUid)
          Deprecated. use other newInstance instead; 9/04 v.5.5+
 void removeAttribute(String key)
          Remove an attribute stored in hashtable in session.
 void setAttribute(String key, Object attribute)
          Set an attribute stored in hashtable in session.
 void setDBName(String newDBName)
          Bean method that setse the database context name for the login.
 void setIpAddress(String theIpAddress)
          Convenience setter.
 void setLoggedInAt(long loggedInAt)
          Convenience setter.
 void setSessionId(String theSessionId)
          Convenience setter.
 void setUid(int theUid)
          Convenience setter.
 void setUserName(String newUserName)
          Bean method that sets the user name for the login.
 void valueBound(HttpSessionBindingEvent evt)
          This class listens to the binding of this object to the session.
 void valueUnbound(HttpSessionBindingEvent evt)
          This class listens to the unbinding of this object to the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGIN_KEY

public static final String LOGIN_KEY
The session key that we can use to get the currentlogin from a person's session.

See Also:
Constant Field Values
Constructor Detail

CurrentLogin

public CurrentLogin(String newSessionId,
                    String newUserName,
                    String newIPAddress,
                    String newDataContext,
                    long newLoggedInAt,
                    int newUid)
Deprecated. use newInstance() instead; 9/04 v5.5+

Old constructor

Parameters:
newSessionId - the session id as returned by the servlet container
newUserName - the user login name
newIPAddress - the user's ip address
newDataContext - the data context for the login
newLoggedInAt - the time the user logged in
newUid - the new user id

CurrentLogin

public CurrentLogin()
Default constructor.

Method Detail

getLogger

public static org.apache.log4j.Logger getLogger()
Loads the Log4j Logger if necessary.

Returns:
Logger instance.

addMessage

public void addMessage(String newMessage)
Add message to the current login.

Parameters:
newMessage - The New Message.

getAndClearMessages

public ArrayList getAndClearMessages()
Gets the current messages associated with this current login and then automatically removes them.

Returns:
ArrayList of messages.

setUserName

public void setUserName(String newUserName)
Bean method that sets the user name for the login.

Parameters:
newUserName - the new user name.

setDBName

public void setDBName(String newDBName)
Bean method that setse the database context name for the login.

Parameters:
newDBName - the database context.

getSessionId

public String getSessionId()
Bean method that gets the session id.

Returns:
java.lang.String the server's session id

getUserName

public String getUserName()
Bean method that gets the currently logged in user name.

Returns:
java.lang.String

getUid

public int getUid()
Bean method that gets the current uid.

Returns:
integer

getDBName

public String getDBName()
Bean method that gets the current database name.

Returns:
java.lang.String

getIPAddress

public String getIPAddress()

getLogInTime

public long getLogInTime()

valueBound

public void valueBound(HttpSessionBindingEvent evt)
This class listens to the binding of this object to the session. Can be overriden, but be sure to call this super method.

Specified by:
valueBound in interface HttpSessionBindingListener
Parameters:
evt - The HttpSession Binding Event.

valueUnbound

public void valueUnbound(HttpSessionBindingEvent evt)
This class listens to the unbinding of this object to the session. Clears this login object from the config system. Can be overriden, but be sure to call this super method.

Specified by:
valueUnbound in interface HttpSessionBindingListener
Parameters:
evt - The HttpSessionBindingEvent that is the source.

newInstance

public static CurrentLogin newInstance(String newUserName,
                                       String newIPAddress,
                                       String dataContext,
                                       int newUid)
Object construction. Constructs a new instance of a Current login. This function will allow pluggable CurrentLogins

Parameters:
newUserName - the user name of the person logging in
newIPAddress - the client ip address
dataContext - the data context to log into.
newUid - The new user id.
Returns:
The constructed CurrentLogin instance

newInstance

public static CurrentLogin newInstance(String newSessionId,
                                       String newUserName,
                                       String newIPAddress,
                                       String dataContext,
                                       long newLoggedInAt,
                                       int newUid)
Deprecated. use other newInstance instead; 9/04 v.5.5+

Object construction. Constructs a new instance of a Current login. This function will allow pluggable CurrentLogins

Parameters:
newSessionId - the servlet session id
newUserName - the user name of the person logging in
newIPAddress - the client ip address
dataContext - the data context to log into.
newLoggedInAt - system time that the person logged in.
newUid - The new user id.
Returns:
The constructed CurrentLogin instance

setLoggedInAt

public void setLoggedInAt(long loggedInAt)
Convenience setter.

Parameters:
loggedInAt - timestamp in milliseconds

getAttribute

public Object getAttribute(String key)
Get an attribute stored in hashtable in session.

Parameters:
key - hashkey
Returns:
Object or null if the attribute isn't set.

setAttribute

public void setAttribute(String key,
                         Object attribute)
Set an attribute stored in hashtable in session.

Parameters:
key - hashkey
attribute - to be stored

removeAttribute

public void removeAttribute(String key)
Remove an attribute stored in hashtable in session.

Parameters:
key - hashkey

setIpAddress

public void setIpAddress(String theIpAddress)
Convenience setter.

Parameters:
theIpAddress - address of this login

setUid

public void setUid(int theUid)
Convenience setter.

Parameters:
theUid - user ID of this login

setSessionId

public void setSessionId(String theSessionId)
Convenience setter.

Parameters:
theSessionId - ID of this session

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.