com.iplanet.jato.model
Class SessionModel

java.lang.Object
  |
  +--com.iplanet.jato.model.SessionModel
All Implemented Interfaces:
Model, RequestParticipant

public class SessionModel
extends java.lang.Object
implements Model, RequestParticipant

Provides a model implementation backed by the HTTP session. This model can be used to automatically bind display fields to the current request's session attributes. The bound name of display fields must correspond exactly to the name of the desired value in the session's attributes. Note that use of this model will cause the session to be created if it does not already exist.

Version:
JATO/1.2.2 $Id: SessionModel.java,v 1.6 2002/03/16 03:26:31 todd Exp $
See Also:
HttpSession

Constructor Summary
SessionModel()
          This constructor is used when the model is created by the ModelManager.
SessionModel(javax.servlet.http.HttpSession session)
          This constructor can be used when creating a SessionModel directly
 
Method Summary
 java.lang.String getName()
          Returns the logical instance name of this model.
 java.lang.Object getValue(java.lang.String name)
          Returns the value contained in the named session attribute
 java.lang.Object[] getValues(java.lang.String name)
          Returns the value contained in the named session attribute wrapped in an Object array
 void setName(java.lang.String value)
          Sets the logical name of this model
 void setRequestContext(RequestContext value)
          Sets the RequestContext used to obtain the HttpSession.
 void setValue(java.lang.String name, java.lang.Object value)
          Sets the provided value in the session attribute under the specified name.
 void setValues(java.lang.String name, java.lang.Object[] value)
          Sets the provided value in the session attribute under the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionModel

public SessionModel()
This constructor is used when the model is created by the ModelManager. If this constructor is used outside of the model manager, the session must be subsequently set via a call to setRequestContext(...) (this method is automatically called by the model manager before returning the model).

SessionModel

public SessionModel(javax.servlet.http.HttpSession session)
This constructor can be used when creating a SessionModel directly
Parameters:
session - The session for the current request
Throws:
java.lang.IllegalArgumentException - Thrown if the session parameter is null
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Model
Returns the logical instance name of this model. This name can be any arbitrary string. This name may only be useful at certain times; for example, the ModelManager may assign a name to a model based on user request.
Specified by:
getName in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Returns:
The opaque, arbitrary name of this model

setName

public void setName(java.lang.String value)
Description copied from interface: Model
Sets the logical name of this model
Specified by:
setName in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The new name of this model

setRequestContext

public void setRequestContext(RequestContext value)
Sets the RequestContext used to obtain the HttpSession. This method will create the session if it has not already been created.
Specified by:
setRequestContext in interface RequestParticipant
Parameters:
value - The request context object for the current request

getValue

public java.lang.Object getValue(java.lang.String name)
Returns the value contained in the named session attribute
Specified by:
getValue in interface Model
Parameters:
name - The name of the session attribute that will be returned
Returns:
The named session attribute, or null if the attribute doesn't exist

setValue

public void setValue(java.lang.String name,
                     java.lang.Object value)
Sets the provided value in the session attribute under the specified name. This method will be automatically called by any bound display field's setValue(...) method. If the value parameter is null, the named session attribute will be removed from the session.
Specified by:
setValue in interface Model
Parameters:
name - The name of the session attribute to set. If this method is called autmaticaly by a bound display field, the provided name will be the display field's bound field name.
value - The value of the session attribute to set. If null, the named attribute will be removed from the session.

getValues

public java.lang.Object[] getValues(java.lang.String name)
Returns the value contained in the named session attribute wrapped in an Object array
Specified by:
getValues in interface Model
Parameters:
name - The name of the session attribute that will be returned
Returns:
An object array of length one, containing the value obtained from the session attributes. If the specified session attribute is null, an array of length zero will be returned.

setValues

public void setValues(java.lang.String name,
                      java.lang.Object[] value)
Sets the provided value in the session attribute under the specified name. This method will be automatically called by any bound display field's setValues(...) method. If the value parameter is null or of length zero, the named session attribute will be removed from the session.
Specified by:
setValues in interface Model
Parameters:
name - The name of the session attribute to set. If this method is called autmaticaly by a bound display field, the provided name will be the display field's bound field name.
value - The value of the session attribute to set. Only the first element of the provided array will be set as the session attribute. If null or of length zero, the named attribute will be removed from the session.