|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Command
Defines a command that can be executed. A command consists of a type (e.g. the command
name) and an optional set of parameters, whose values can be obtained via
getParameterValue(String).
If a command accepts any and all parameter types and values, it does not need to define a set of parameter definitions. However, if a command accepts only a certain set of parameters, it must define a set of parameter definitions that determine the validity of a command's parameter values.
Note that command implementors are recommended to provide a set of parameter setter methods should they require
parameters in order to be able to execute. This will allow a strongly-typed mechanism to be available in order to set
parameters (as opposed to asking the client to add Object values to a weakly-typed map and/or checking the parameter
definitions to ensure the parameter values are valid). It is highly recommended that the implementors of this
interface define setter methods that take Objects as opposed to primitives (e.g. Integer vs.
int) to make it easier for cmdline clients to convert from
text-based input to the Java representations of the actual data types needed.
| Method Summary | |
|---|---|
boolean |
allowAnyParameter()
Returns true if this command does not utilize
parameter definitions to restrict what parameters it can accept. |
void |
checkParameterValidity(boolean convertIfNecessary)
This method verifies the validity of the parameters. |
void |
convertParameters()
This method will attempt to convert all parameters whose types did not match that of its corresponding parameter definition. |
CommandType |
getCommandType()
Returns an object that identifies the type of command. |
Properties |
getConfiguration()
Returns a map of name/value pairs that can be used to configure this particular instance of the command. |
ParameterDefinition |
getParameterDefinition(String paramName)
Returns the definition of the named parameter. |
ParameterDefinition[] |
getParameterDefinitions()
Returns the set of parameter definitions for all allowable parameters this command accepts. |
Object |
getParameterValue(String paramName)
Returns the value of a parameter that is to be passed to the command. |
Map<String,Object> |
getParameterValues()
Returns the values of all parameters that are to be passed to the command in a Map, with the keys in
the map being the parameter names. |
boolean |
hasParameterValue(String paramName)
Checks to see if the given parameter has explicitly been given a value ( null or otherwise). |
boolean |
isCommandInResponse()
If true is returned, then this Command that was executed will be included in the returned
response. |
void |
removeParameterValue(String paramName)
Removes a parameter from this command. |
void |
removeParameterValues()
Removes all parameters from this command. |
void |
setCommandInResponse(boolean flag)
Sets a flag to determine if this Command object is to be returned with the response after the command has
executed. |
void |
setParameterValue(String paramName,
Object paramValue)
Adds a parameter value under the given parameter name. |
| Method Detail |
|---|
CommandType getCommandType()
null)boolean allowAnyParameter()
true if this command does not utilize
parameter definitions to restrict what parameters it can accept.
true means this command will accept any and all parameter values and types. false means that
this command restricts the kinds of parameters it will accept. The definitions of the allowable parameters are
determined by a call to getParameterDefinitions().
true if there are no restrictions to the number, types and names of parameters accepted by
the command; false means all parameters must pass validity checks based on parameter
definitions found in getParameterDefinitions()
ParameterDefinition[] getParameterDefinitions()
throws NoParameterDefinitionsException
Whether a command accepts any and all parameters can also be determined by calling
allowAnyParameter().
Command implementations may choose to make the order of the returned array significant.
null)
NoParameterDefinitionsException - if no parameter definitions have been defined by the command; this
indicates the command will accept any and all parameters
ParameterDefinition getParameterDefinition(String paramName)
throws IllegalArgumentException,
NoParameterDefinitionsException
null
is returned. If a command does not define parameter definitions (e.g. allowAnyParameter() returns
true}), an exception is thrown.
paramName - the name of the parameter whose definition is to be returned (must not be null)
null if the command does not accept a parameter with
the given name
IllegalArgumentException - if paramName is null
NoParameterDefinitionsException - if the command has not defined any parameter definitions
boolean hasParameterValue(String paramName)
throws IllegalArgumentException
null or otherwise).
paramName - the name of the parameter whose existence is to be checked
true if a parameter named paramName has a value explicitly defined in this
command; false if there is no parameter of that name defined
IllegalArgumentException - if paramName is nullMap<String,Object> getParameterValues()
Map, with the keys in
the map being the parameter names.
Note that the returned Map is a copy - changes to the Map will not reflect back into
the command. However, each individual value object is the original reference; it is recommended that the caller
not modify the underlying value objects found in the returned map; instead,
setParameterValue(String, Object) should be used.
null but may be empty)
Object getParameterValue(String paramName)
throws IllegalArgumentException
paramName - the name of the parameter whose value is to be returned (must not be null)
null)
IllegalArgumentException - if paramName is null
void setParameterValue(String paramName,
Object paramValue)
throws IllegalArgumentException
paramValue. Note that any parameter name or value may be added
with this method - validity checking is not performed. To ensure a command's parameters are valid, call
checkParameterValidity(boolean).
Note that implementations should not rely on clients using this method - instead, implementations of this
interface should provide additional, more strongly typed, setter methods. This provides two things: first, it
does not ask the client to know the actual parameter name and second it provides stronger type checking (as
opposed to being able to just pass in an Object as this method allows).
paramName - the name of the new parameterparamValue - the value of the new parameter
IllegalArgumentException - if paramName is null
void removeParameterValue(String paramName)
throws IllegalArgumentException
checkParameterValidity(boolean).
Also see setParameterValue(String, Object) for the recommendation of defining strongly-typed methods
in implementation classes.
paramName - a key to identify the parameter to remove (may be null)
IllegalArgumentException - if paramName is nullvoid removeParameterValues()
checkParameterValidity(boolean).
boolean isCommandInResponse()
true is returned, then this Command that was executed will be included in the returned
response. This is useful if executed asynchronously and the command requestor will need to know the command and
the parameters that were issued. If false, then the response returned by the server after the
command has executed will be unavailable (i.e. null).
true if this object will be returned in the response to the command executionvoid setCommandInResponse(boolean flag)
Command object is to be returned with the response after the command has
executed. Using this will affect performance as it requires not only for the actual response data to be
(un)marshalled, but also the Command must be (un)marshalled and set over the network as well. Use this if
the command was executed asynchronously and the original Command object is no longer available on the
client.
flag - true to get this object returned with the command response.
void checkParameterValidity(boolean convertIfNecessary)
throws InvalidParameterValueException
If convertIfNecessary is true, this method will attempt to convert a parameter whose
value did not match that of its parameter definition. This conversion is not guaranteed to be successful; if the
conversion fails, the original parameter value remains intact and the validity check fails. If the conversion
succeeds, the newly converted parameter value replaces the invalid value.
If all parameters are deemed valid and the command can be invoked, this method does nothing.
convertIfNecessary - if true, then attempt to convert any invalid parameter values
InvalidParameterValueException - if one or more parameters are invalidconvertParameters()void convertParameters()
checkParameterValidity(boolean)Properties getConfiguration()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||