Keel 2.1RC2

org.keel.services.model
Interface ModelRequest

All Superinterfaces:
KeelRequest
All Known Implementing Classes:
DefaultModelRequest

public interface ModelRequest
extends KeelRequest


Field Summary
static java.lang.String ROLE
           
 
Method Summary
 void addError(java.lang.String errorName, java.lang.String errorMessage)
          Add an error with a specific name.
 void copyFrom(KeelRequest newRequest)
          Copy the values from another Keel Request into this one.
 ModelResponse createResponse()
          Used by the model to generate the "empty" response object, which the model then populates with Inputs, Outputs and Commands
 ModelResponse execute()
          Actually execute the requested model object's logic, returning the ModelResponse it creates
 java.lang.Object getConfiguration()
          Get the configuration object for this Request's Model
 Context getContext()
          Get the Keel Context object indiciating the current context for this request.
 java.lang.Object getDefaultService(java.lang.String role)
          This method is used by Model objects to get access to other services or services in the system.
 java.lang.String getDomain()
           
 java.util.Map getErrors()
          Return a map of error names and messages produced by validation of the parameters before entering this model.
 java.lang.Object[] getParameterAsArray(java.lang.String name)
          Return the values of a multi-valued parameter as an array of objects.
 java.util.Date getParameterAsDate(java.lang.String name)
          Return the value of the specified parameter as a date
 java.util.Date getParameterAsDate(java.lang.String name, java.util.Date defaultValue)
          Return the specified parameter's value as a date, or the default value if no such parameter exists.
 double getParameterAsDouble(java.lang.String name)
          Return the specified parameter's value as a double
 double getParameterAsDouble(java.lang.String name, double defaultValue)
           
 float getParameterAsFloat(java.lang.String name)
          Return the value of a parameter as a float
 float getParameterAsFloat(java.lang.String name, float defaultValue)
          Return the specified parameter's value as a float
 int getParameterAsInt(java.lang.String name)
          Get the named parameter as an int.
 int getParameterAsInt(java.lang.String name, int defaultValue)
          Return the specified parameter as an integer, returning the supplied default value if no such parameter exists.
 java.util.List getParameterAsList(java.lang.String name)
          Return the values of a parameter which has more than one value
 java.util.List getParameterAsList(java.lang.String name, java.util.List defaultValue)
          Return the values of a parameter which has more than one value
 long getParameterAsLong(java.lang.String name)
          Return the specified parameter as a long
 long getParameterAsLong(java.lang.String name, long defaultValue)
          Return the specified parameter as a long, or the default value if there is no such parameter.
 java.lang.String getParameterAsString(java.lang.String name)
          Return the specified parameter's value as a string
 java.lang.String getParameterAsString(java.lang.String name, java.lang.String defaultValue)
           
 java.util.Map getPreviousRequest()
          A request for a model may involve a jump to another model, or back to the same model in the event of an error (for the user to input new data, for example).
 java.lang.Object getService(java.lang.String role, java.lang.String hint)
          This method is used by a model when it wants to access a particular service (often a factory for another service) and specify the hint itself.
 java.lang.Object getService(java.lang.String role, java.lang.String hint, Context ctx)
          This method is used by a model when it wants to access a particular service (often a factory for another service) and specify the hint itself.
 int getUid()
          Return the user identifier of the user who has submitted this request.
 void setPreviousRequest(java.util.Map newPrevious)
           
 
Methods inherited from interface org.keel.services.model.KeelRequest
deserialize, getAttribute, getAttributes, getModel, getParameter, getParameters, serialize, setAttribute, setModel, setParameter
 

Field Detail

ROLE

public static final java.lang.String ROLE
See Also:
Constant Field Values
Method Detail

execute

public ModelResponse execute()
                      throws ModelException
Actually execute the requested model object's logic, returning the ModelResponse it creates

Throws:
ModelException

createResponse

public ModelResponse createResponse()
                             throws ModelException
Used by the model to generate the "empty" response object, which the model then populates with Inputs, Outputs and Commands

Throws:
ModelException

getContext

public Context getContext()
                   throws ModelException
Get the Keel Context object indiciating the current context for this request. Usually this contains at least a UserEnvironment object

Throws:
ModelException

getDefaultService

public java.lang.Object getDefaultService(java.lang.String role)
                                   throws ModelException
This method is used by Model objects to get access to other services or services in the system. The current context is used to determine if a special "hint" should be used with the service selector in order to deliver a specific service - for example, when getting a PersistentFactory, the UserEnvironment in the current context is used to determine the currently selected database.

Throws:
ModelException

getService

public java.lang.Object getService(java.lang.String role,
                                   java.lang.String hint)
                            throws ModelException
This method is used by a model when it wants to access a particular service (often a factory for another service) and specify the hint itself. This basically means the Model has access to the same kind of access it would have if it were a Composable, but only through it's request object.

Throws:
ModelException

getService

public java.lang.Object getService(java.lang.String role,
                                   java.lang.String hint,
                                   Context ctx)
                            throws ModelException
This method is used by a model when it wants to access a particular service (often a factory for another service) and specify the hint itself. This basically means the Model has access to the same kind of access it would have if it were a Composable, but only through it's request object.

Throws:
ModelException

getUid

public int getUid()
Return the user identifier of the user who has submitted this request. Normally gets this information from the UserEnvironment object in the current context. If none, return 0 (anonymous user)


getDomain

public java.lang.String getDomain()

getPreviousRequest

public java.util.Map getPreviousRequest()
A request for a model may involve a jump to another model, or back to the same model in the event of an error (for the user to input new data, for example). In this case, a map of the parameters to the the 'previous' request is held here, so that the last value of various parameters supplied in the last request can be displayed (possibly along with an error message) for the user to try again


setPreviousRequest

public void setPreviousRequest(java.util.Map newPrevious)

getConfiguration

public java.lang.Object getConfiguration()
Get the configuration object for this Request's Model

Returns:
Return the Configuration object for this model (if any)

copyFrom

public void copyFrom(KeelRequest newRequest)
              throws ModelException
Copy the values from another Keel Request into this one.

Parameters:
newRequest - The request to copy from
Throws:
ModelException - If an error occurs during the copy

getParameterAsInt

public int getParameterAsInt(java.lang.String name)
Get the named parameter as an int. Return 0 if there is no such parameter.

Parameters:
name - Name of the required parameter
Returns:
An int representation of the paramter, 0 if no such parameter.

getParameterAsInt

public int getParameterAsInt(java.lang.String name,
                             int defaultValue)
Return the specified parameter as an integer, returning the supplied default value if no such parameter exists.

Parameters:
name - Name of the required parameter
defaultValue - The value returned if no such parameter exists
Returns:
The int value corresponding to the named parameter

getParameterAsLong

public long getParameterAsLong(java.lang.String name)
Return the specified parameter as a long

Parameters:
name - Name of the required parameter
Returns:
The parameter value as a long, or 0 if no such parameter exists.

getParameterAsLong

public long getParameterAsLong(java.lang.String name,
                               long defaultValue)
Return the specified parameter as a long, or the default value if there is no such parameter.

Parameters:
name - Name of the required parameter
defaultValue - The value to be returned if no such parameter exists
Returns:
The value of the specified parameter as a long, or the default value if no such parameter exists.

getParameterAsFloat

public float getParameterAsFloat(java.lang.String name)
Return the value of a parameter as a float

Parameters:
name - Name of the required parameter
Returns:
The specified parameter as a float, or 0 if there is no such parameter

getParameterAsFloat

public float getParameterAsFloat(java.lang.String name,
                                 float defaultValue)
Return the specified parameter's value as a float

Parameters:
name - Name of the required parameter
defaultValue -
Returns:
The specified parameter's value as a float, or the default value if no such parameter exists

getParameterAsDouble

public double getParameterAsDouble(java.lang.String name)
Return the specified parameter's value as a double

Parameters:
name - Name of the required parameter
Returns:
The specified value as a double, or 0 if there is no such parameter

getParameterAsDouble

public double getParameterAsDouble(java.lang.String name,
                                   double defaultValue)
Parameters:
name - Name of the required parameter
defaultValue -
Returns:

getParameterAsString

public java.lang.String getParameterAsString(java.lang.String name)
Return the specified parameter's value as a string

Parameters:
name - Name of the required parameter
Returns:
The parameter value as a string, or an empty string if there is no such parameter

getParameterAsString

public java.lang.String getParameterAsString(java.lang.String name,
                                             java.lang.String defaultValue)
Parameters:
name - Name of the required parameter
defaultValue -
Returns:

getParameterAsArray

public java.lang.Object[] getParameterAsArray(java.lang.String name)
Return the values of a multi-valued parameter as an array of objects.

Parameters:
name - Name of the required parameter
Returns:
The parameter value as an array of objects.

getParameterAsDate

public java.util.Date getParameterAsDate(java.lang.String name)
Return the value of the specified parameter as a date

Parameters:
name - Name of the required parameter
Returns:
A date value for the specified parameter, or null if there is no such parameter

getParameterAsDate

public java.util.Date getParameterAsDate(java.lang.String name,
                                         java.util.Date defaultValue)
Return the specified parameter's value as a date, or the default value if no such parameter exists.

Parameters:
name - Name of the required parameter
defaultValue - The date value to return if no such parameter exists
Returns:
The specified parameter as a date, or the default

getParameterAsList

public java.util.List getParameterAsList(java.lang.String name)
Return the values of a parameter which has more than one value

Parameters:
name - Name of the required parameter
Returns:
The specified parameter as a list of values

getParameterAsList

public java.util.List getParameterAsList(java.lang.String name,
                                         java.util.List defaultValue)
Return the values of a parameter which has more than one value

Parameters:
name - Name of the required parameter
defaultValue - The list returned if no such parameter exists.
Returns:
The specified parameter as a list of values, or the default list supplied if no such parameter exists.

getErrors

public java.util.Map getErrors()
Return a map of error names and messages produced by validation of the parameters before entering this model. This allows the model to deal with these errors as it sees fit - note: such errors are not automatically added the the response, the model must do that if it is required (res.addErrors(req.addErrors()) for example.

Returns:
A map mapping names to messages for validation errors, or an empty map if no such errors have occurred.

addError

public void addError(java.lang.String errorName,
                     java.lang.String errorMessage)
Add an error with a specific name. This name may be used to associate the error with a certain UI element (such as an Input), so the user can see immediately what was wrong when the error is displayed.This method is generally only used by ModelValidator components *before* Model execution begins.

Parameters:
errorName - A name for this error message, which may (or may not) correspond to the UI element from which the error originated.
errorMessage - A human-readable error message to be displayed to the user. Messages beginning with "$" will be taken to be internationalized keys to look up in the appropriate message bundle for this locale.

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.