au.com.whitesquare.waf.command
Class ValidatedCommand

java.lang.Object
  extended byau.com.whitesquare.waf.command.ValidatedCommand
All Implemented Interfaces:
BaseCommand
Direct Known Subclasses:
BaseObjectViewCmd, SecureCommand

public abstract class ValidatedCommand
extends Object
implements BaseCommand

This is the base implementation of BaseCommand, it is the most advanced command that can be used by sub-classes, it supports all types of parameter parsing context management and the sorts.

Last Modified $Date: 2006/08/09 22:17:24 $

Version:
$Revision: 1.24 $
Author:
Steve Mactaggart

Field Summary
protected  WAFRequest params
           
 
Constructor Summary
ValidatedCommand()
           
 
Method Summary
protected  void addParamRetriever(ParameterRetriever retriever)
          Queues in a parameter retreiver to this command.
protected  void addPostParseParameter(String code, int paramType, boolean mandatory, String description)
           
protected  void addPostParseParamRetriever(ParameterRetriever retriever)
          Deprecated. Parameter retrivers can now have their own post parse parameters, add the param retreiver in the constructor and it will automatically get its post parse params loaded.
protected  void addRequestParameter(String code, int paramType)
          An overloaded version of the addRequestParameter method that defines the parameter as optional.
protected  void addRequestParameter(String code, int paramType, boolean mandatory, String description)
          Defines a parameter to be retreived from the request and mapped to a data type.
protected  void addSubCommandParameter(String key, Object value)
           
 void clearParameter(String key)
           
 void clearParameters()
           
 Response execute(WAFRequest theParams)
          This is the method that is called to execute the actual work for the command.
 Boolean getBoolean(String code)
           
 String getContext(int i)
          Returns the name of a specific context element
 int getContextCount()
          Returns the numeber of context elements found.
 Float getFloat(String code)
           
 Float[] getFloatArray(String code)
           
 Integer getInteger(String code)
           
 Integer[] getIntegerArray(String code)
           
 Long getLong(String code)
           
 Long[] getLongArray(String code)
           
 Object getObject(String code)
           
 HttpServletRequest getRequest()
          Allows the command to access data directly from the HttpServletRequest
 HttpServletResponse getResponse()
          Allows the command to access data directory from the HttpServletResponse.
 HttpSession getSession()
           
 String getString(String code)
           
 String[] getStringArray(String code)
           
protected abstract  Response innerExecute()
           
protected abstract  Response parameterErrorExecute(ParameterErrors pe)
           
protected  Response processSubCommand(BaseCommand command)
           
 Response processSubCommand(BaseCommand command, String message)
           
protected  void setupPostParseFields()
          This function is executed after the first set of parameters are processed.
protected  void setupPreParseFields()
          This function is executed before the parameters values are processed.
protected  ParameterErrors validate()
          This method supports post parameter check validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface au.com.whitesquare.waf.command.BaseCommand
isSessionRequired
 

Field Detail

params

protected WAFRequest params
Constructor Detail

ValidatedCommand

public ValidatedCommand()
Method Detail

addRequestParameter

protected final void addRequestParameter(String code,
                                         int paramType)
An overloaded version of the addRequestParameter method that defines the parameter as optional.

Parameters:
code - The data input field name/code to be parsed
paramType - A RequestParameter constant (INTEGER, STRING, etc..) to determine the fields datatype.

addRequestParameter

protected final void addRequestParameter(String code,
                                         int paramType,
                                         boolean mandatory,
                                         String description)
Defines a parameter to be retreived from the request and mapped to a data type.
Automatic existance checking can be enabled by setting a mandatory flag to true. If the parameter is not supplied and marked as mandatory, a ParameterError will be generated and sent to the Command via the processParameterErrors() method.

Parameters:
code - The data input field name/code to be parsed
paramType - A RequestParameter constant (INTEGER, STRING, etc..) to determine the fields datatype.
mandatory - To flag that the parameter is required
description - The human readable name of the field.

addPostParseParameter

protected final void addPostParseParameter(String code,
                                           int paramType,
                                           boolean mandatory,
                                           String description)

addParamRetriever

protected final void addParamRetriever(ParameterRetriever retriever)
Queues in a parameter retreiver to this command.

Parameters:
retriever - the retreiver to add to the command.

addPostParseParamRetriever

protected final void addPostParseParamRetriever(ParameterRetriever retriever)
Deprecated. Parameter retrivers can now have their own post parse parameters, add the param retreiver in the constructor and it will automatically get its post parse params loaded.

Parameters:
retriever -

getSession

public final HttpSession getSession()

clearParameter

public final void clearParameter(String key)

clearParameters

public final void clearParameters()

getString

public String getString(String code)

getStringArray

public String[] getStringArray(String code)

getLong

public Long getLong(String code)

getLongArray

public Long[] getLongArray(String code)

getFloat

public Float getFloat(String code)

getFloatArray

public Float[] getFloatArray(String code)

getInteger

public Integer getInteger(String code)

getIntegerArray

public Integer[] getIntegerArray(String code)

getBoolean

public Boolean getBoolean(String code)

getObject

public Object getObject(String code)

setupPostParseFields

protected void setupPostParseFields()
This function is executed after the first set of parameters are processed. It allows you to access these parameters and add additional parameters to be parsed.
Ensure to use the addPostParseParameter or addPostParseParamRetriever as the way to add the extra params as they are the only ones processed after this function is called.


setupPreParseFields

protected void setupPreParseFields()
This function is executed before the parameters values are processed.


execute

public final Response execute(WAFRequest theParams)
Description copied from interface: BaseCommand
This is the method that is called to execute the actual work for the command. This method is implemented with the ability to interact with the request and session (via the WAFRequest object) and the response, by returning a sub-class of Response.

Specified by:
execute in interface BaseCommand
Parameters:
theParams - is the WAFRequest object that contains all of the request information parsed into the standard WAF format.
Returns:
a sub-class of Response which will direct the Controller Servlet on how to manage the response.

validate

protected ParameterErrors validate()
This method supports post parameter check validation. If your command needs to do more complex validation than null and type checking, then by overriding this method you can implement your own manual checks, string length or that a parameter matches a specific pattern.

If any parameters are in error then return a ParameterErrors containing the errors that have occured and then parameterErrorExecute will be called.

Sub-classes should initise a ParameterErrors collection by calling super.validate().

Returns:
a set of errors on the current parameters;

innerExecute

protected abstract Response innerExecute()

parameterErrorExecute

protected abstract Response parameterErrorExecute(ParameterErrors pe)

processSubCommand

protected final Response processSubCommand(BaseCommand command)

processSubCommand

public final Response processSubCommand(BaseCommand command,
                                        String message)

addSubCommandParameter

protected final void addSubCommandParameter(String key,
                                            Object value)

getRequest

public HttpServletRequest getRequest()
Allows the command to access data directly from the HttpServletRequest

Returns:
the request that this command is connected to.

getResponse

public HttpServletResponse getResponse()
Allows the command to access data directory from the HttpServletResponse.

Returns:
the response that this command is connected to.

getContext

public String getContext(int i)
Returns the name of a specific context element

Parameters:
i - the index of the context to return.
Returns:
the name of the context.

getContextCount

public int getContextCount()
Returns the numeber of context elements found.

Returns:
the number for context elements found.


Copyright © 2004 Whitesquare Software. All Rights Reserved.