Expresso 5-6

com.jcorporate.expresso.core.controller.session
Interface PersistentSession

All Superinterfaces:
Serializable
All Known Implementing Classes:
HTTPPersistentSession, SimplePersistentSession

public interface PersistentSession
extends Serializable

A PersistentSession is simply a place to stash some values between states of a controller object. Different environments may employ different ways of doing this - the simplest being SimplePersistentSession, where a hashtable does all the required work.

The typical way to use a PersistentSession is within a controller object as part of your state handler. You do not instantiate it directly, the controller framework instantiates the appropriate kind of session for you. [Unless you're directly creating a controller yourself, such as in a command line environment, in which case, you would set the session object at say, SimplePersistentSession... if you're getting confused at what is meant by this, ignore it.]

Example Usage:
void protected runMyState(ControllerRequest request, ControllerResponse response) throws ControllerException {
   PersistentSesssion session = request.getSession();
   //Set an attribute that exists only for the current request.
   session.setAttribute("RequestAttribute", "Controller Was Executed");

   //Set an attribute that exists for the entire session
   session.setPersistentAttribute("SessionAttribute","Customer Has Logged In");

   //Set an attribute that persists across requests. [In HTTP sets a cookie]
   session.setClientAttribute("ACookie", "Cookie Data That May Get Encrypted");

Since:
Expresso 4.0
Author:
Michael Nash

Method Summary
 Object getAttribute(String attribName)
          Retrieves the object from the request context.
 Enumeration getAttributeNames()
          Retrieves all attribute names in the request context.
 String getClientAttribute(String attribName)
          Retrieves a value of a cookie set on the client's system.
 Enumeration getPeristentAttributeNames()
          Retrieves all attribute names from the session context.
 Object getPersistentAttribute(String attribName)
          Retrieves the object from the session context.
 void invalidate()
          Clear out the session.
 void removeAttribute(String attribName)
          Clears an attribute from the request context
 void removePersistentAttribute(String attribName)
          Clears an attribute from the session context
 void setAttribute(String attribName, Object attribValue)
          Sets an attribute that is valid for the duration of the request.
 void setClientAttribute(String attribName, String attribValue)
          If in HTTP environment, it sets an encrypted cookie to the client.
 void setPersistentAttribute(String attribName, Object attribValue)
          Saves an attribute to the actual session, rather than simply the response.
 

Method Detail

setAttribute

public void setAttribute(String attribName,
                         Object attribValue)
Sets an attribute that is valid for the duration of the request.

Parameters:
attribName - The name of the object you wish to set.
attribValue - the object you want to set.

getAttribute

public Object getAttribute(String attribName)
Retrieves the object from the request context.

Parameters:
attribName - the name of the object to retrieve
Returns:
the object or null if it doesn't exist.

getAttributeNames

public Enumeration getAttributeNames()
Retrieves all attribute names in the request context.

Returns:
java.util.Enumeration

setClientAttribute

public void setClientAttribute(String attribName,
                               String attribValue)
If in HTTP environment, it sets an encrypted cookie to the client.

Parameters:
attribName - the name of the attribute to
attribValue - the value of the attribute to set.

getClientAttribute

public String getClientAttribute(String attribName)
Retrieves a value of a cookie set on the client's system. It also decrypts the value with the password you set up in your expresso-config.xml file.

Parameters:
attribName - the name of the cookie to retrieve
Returns:
java.lang.String the value of the cookie or null if the cookie doesn't exist.

getPeristentAttributeNames

public Enumeration getPeristentAttributeNames()
Retrieves all attribute names from the session context.

Returns:
java.util.Enumeration

setPersistentAttribute

public void setPersistentAttribute(String attribName,
                                   Object attribValue)
Saves an attribute to the actual session, rather than simply the response. Use this for storing objects between requests, but only use it with care since the extra memory used may bog down systems under high load.

Parameters:
attribName - the name of the attribute to set
attribValue - a Serializable java object.
See Also:
Serializable

getPersistentAttribute

public Object getPersistentAttribute(String attribName)
Retrieves the object from the session context.

Parameters:
attribName - the name of the object to retrieve
Returns:
the object or null if it doesn't exist.

invalidate

public void invalidate()
Clear out the session. Invalidates the entire session.


removeAttribute

public void removeAttribute(String attribName)
Clears an attribute from the request context

Parameters:
attribName - the name of the attribute to remove.

removePersistentAttribute

public void removePersistentAttribute(String attribName)
Clears an attribute from the session context

Parameters:
attribName - the name of the attribute to remove.

Expresso 5-6

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