|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.billpringle.utils.WrpSession
public class WrpSession
This class encapsulates a singleton session object.
This is a singleton class that should be created using the static method WrpSession.initInstance() when a user authenticates with the system. Any subsequent calls to WrpSession.initInstance() will be ignored.
After that, a method can test to determine if the session has expired by calling the static WrpSession.getUserId() method, which will return -1 if expired, or the user ID that was passed to WrpSession.initInstance() at creation time.
This class also provides a HashMap for storing session level objects. The HashMap is defined using a key string and an object value, so any Java object (including arrays and complex objects) can be stored by one method and retrieved by another method.
© 2011 by Bill Pringle, all rights reserved.
Field Summary | |
---|---|
private static WrpSession |
ref
the actual singleton object |
private static java.util.HashMap<java.lang.String,java.lang.Object> |
sessionMap
HashMap for storing session information |
private static int |
userId
the user id for session - initialized |
Constructor Summary | |
---|---|
private |
WrpSession()
Private constructor to prevent multiple instances. |
Method Summary | |
---|---|
java.lang.Object |
clone()
|
static WrpSession |
getInstance()
Get the singleton instance. |
static java.lang.Object |
getMap(java.lang.String key)
Get session attribute. |
static int |
getUserid()
|
static WrpSession |
initInstance(int userId)
Initialize the singleton. |
static java.lang.Object |
setMap(java.lang.String key,
java.lang.Object value)
Store a session attribute. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static WrpSession ref
private static int userId
private static java.util.HashMap<java.lang.String,java.lang.Object> sessionMap
Constructor Detail |
---|
private WrpSession()
Method Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public static WrpSession getInstance()
public static WrpSession initInstance(int userId)
userId
- the current logged-in user IDpublic static int getUserid()
public static java.lang.Object getMap(java.lang.String key)
key
- attribute namevalue
- attribute valuepublic static java.lang.Object setMap(java.lang.String key, java.lang.Object value)
key
- attribute namevalue
- attribute value
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |