public abstract class AbstractCommandResponse extends Object implements CommandResponse
Command responses.
Note that all setters in this class are not public to prohibit users of this class from arbitrarily
modifying the response once it has been created.
| Constructor and Description |
|---|
AbstractCommandResponse(Command command)
Constructor for
AbstractCommandResponse to initialize this response with empty results. |
AbstractCommandResponse(Command command,
boolean success,
Object results,
Throwable exception)
Constructor for
AbstractCommandResponse that allows all fields to be initialized. |
AbstractCommandResponse(CommandResponse responseToTransform)
Constructor for
AbstractCommandResponse that acts as a copy constructor and a command response
decorator/transformer. |
| Modifier and Type | Method and Description |
|---|---|
Command |
getCommand()
If the command was issued with
Command.isCommandInResponse() set to true, this will return a
copy of the Command object that was executed. |
Throwable |
getException()
Returns the exception that was the cause of a failed command.
|
Object |
getResults()
Provides the command's results.
|
boolean |
isSuccessful()
Returns
true if the command was executed successfully, false if any error occurred that
caused the command to fail. |
protected void |
setCommand(Command command)
Sets the command that was executed and whose results are being returned in this response object.
|
protected void |
setException(Throwable exception)
Sets the exception that was the result of a failed command.
|
protected void |
setResults(Object results)
Sets the response data that was the result of the command execution.
|
protected void |
setSuccessful(boolean success)
Sets the flag to indicate if the command execution was successful or not.
|
String |
toString() |
public AbstractCommandResponse(Command command)
AbstractCommandResponse to initialize this response with empty results. This sets the
isSuccessful() flag to true, which assumes that the command was successful unless told
otherwise.
Note that if command is null, this response object will not store any command for
the client to review (which may or may not be what the client wanted - see Command.isCommandInResponse()
.
command - the command that was executed (may be null)public AbstractCommandResponse(Command command, boolean success, Object results, Throwable exception)
AbstractCommandResponse that allows all fields to be initialized.
Note that if command is null, this response object will not store any command for
the client to review (which may or may not be what the client wanted - see Command.isCommandInResponse()
.
command - the command that was executed (may be null)success - the flag to indicate if the command was successful or notresults - the results of the command (may be null)exception - an exception that is typically the result of a failed command (may be null)public AbstractCommandResponse(CommandResponse responseToTransform)
AbstractCommandResponse that acts as a copy constructor and a command response
decorator/transformer. The given command reponse's parameter values will be copied to this new command response
object.
Transforming a command response allows the caller to "decorate" the given response with a concrete command response implementation's API (which typically has more strongly typed methods to extract out result object data).
This is typically used when the given command response is a generic command response (one with no strongly typed accessor methods to retrieve data from the result object for example) and the caller wants to convert it to a more concrete command response implementation. This is usually due to the fact that the creator of the given command object and its response did not know at compile time the specific concrete command type it needed.
The only thing a subclass must do in order to support this transformer constructor is to override it and call
it via super.
responseToTransform - the command response object to transform into this class typepublic boolean isSuccessful()
CommandResponsetrue if the command was executed successfully, false if any error occurred that
caused the command to fail.isSuccessful in interface CommandResponsetrue if the command was successful, false otherwiseCommandResponse.isSuccessful()protected void setSuccessful(boolean success)
Note the scope of this method is protected - only subclasses will be able to modify this
flag.
success - true if command was successful, false otherwiseisSuccessful()public Object getResults()
CommandResponsenull, irregardless of whether the command was
successful or not. The return value of this method may or may not be valid if CommandResponse.isSuccessful() returns
false. It is up to each implementor of this interface to determine the semantics of these
conditions.getResults in interface CommandResponseCommandResponse.getResults()protected void setResults(Object results)
null, irregardless of whether the command execution was successful or not. The semantics of this is
determined by each implementor of this object.results - the command response datapublic Throwable getException()
null if the
command succeeded and will be non-null if the command failed. Subclasses are
free to define when or if this exception value is set.getException in interface CommandResponseprotected void setException(Throwable exception)
exception - an exception that was the result of a failed command (may be null)public Command getCommand()
CommandResponseCommand.isCommandInResponse() set to true, this will return a
copy of the Command object that was executed. This is helpful in allowing for the client processing the
response to know what command was executed.
To determine the actual results of the executed command, see CommandResponse.getResults().
getCommand in interface CommandResponsenull if not availableCommandResponse.getCommand()protected void setCommand(Command command)
Command.isCommandInResponse() is false, this method does nothing.command - the command that was executedpublic String toString()
toString in class ObjectObject.toString()Copyright © 2008-2013 Red Hat, Inc.. All Rights Reserved.