Expresso 5-6

com.jcorporate.expresso.core.controller
Class ControllerRequest

java.lang.Object
  extended bycom.jcorporate.expresso.core.controller.ControllerRequest
All Implemented Interfaces:
Cloneable, RequestContext, Serializable
Direct Known Subclasses:
ServletControllerRequest

public class ControllerRequest
extends Object
implements Serializable, RequestContext, Cloneable

ControllerRequest is a simple "wrapper" object that holds the parameters and data required for a controller to be able to transition to a new state.
Developer Notes Because this class can be cloned, please make sure that you add any fields to this class to the clone function.

See Also:
Serialized Form

Constructor Summary
ControllerRequest()
          Default Constructor.
 
Method Summary
 Object clone()
          Returns a clone of this object.
 Object getAttrib(String attrib)
          get the named attribute of this Controller
 String getAttribute(String attrib)
          Deprecated. v5.5, 4/2004; use getAttrib() instead, and cast to string
 Map getAttributes()
          Get the attributes Map
 String getDataContext()
          Return the name of the database connection we use - or null for the default connection
 String getDBName()
          Deprecated. 10/2004 v.5.6 use getDataContext instead
 ErrorCollection getErrorCollection()
          Returns the Error collection that exists in the current session.
 String getFileName(String paramName)
          If a particular parameter represents an uploaded file (which can be determined by the isFileParameter(String) method) then this method retrieves the server-side file name - e.g. the location that has the data that was uploaded stored in it.
 String getFormAttribute()
           
 String getInitParameter(String paramName)
          Retrieve the initialization parameter
 Locale getLocale()
          Returns the locale of this request.
 Object getObjectParameter(String paramName)
           
 String getParameter(String paramCode)
          Fetch the value for the given parameter.
 Hashtable getParameters()
          Return the complete hashtable of parameters all keyed by parameter names
 PersistentSession getSession()
          Returns the Persistant Session Wrapper object to store requests between environments.
 int getUid()
          Get the user id as an integer
 String getUser()
          Get the user name
 User getUserInfo()
          get requesting user
 boolean isFileParameter(String paramName)
          Does a specified parameter refer to an uploaded file?
 boolean isParameter(String paramName)
          Checks if the described parameter is a defined parameter for this request
 void populate(DBObject myDBObj)
          Convenience method to populate a dbobject from the parameters supplied, by looking for parameters with the same name as the field name in the db object
 void removeAttrib(String key)
          remove the attribute
 void removeParameter(String paramName)
          Remove a parameter from this controller request.
 void setAttrib(String attrib, Object val)
          Set the named attribute to the given value
 void setAttribute(String attrib, String val)
          Deprecated. v5.5, 4/2004; use setAttrib() instead
 void setAttributes(Map attributes)
          Set the attributes Map to the supplied Map
 void setDataContext(String newDBName)
          Set this DB Controller to operate on a database other than the default
 void setDBName(String newDBName)
          Set this DB Controller to operate on a database other than the default
 void setFileParameter(String paramName, String paramValue, String fileName)
           
 void setFormAttribute(String newAttribute)
           
 void setInitParameter(String paramName, String paramValue)
          Our caller can pass us initialization parameters.
 void setLocale(Locale newLocale)
          Sets the Locale of this request
 void setObjectParameter(String paramName, Object paramValue)
          Set a parameter as an object
 void setParameter(String paramName, String paramValue)
           
 void setParameters(Hashtable h)
          Set the parameters for this request.
 void setSession(PersistentSession newSession)
          Provide the controller with a PersitentSession object, which it can use to hold values between invokations.
 void setUid(int newUid)
          Sets the current integer user id.
 void setUser(String newUser)
          The client of the controller must tell us who is accessing us, and we decide if they're allowed to access the given state.
 void validateDBField(String dbFieldName, DBObject oneObject, ErrorCollection ec)
          Convenience method that retrieves the validates against that one database object field.
 void validateDBObject(DBObject oneObject, ErrorCollection ec)
          Convenience method that retrieves parameters/field values and populates a specified db object.
 void validateField(String dbFieldName, String reqFieldName, DBObject oneObject, ErrorCollection ec)
          Convenience method that retrieves the validates against that one database object field.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControllerRequest

public ControllerRequest()
Default Constructor. Initializes Logging

Method Detail

setFileParameter

public void setFileParameter(String paramName,
                             String paramValue,
                             String fileName)
                      throws ControllerException
Throws:
ControllerException

getFileName

public String getFileName(String paramName)
If a particular parameter represents an uploaded file (which can be determined by the isFileParameter(String) method) then this method retrieves the server-side file name - e.g. the location that has the data that was uploaded stored in it.

Parameters:
paramName - the name of the paramter to get the filename for.
Returns:
java.lang.String

setAttribute

public void setAttribute(String attrib,
                         String val)
Deprecated. v5.5, 4/2004; use setAttrib() instead

Set the named attribute of this Controller to the given value

Parameters:
attrib - The name of an "attribtue" for this ControllerElement item
val - The value for this attribute

setAttrib

public void setAttrib(String attrib,
                      Object val)
Set the named attribute to the given value

Parameters:
attrib - The name of an "attribtue" for this ControllerElement item
val - The value for this attribute

getAttribute

public String getAttribute(String attrib)
Deprecated. v5.5, 4/2004; use getAttrib() instead, and cast to string

get the named attribute of this Controller

Parameters:
attrib - The name of an "attribute" for this ControllerElement item
Returns:
java.lang.String

getAttrib

public Object getAttrib(String attrib)
get the named attribute of this Controller

Parameters:
attrib - The name of an "attribute" for this ControllerElement item
Returns:
java.lang.String

getAttributes

public Map getAttributes()
Get the attributes Map

Returns:
java.util.Map of objects keyed by String. todo return new HashMap(attributes) to encapsulate the data member properly? // 4/04 LAH

setAttributes

public void setAttributes(Map attributes)
Set the attributes Map to the supplied Map

Parameters:
attributes - a Map of attribute values

removeAttrib

public void removeAttrib(String key)
remove the attribute

Parameters:
key - the name of the attribute to remove

setInitParameter

public void setInitParameter(String paramName,
                             String paramValue)
Our caller can pass us initialization parameters. For example, if we're being called by a client that has information on connecting to a database, the connection parameters can be passed to us.

Parameters:
paramName - the name of the parameter
paramValue - the value of the parameter

setParameter

public void setParameter(String paramName,
                         String paramValue)
                  throws ControllerException
Parameters:
paramName - The name of the parameter
paramValue - The value of the parameter
Throws:
ControllerException - upon error

setObjectParameter

public void setObjectParameter(String paramName,
                               Object paramValue)
                        throws ControllerException
Set a parameter as an object

Parameters:
paramName - The name of the parameter
paramValue - The value object
Throws:
ControllerException - upon error

getObjectParameter

public Object getObjectParameter(String paramName)
                          throws ControllerException
Parameters:
paramName - The name of the parameter to retrieve
Returns:
the Object retrieved from the object parameters list.
Throws:
ControllerException - if unable to get the object parameters

setParameters

public void setParameters(Hashtable h)
Set the parameters for this request.

Parameters:
h - The hashtable for the bulk copies.

setUser

public void setUser(String newUser)
The client of the controller must tell us who is accessing us, and we decide if they're allowed to access the given state.

Parameters:
newUser - The user's string id to set this user to.

setUid

public void setUid(int newUid)
Sets the current integer user id.

Parameters:
newUid - - the user ID integer to set this request to.

setSession

public void setSession(PersistentSession newSession)
                throws ControllerException
Provide the controller with a PersitentSession object, which it can use to hold values between invokations. It is essential to use the PersistentSession rather than handing the controller the HTTPSession or HTTPServletRequest, for example, to preserve it's portability across all UI environments.

Parameters:
newSession - A PersistentSession object
Throws:
ControllerException

getSession

public PersistentSession getSession()
                             throws ControllerException
Returns the Persistant Session Wrapper object to store requests between environments. Use this instead of HTTPSession or HTTPServletRequest

Returns:
a Persistant Session Object
Throws:
ControllerException - upon error

getInitParameter

public String getInitParameter(String paramName)
Retrieve the initialization parameter

Parameters:
paramName - the name of the parameter to retrieve
Returns:
java.lang.String

getUser

public String getUser()
Get the user name

Returns:
the currently logged in user or NONE if there's no user logged in

getUid

public int getUid()
Get the user id as an integer

Specified by:
getUid in interface RequestContext
Returns:
an integer representing the internal UID

getParameters

public Hashtable getParameters()
Return the complete hashtable of parameters all keyed by parameter names

Returns:
a Hashtable containing all the parameter values, keyed by name; this is a CLONE of the source hashtable, not the original

getParameter

public String getParameter(String paramCode)
Fetch the value for the given parameter. Return null if there is no such parameter

Parameters:
paramCode - Code of the parameter desired
Returns:
java.lang.String

isFileParameter

public boolean isFileParameter(String paramName)
Does a specified parameter refer to an uploaded file?

Parameters:
paramName - the name of the parameter to check if it is a file
Returns:
boolean

getDBName

public String getDBName()
Deprecated. 10/2004 v.5.6 use getDataContext instead

Return the name of the database connection we use - or null for the default connection

Specified by:
getDBName in interface RequestContext
Returns:
The current DBContext

getDataContext

public String getDataContext()
Return the name of the database connection we use - or null for the default connection

Returns:
The current DBContext

setDBName

public void setDBName(String newDBName)
Set this DB Controller to operate on a database other than the default

Parameters:
newDBName - The dbcontext to set this request to.

setDataContext

public void setDataContext(String newDBName)
Set this DB Controller to operate on a database other than the default

Parameters:
newDBName - The dbcontext to set this request to.

populate

public void populate(DBObject myDBObj)
              throws ControllerException
Convenience method to populate a dbobject from the parameters supplied, by looking for parameters with the same name as the field name in the db object

Parameters:
myDBObj - the dbobject to populate
Throws:
ControllerException - upon error

getErrorCollection

public ErrorCollection getErrorCollection()
                                   throws ControllerException
Returns the Error collection that exists in the current session.

Returns:
an ErrorCollection object or NULL if an error collection doesn't exist.
Throws:
ControllerException - if there is an error getting the Session object

setFormAttribute

public void setFormAttribute(String newAttribute)

getFormAttribute

public String getFormAttribute()

isParameter

public boolean isParameter(String paramName)
Checks if the described parameter is a defined parameter for this request

Parameters:
paramName - the parameter to check against.
Returns:
true if the name given IS a valid defined parameter

validateDBObject

public void validateDBObject(DBObject oneObject,
                             ErrorCollection ec)
                      throws ControllerException,
                             ValidationException
Convenience method that retrieves parameters/field values and populates a specified db object. Once the object is populated, the fields are validated and the error collection populated if necessary.

Parameters:
oneObject - the object to validate
ec - The error collection that gets filled out.
Throws:
ControllerException - upon internal or data error
ValidationException - if there is an error validating the object

validateDBField

public void validateDBField(String dbFieldName,
                            DBObject oneObject,
                            ErrorCollection ec)
                     throws ControllerException,
                            DBException
Convenience method that retrieves the validates against that one database object field. Assumes that the parameter name in the request is the same as the DB field name.

Parameters:
dbFieldName - the name of the field to validate
oneObject - the DBOBject to validate
ec - The ErrorCollection to fill out if there is an error
Throws:
DBException - upon data error
ControllerException - upon internal error

validateField

public void validateField(String dbFieldName,
                          String reqFieldName,
                          DBObject oneObject,
                          ErrorCollection ec)
                   throws ControllerException,
                          DBException
Convenience method that retrieves the validates against that one database object field.

Parameters:
dbFieldName - the name of the field to validate
reqFieldName - ???
oneObject - the DBOBject to validate
ec - The ErrorCollection to fill out if there is an error
Throws:
DBException - upon data error
ControllerException - upon internal error

setLocale

public void setLocale(Locale newLocale)
Sets the Locale of this request

Parameters:
newLocale - the new Locale to set this request to.

getLocale

public Locale getLocale()
Returns the locale of this request.

Specified by:
getLocale in interface RequestContext
Returns:
a Locale Object based upon current locale settings.

clone

public Object clone()
Returns a clone of this object.

Returns:
a newly cloned ControllerRequest object.

removeParameter

public void removeParameter(String paramName)
Remove a parameter from this controller request.

Parameters:
paramName - the name of the parameter to remove

getUserInfo

public User getUserInfo()
                 throws DBException
get requesting user

Returns:
user object for requesting user; will throw if UID is not found
Throws:
DBException

Expresso 5-6

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