edu.uoc.pfc.j2ee.jalonsod.mtp.request
Class HttpRequestData

java.lang.Object
  extended by edu.uoc.pfc.j2ee.jalonsod.mtp.request.HttpRequestData
All Implemented Interfaces:
RequestData, RequestDataPrivate

public class HttpRequestData
extends java.lang.Object
implements RequestDataPrivate

File: HttpRequestData.java Created: 2012-04-30 HttpRequestData is the HTTP implementation of the RequestDataPrivate. Applications should not use directly this class, they must use the requestData interface.

Author:
José Alonso de Motta
See Also:
RequestData, RequestDataPrivate

Field Summary
private  boolean authorized
          The authorization status of the request.
private  Configurator configurator
          The framework configuration of the application.
private  FormInstance formInstance
          The formInstance object with the parameter values of the request associated with the model.
private  Model model
          The model configuraction selected for the request.
private  java.lang.Object modelInstance
          The application model object.
private  java.lang.String modelResponse
          The string that the application model object run method has returned.
private  javax.servlet.http.HttpServletRequest request
          The request received from the user.
private  Language requestLanguage
          The language inferred to the request.
private  Result result
          The result inferred to the request.
private  int validationStatus
          The validation status of the request.
private  java.lang.String view
          The view selected to redirect the response (like a jsp page).
 
Fields inherited from interface edu.uoc.pfc.j2ee.jalonsod.mtp.request.RequestDataPrivate
REQUEST_MODEL_ATTRIBUTE, SESSION_LANGUAGE_ATTRIBUTE, SESSION_ROLES_ATTRIBUTE
 
Fields inherited from interface edu.uoc.pfc.j2ee.jalonsod.mtp.request.RequestData
MTP_LOGGER, REQUEST_EXCEPTION, REQUEST_REQUESTDATA_ATTRIBUTE, VALIDATION_ERROR_LOADING_PARAMETER_VALUES_INTO_MODEL, VALIDATION_ERROR_STAGE_1_DATATYPE_CONVERSION, VALIDATION_ERROR_STAGE_2_REQUIRED_FIELDS, VALIDATION_ERROR_STAGE_3_FIELD_VALIDATION_FUNCTIONS, VALIDATION_ERROR_STAGE_4_MODEL_VALIDATION_FUNCTION, VALIDATION_NO_VALIDATED, VALIDATION_OK
 
Constructor Summary
HttpRequestData(javax.servlet.http.HttpServletRequest request)
          Constructor.
 
Method Summary
 void authorize(boolean authorized)
          Sets the request authorization status to run the model.
 void createSession()
          Creates a new session for the user (framework creates a new session for the request if it does not has one).
 void deleteSessionAttribute(java.lang.String attributeName)
          Removes an attribute from the session.
 Configurator getConfigurator()
          Returns the main configuration object.
 FormInstance getFormInstance()
          Returns the formInstance object with the parameters of the request associated with the model.
 java.util.Hashtable<java.lang.String,Language> getLanguages()
          Returns the application supported languages.
 java.lang.String getMessage(java.lang.String key)
          Obtains a message text from a languageEntry in the request user's language with the supplied key.
 Model getModel()
          Gets the model configuration object selected for the request, or null if the request has no model.
 java.lang.Object getModelInstance()
          Returns the application model instance object.
 java.lang.String getModelResponse()
          Returns the response string returned by the run method of the application model object.
private  javax.servlet.http.HttpServletRequest getRequest()
           
 java.lang.Object getRequestAttribute(java.lang.String attributeName)
          Returns an attribute stored previously in the request.
 java.lang.String getRequestParameter(java.lang.String parameterName)
          Obtains a parameter from the request.
 Result getResult()
          Returns the result object of the request.
 java.util.Hashtable<java.lang.String,Role> getRoles()
          Gets the roles granted to the session.
private  javax.servlet.http.HttpSession getSession()
           
 java.lang.Object getSessionAttribute(java.lang.String attributeName)
          Returns an attribute stored previously in the session.
 Language getUserLanguage()
          Gets the language inferred for the request, based on previous setUserLanguage call, request agent supported languages or default application language.
 int getValidationStatus()
          Returns the request validation status.
 java.lang.String getView()
          Returns the view name to which the response will be redirected.
 boolean hasValidSession()
          Checks if the request has a valid session.
private  Language inferUserLanguage()
          Algorithm to infer the language of the request based on: the language of the session if it was set on previous request.
 boolean isAuthorized()
          Returns the request session authorization status to run the model.
 boolean isValidated()
          Returns if the request has passed all validations.
 void logoutSession()
          Invalidates the session of the request.
private  void setConfigurator(Configurator configurator)
           
private  void setDefaultRoles()
          Stores the default roles defined by the configurator into the session.
 void setFormInstance(FormInstance formInstance)
          Sets the formInstance object with the parameters of the request associated with the model.
 void setModel(Model model)
          Sets the model configuration object for the request.
 void setModelInstance(java.lang.Object modelInstance)
          Sets the application model object.
 void setModelResponse(java.lang.String modelResponse)
          Sets the response string returned by the run method of the application model object.
private  void setRequest(javax.servlet.http.HttpServletRequest request)
           
 void setRequestAttribute(java.lang.String attributeName, java.lang.Object attributeObject)
          Stores an attribute in the request.
private  void setRequestLanguage(Language requestLanguage)
          Sets the language of the request.
 void setResult(Result result)
          Sets the result object of the request.
 void setRoles(java.util.Hashtable<java.lang.String,Role> sessionRoles)
          Sets the roles granted to the session.
 void setSessionAttribute(java.lang.String attributeName, java.lang.Object attributeObject)
          Stores an attribute into the session.
 void setUserLanguage(Language userLanguage)
          Sets the language for the session.
 void setValidationStatus(int validationStatus)
          Sets the request validation status.
 void setView(java.lang.String view)
          Sets the view name to which response will be redirected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

private javax.servlet.http.HttpServletRequest request
The request received from the user.


configurator

private Configurator configurator
The framework configuration of the application.


requestLanguage

private Language requestLanguage
The language inferred to the request. It's one of the languages from the configurator.


model

private Model model
The model configuraction selected for the request. Is stored during the ModelMapper stage of the request. It's one of the models from the configurator.


modelResponse

private java.lang.String modelResponse
The string that the application model object run method has returned. It's value is stored after the ModelRunner stage of the request. It can be null.


result

private Result result
The result inferred to the request. It's value is stored during the ViewMapper stage of the request. It's one of the results from the configurator associated with the model selected for the request. It can be null.


view

private java.lang.String view
The view selected to redirect the response (like a jsp page). It's value is stored during the ViewMapper stage of the request.


modelInstance

private java.lang.Object modelInstance
The application model object. It's value is stored during the ModelMapper stage of the request.


formInstance

private FormInstance formInstance
The formInstance object with the parameter values of the request associated with the model. It's value is stored during the Validator stage of the request.


authorized

private boolean authorized
The authorization status of the request. The authorization is done during the AccessControl stage of the request. false means that request is not authorized, true means request is authorized to execute.


validationStatus

private int validationStatus
The validation status of the request. Possible values are defined by RequestData.VALIDATION_* constants. The request is full validated when the value is RequestData.VALIDATION_OK

Constructor Detail

HttpRequestData

public HttpRequestData(javax.servlet.http.HttpServletRequest request)
                throws ConfiguratorException
Constructor. Creates the object, sets initial values for request and infers the language.

Parameters:
request - the request object received from the user.
Throws:
ConfiguratorException - throws when the configurator has any problem.
Method Detail

getConfigurator

public Configurator getConfigurator()
Description copied from interface: RequestData
Returns the main configuration object.

Specified by:
getConfigurator in interface RequestData
Returns:
the configuration main object.
See Also:
Configurator

setConfigurator

private void setConfigurator(Configurator configurator)

getLanguages

public java.util.Hashtable<java.lang.String,Language> getLanguages()
Description copied from interface: RequestData
Returns the application supported languages.

Specified by:
getLanguages in interface RequestData
Returns:
the list of application supported languages.
See Also:
Language

createSession

public void createSession()
Description copied from interface: RequestData
Creates a new session for the user (framework creates a new session for the request if it does not has one).

This is done automatically by the framework, but application can create a new session for the request.

Specified by:
createSession in interface RequestData
See Also:
RequestData.hasValidSession(), RequestData.logoutSession()

hasValidSession

public boolean hasValidSession()
Description copied from interface: RequestData
Checks if the request has a valid session.

Specified by:
hasValidSession in interface RequestData
Returns:
true if request has a valid session, false otherwise.
See Also:
RequestData.createSession(), RequestData.logoutSession()

getSession

private javax.servlet.http.HttpSession getSession()

logoutSession

public void logoutSession()
Description copied from interface: RequestData
Invalidates the session of the request.

Specified by:
logoutSession in interface RequestData
See Also:
RequestData.createSession(), RequestData.hasValidSession()

getSessionAttribute

public java.lang.Object getSessionAttribute(java.lang.String attributeName)
Description copied from interface: RequestData
Returns an attribute stored previously in the session.

Specified by:
getSessionAttribute in interface RequestData
Parameters:
attributeName - the name of the attribute to obtain.
Returns:
the object stored in the session, or null if it's empty or doesn't exists.

setSessionAttribute

public void setSessionAttribute(java.lang.String attributeName,
                                java.lang.Object attributeObject)
Description copied from interface: RequestData
Stores an attribute into the session.

Specified by:
setSessionAttribute in interface RequestData
Parameters:
attributeName - the name of the attribute to store.
attributeObject - the object to store in the session.

deleteSessionAttribute

public void deleteSessionAttribute(java.lang.String attributeName)
Description copied from interface: RequestData
Removes an attribute from the session.

Specified by:
deleteSessionAttribute in interface RequestData
Parameters:
attributeName - the name of the attribute to remove.

getRoles

public java.util.Hashtable<java.lang.String,Role> getRoles()
Description copied from interface: RequestData
Gets the roles granted to the session.

Specified by:
getRoles in interface RequestData
Returns:
the list of roles granted to the session.
See Also:
Role

setRoles

public void setRoles(java.util.Hashtable<java.lang.String,Role> sessionRoles)
Description copied from interface: RequestData
Sets the roles granted to the session.

Specified by:
setRoles in interface RequestData
Parameters:
sessionRoles - the list of roles to grant to the session. The previous granted roles are replaced with these.
See Also:
Role

setDefaultRoles

private void setDefaultRoles()
Stores the default roles defined by the configurator into the session.


getUserLanguage

public Language getUserLanguage()
Description copied from interface: RequestData
Gets the language inferred for the request, based on previous setUserLanguage call, request agent supported languages or default application language.

Specified by:
getUserLanguage in interface RequestData
Returns:
the language inferred for the request.
See Also:
Language

setUserLanguage

public void setUserLanguage(Language userLanguage)
Description copied from interface: RequestData
Sets the language for the session. This language is stored in the session for use on the next requests from the same session.

Specified by:
setUserLanguage in interface RequestData
Parameters:
userLanguage - the language to assign to the session.
See Also:
Language

setRequestLanguage

private void setRequestLanguage(Language requestLanguage)
Sets the language of the request.

Parameters:
requestLanguage - the language assigned to the request.

inferUserLanguage

private Language inferUserLanguage()
Algorithm to infer the language of the request based on:

Returns:
the language inferred by the algorithm.

getMessage

public java.lang.String getMessage(java.lang.String key)
Description copied from interface: RequestData
Obtains a message text from a languageEntry in the request user's language with the supplied key.

Specified by:
getMessage in interface RequestData
Parameters:
key - the key string to match with a languageEntry key.
Returns:
a string message in request inferred language or null if not found.
See Also:
Language, LanguageEntry

getRequest

private javax.servlet.http.HttpServletRequest getRequest()

setRequest

private void setRequest(javax.servlet.http.HttpServletRequest request)

getRequestAttribute

public java.lang.Object getRequestAttribute(java.lang.String attributeName)
Description copied from interface: RequestData
Returns an attribute stored previously in the request.

Specified by:
getRequestAttribute in interface RequestData
Parameters:
attributeName - the name of the attribute to obtain.
Returns:
the object stored in the request with supplied name, or null if it's empty or doesn't exists.

setRequestAttribute

public void setRequestAttribute(java.lang.String attributeName,
                                java.lang.Object attributeObject)
Description copied from interface: RequestData
Stores an attribute in the request. The life of the attribute is the same as the request.

Specified by:
setRequestAttribute in interface RequestData
Parameters:
attributeName - the name of the attribute to store.
attributeObject - the object to store in the request.

getRequestParameter

public java.lang.String getRequestParameter(java.lang.String parameterName)
Description copied from interface: RequestData
Obtains a parameter from the request.

Specified by:
getRequestParameter in interface RequestData
Parameters:
parameterName - the name of the parameter to obtain.
Returns:
the string with the parameter value or null if the parameter doesn't exists.

getModel

public Model getModel()
Description copied from interface: RequestData
Gets the model configuration object selected for the request, or null if the request has no model.

Specified by:
getModel in interface RequestData
Returns:
the model configuration object.
See Also:
Model

setModel

public void setModel(Model model)
Description copied from interface: RequestDataPrivate
Sets the model configuration object for the request.

This is done by the modelMapper.

Specified by:
setModel in interface RequestDataPrivate
Parameters:
model - the model configuration object to set into the request.
See Also:
Model

getModelInstance

public java.lang.Object getModelInstance()
Description copied from interface: RequestData
Returns the application model instance object.

Specified by:
getModelInstance in interface RequestData
Returns:
the application model instance object.

setModelInstance

public void setModelInstance(java.lang.Object modelInstance)
Description copied from interface: RequestDataPrivate
Sets the application model object.

This is done by the modelMapper.

Specified by:
setModelInstance in interface RequestDataPrivate
Parameters:
modelInstance - the application model object.
See Also:
ModelMapper

getFormInstance

public FormInstance getFormInstance()
Description copied from interface: RequestData
Returns the formInstance object with the parameters of the request associated with the model.

Specified by:
getFormInstance in interface RequestData
Returns:
the formInstance configuration object.
See Also:
FormInstance

setFormInstance

public void setFormInstance(FormInstance formInstance)
Description copied from interface: RequestDataPrivate
Sets the formInstance object with the parameters of the request associated with the model.

This is done in the validation stage by the validator.

Specified by:
setFormInstance in interface RequestDataPrivate
Parameters:
formInstance - the formInstance object with the parameters of the request associated with the model.

getModelResponse

public java.lang.String getModelResponse()
Description copied from interface: RequestData
Returns the response string returned by the run method of the application model object.

Specified by:
getModelResponse in interface RequestData
Returns:
the response string returned by the run method of the application model object.

setModelResponse

public void setModelResponse(java.lang.String modelResponse)
Description copied from interface: RequestDataPrivate
Sets the response string returned by the run method of the application model object.

This is done by the framework when the model run method finishes.

Specified by:
setModelResponse in interface RequestDataPrivate
Parameters:
modelResponse - the response string returned by the run method of the application model object.

getResult

public Result getResult()
Description copied from interface: RequestData
Returns the result object of the request.

Specified by:
getResult in interface RequestData
Returns:
the result object of the request or null if it doesn't exists.
See Also:
Model, Result

setResult

public void setResult(Result result)
Description copied from interface: RequestDataPrivate
Sets the result object of the request.

This is done by the viewMapper.

Specified by:
setResult in interface RequestDataPrivate
Parameters:
result - the result object of the request.
See Also:
ViewMapper

getView

public java.lang.String getView()
Description copied from interface: RequestData
Returns the view name to which the response will be redirected.

Specified by:
getView in interface RequestData
Returns:
the view name selected for the response.

setView

public void setView(java.lang.String view)
Description copied from interface: RequestDataPrivate
Sets the view name to which response will be redirected.

This is done by the viewMapper.

Specified by:
setView in interface RequestDataPrivate

isAuthorized

public boolean isAuthorized()
Description copied from interface: RequestData
Returns the request session authorization status to run the model.

Specified by:
isAuthorized in interface RequestData
Returns:
true if request session has been authorized, or false otherwise.

authorize

public void authorize(boolean authorized)
Description copied from interface: RequestDataPrivate
Sets the request authorization status to run the model.

This is done by the accessControl of the framework.

Specified by:
authorize in interface RequestDataPrivate
Parameters:
authorized - true if request is authorized, false otherwise.

getValidationStatus

public int getValidationStatus()
Description copied from interface: RequestData
Returns the request validation status.

Specified by:
getValidationStatus in interface RequestData
Returns:
the validation status of the request. It's one of the RequestData.VALIDATION_* values.

setValidationStatus

public void setValidationStatus(int validationStatus)
Description copied from interface: RequestDataPrivate
Sets the request validation status.

This is done by the framework in validation stage.

Specified by:
setValidationStatus in interface RequestDataPrivate
Parameters:
validationStatus - the validation status of the framework. It's one of the RequestData.VALIDATION_* values.

isValidated

public boolean isValidated()
Description copied from interface: RequestData
Returns if the request has passed all validations.

Specified by:
isValidated in interface RequestData
Returns:
true if the request has passed all validations, false otherwise.