Keel 2.1RC2

org.keel.services.model.defaultmodel
Class DefaultModelRequest

java.lang.Object
  extended byorg.keel.services.model.defaultmodel.DefaultModelRequest
All Implemented Interfaces:
Configurable, KeelContextualizable, KeelRequest, LogEnabled, ModelRequest, Poolable, Recyclable, Serviceable

public class DefaultModelRequest
extends java.lang.Object
implements LogEnabled, Serviceable, ModelRequest, Configurable, KeelContextualizable, Poolable, Recyclable


Field Summary
private  java.util.Map attributes
           
private  boolean configured
           
private  Context keelContext
           
private  Logger log
           
private  Configuration myConfig
           
private  ModelValidator myDefaultValidator
           
private  java.lang.String myModel
           
private  java.util.Map params
           
private  java.util.Map previousRequest
           
protected  KeelServiceableDelegate svcDelegate
           
private  java.util.Map validationErrors
           
 
Fields inherited from interface org.keel.services.model.ModelRequest
ROLE
 
Constructor Summary
DefaultModelRequest()
           
 
Method Summary
 void addError(java.lang.String name, java.lang.String message)
          Add a validation error to the collection of errors in this request.
protected  ModelResponse afterExecute(ModelResponse res, Configuration modelConfig)
           
 void configure(Configuration conf)
          Pass the Configuration to the Configurable class.
 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
 KeelRequest deserialize(byte[] bytes)
           
 void enableLogging(Logger logger)
          Provide component with a logger.
 ModelResponse execute()
          Actually execute the requested model object's logic, returning the ModelResponse it creates
 java.lang.Object getAttribute(java.lang.String key)
           
 java.util.Map getAttributes()
           
 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.
 Context getKeelContext()
           
 java.lang.String getModel()
          Return the name of the model currently being requested
 java.util.Set getOperations()
           
 java.lang.Object getParameter(java.lang.String paramKey)
          Retrieve the named parameter as a "raw" object - e.g.
 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)
          Type-specific access to request parameters *****
 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 getParameters()
          Retrieve the entire mapping of parameters and values
 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 first checks if the current model is securable.
 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 recycle()
          Model requests can be "recycled", that is, cleared and used again for a new request.
 byte[] serialize()
           
 void service(ServiceManager manager)
          Pass the ServiceManager to the Serviceable.
 void setAttribute(java.lang.String key, java.lang.Object value)
          Set the value of an attribute of this response
 void setKeelContext(Context keelContext)
           
 void setModel(java.lang.String modelName)
          The name of the model and the state allow us to determine the actual Java class that is going to be invoked, and how we're going to communicate with it
 void setParameter(java.lang.String paramKey, java.lang.Object param)
           
 void setPreviousRequest(java.util.Map newPrevious)
           
private  Command validate(Model newModel)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Logger log

myDefaultValidator

private ModelValidator myDefaultValidator

svcDelegate

protected KeelServiceableDelegate svcDelegate

params

private java.util.Map params

configured

private boolean configured

attributes

private java.util.Map attributes

keelContext

private Context keelContext

myModel

private java.lang.String myModel

myConfig

private Configuration myConfig

previousRequest

private java.util.Map previousRequest

validationErrors

private java.util.Map validationErrors
Constructor Detail

DefaultModelRequest

public DefaultModelRequest()
Method Detail

getModel

public java.lang.String getModel()
Description copied from interface: KeelRequest
Return the name of the model currently being requested

Specified by:
getModel in interface KeelRequest

recycle

public void recycle()
Model requests can be "recycled", that is, cleared and used again for a new request.

Specified by:
recycle in interface Recyclable

getParameter

public java.lang.Object getParameter(java.lang.String paramKey)
Retrieve the named parameter as a "raw" object - e.g. attempt no type conversion.

Specified by:
getParameter in interface KeelRequest
Parameters:
paramKey - The name of the requested parameter
Returns:
The value of the specified parameter, or null if there is no parameter with that name.

getParameters

public java.util.Map getParameters()
Retrieve the entire mapping of parameters and values

Specified by:
getParameters in interface KeelRequest
Returns:
A Map of parameter names and their values

setParameter

public void setParameter(java.lang.String paramKey,
                         java.lang.Object param)
Specified by:
setParameter in interface KeelRequest

setModel

public void setModel(java.lang.String modelName)
The name of the model and the state allow us to determine the actual Java class that is going to be invoked, and how we're going to communicate with it

Specified by:
setModel in interface KeelRequest

execute

public ModelResponse execute()
                      throws ModelException
Description copied from interface: ModelRequest
Actually execute the requested model object's logic, returning the ModelResponse it creates

Specified by:
execute in interface ModelRequest
Throws:
ModelException

createResponse

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

Specified by:
createResponse in interface ModelRequest
Throws:
ModelException

getContext

public Context getContext()
Description copied from interface: ModelRequest
Get the Keel Context object indiciating the current context for this request. Usually this contains at least a UserEnvironment object

Specified by:
getContext in interface ModelRequest

getUid

public int getUid()
Description copied from interface: ModelRequest
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)

Specified by:
getUid in interface ModelRequest

getDomain

public java.lang.String getDomain()
Specified by:
getDomain in interface ModelRequest

getPreviousRequest

public java.util.Map getPreviousRequest()
Description copied from interface: ModelRequest
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

Specified by:
getPreviousRequest in interface ModelRequest

setPreviousRequest

public void setPreviousRequest(java.util.Map newPrevious)
Specified by:
setPreviousRequest in interface ModelRequest

configure

public void configure(Configuration conf)
               throws ConfigurationException
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
conf - the class configurations. Must not be null.
Throws:
ConfigurationException - if an error occurs

getConfiguration

public java.lang.Object getConfiguration()
Description copied from interface: ModelRequest
Get the configuration object for this Request's Model

Specified by:
getConfiguration in interface ModelRequest
Returns:
Return the Configuration object for this model (if any)

afterExecute

protected ModelResponse afterExecute(ModelResponse res,
                                     Configuration modelConfig)
                              throws ModelException
Throws:
ModelException

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Specified by:
getAttribute in interface KeelRequest

getAttributes

public java.util.Map getAttributes()
Specified by:
getAttributes in interface KeelRequest

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value)
Description copied from interface: KeelRequest
Set the value of an attribute of this response

Specified by:
setAttribute in interface KeelRequest

getOperations

public java.util.Set getOperations()

getService

public java.lang.Object getService(java.lang.String role,
                                   java.lang.String hint)
                            throws ModelException
This method first checks if the current model is securable. If it is then it uses the AuthorizationManager class to check for authorization. If authorized then it passes on the model, otherwise throws SecurityException.

Specified by:
getService in interface ModelRequest
Throws:
ModelException

serialize

public byte[] serialize()
                 throws java.io.IOException
Specified by:
serialize in interface KeelRequest
Throws:
java.io.IOException

deserialize

public KeelRequest deserialize(byte[] bytes)
                        throws java.io.IOException
Specified by:
deserialize in interface KeelRequest
Throws:
java.io.IOException

copyFrom

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

Specified by:
copyFrom in interface ModelRequest
Parameters:
newRequest - The request to copy from
Throws:
ModelException - If an error occurs during the copy

enableLogging

public void enableLogging(Logger logger)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
logger - the logger. Must not be null.

getDefaultService

public java.lang.Object getDefaultService(java.lang.String role)
                                   throws ModelException
Description copied from interface: ModelRequest
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.

Specified by:
getDefaultService in interface ModelRequest
Throws:
ModelException

getService

public java.lang.Object getService(java.lang.String role,
                                   java.lang.String hint,
                                   Context ctx)
                            throws ModelException
Description copied from interface: ModelRequest
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.

Specified by:
getService in interface ModelRequest
Throws:
ModelException

service

public void service(ServiceManager manager)
             throws ServiceException
Description copied from interface: Serviceable
Pass the ServiceManager to the Serviceable. The Serviceable implementation should use the specified ServiceManager to acquire the components it needs for execution.

Specified by:
service in interface Serviceable
Parameters:
manager - The ServiceManager which this Serviceable uses. Must not be null.
Throws:
ServiceException - if an error occurs

getKeelContext

public Context getKeelContext()
Specified by:
getKeelContext in interface KeelContextualizable
See Also:
KeelContextualizable.getKeelContext()

setKeelContext

public void setKeelContext(Context keelContext)
                    throws ContextException
Specified by:
setKeelContext in interface KeelContextualizable
Throws:
ContextException
See Also:
KeelContextualizable.setKeelContext(org.apache.avalon.framework.context.Context)

getParameterAsInt

public int getParameterAsInt(java.lang.String name)
Type-specific access to request parameters *****

Specified by:
getParameterAsInt in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the specified parameter as an integer, returning the supplied default value if no such parameter exists.

Specified by:
getParameterAsInt in interface ModelRequest
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

getParameterAsString

public java.lang.String getParameterAsString(java.lang.String name)
Description copied from interface: ModelRequest
Return the specified parameter's value as a string

Specified by:
getParameterAsString in interface ModelRequest
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)
Specified by:
getParameterAsString in interface ModelRequest
Parameters:
name - Name of the required parameter
defaultValue -
Returns:

getParameterAsArray

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

Specified by:
getParameterAsArray in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the value of the specified parameter as a date

Specified by:
getParameterAsDate in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the specified parameter's value as a date, or the default value if no such parameter exists.

Specified by:
getParameterAsDate in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the values of a parameter which has more than one value

Specified by:
getParameterAsList in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the values of a parameter which has more than one value

Specified by:
getParameterAsList in interface ModelRequest
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.

getParameterAsLong

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

Specified by:
getParameterAsLong in interface ModelRequest
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.

getErrors

public java.util.Map getErrors()
Description copied from interface: ModelRequest
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.

Specified by:
getErrors in interface ModelRequest
Returns:
A map mapping names to messages for validation errors, or an empty map if no such errors have occurred.

getParameterAsDouble

public double getParameterAsDouble(java.lang.String name)
Description copied from interface: ModelRequest
Return the specified parameter's value as a double

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

getParameterAsFloat

public float getParameterAsFloat(java.lang.String name)
Description copied from interface: ModelRequest
Return the value of a parameter as a float

Specified by:
getParameterAsFloat in interface ModelRequest
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)
Description copied from interface: ModelRequest
Return the specified parameter's value as a float

Specified by:
getParameterAsFloat in interface ModelRequest
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,
                                   double defaultValue)
Specified by:
getParameterAsDouble in interface ModelRequest
Parameters:
name - Name of the required parameter
defaultValue -
Returns:

getParameterAsLong

public long getParameterAsLong(java.lang.String name)
Description copied from interface: ModelRequest
Return the specified parameter as a long

Specified by:
getParameterAsLong in interface ModelRequest
Parameters:
name - Name of the required parameter
Returns:
The parameter value as a long, or 0 if no such parameter exists.

addError

public void addError(java.lang.String name,
                     java.lang.String message)
Add a validation error to the collection of errors in this request. This method called by a ModelValidator component, not by the Model itself (normally)

Specified by:
addError in interface ModelRequest
Parameters:
name - A name for this error message, which may (or may not) correspond to the UI element from which the error originated.
message - 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.

validate

private Command validate(Model newModel)
                  throws ModelException,
                         ConfigurationException
Throws:
ModelException
ConfigurationException

Keel 2.1RC2

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