org.rhq.enterprise.communications.command
Class AbstractCommandResponse

java.lang.Object
  extended by org.rhq.enterprise.communications.command.AbstractCommandResponse
All Implemented Interfaces:
Serializable, CommandResponse
Direct Known Subclasses:
EchoCommandResponse, GenericCommandResponse, IdentifyCommandResponse, RemoteInputStreamCommandResponse, RemoteOutputStreamCommandResponse, RemotePojoInvocationCommandResponse, StartCommandResponse

public abstract class AbstractCommandResponse
extends Object
implements CommandResponse

Superclass to all 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.

Author:
John Mazzitelli
See Also:
Serialized Form

Constructor Summary
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.
 
Method Summary
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractCommandResponse

public AbstractCommandResponse(Command command)
Constructor for 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() .

Parameters:
command - the command that was executed (may be null)

AbstractCommandResponse

public AbstractCommandResponse(Command command,
                               boolean success,
                               Object results,
                               Throwable exception)
Constructor for 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() .

Parameters:
command - the command that was executed (may be null)
success - the flag to indicate if the command was successful or not
results - the results of the command (may be null)
exception - an exception that is typically the result of a failed command (may be null)

AbstractCommandResponse

public AbstractCommandResponse(CommandResponse responseToTransform)
Constructor for 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.

Parameters:
responseToTransform - the command response object to transform into this class type
Method Detail

isSuccessful

public boolean isSuccessful()
Description copied from interface: CommandResponse
Returns true if the command was executed successfully, false if any error occurred that caused the command to fail.

Specified by:
isSuccessful in interface CommandResponse
Returns:
true if the command was successful, false otherwise
See Also:
CommandResponse.isSuccessful()

setSuccessful

protected void setSuccessful(boolean success)
Sets the flag to indicate if the command execution was successful or not.

Note the scope of this method is protected - only subclasses will be able to modify this flag.

Parameters:
success - true if command was successful, false otherwise
See Also:
isSuccessful()

getResults

public Object getResults()
Description copied from interface: CommandResponse
Provides the command's results. This may or may not be null, 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.

Specified by:
getResults in interface CommandResponse
Returns:
the command execution results
See Also:
CommandResponse.getResults()

setResults

protected void setResults(Object results)
Sets the response data that was the result of the command execution. Note that this value may or may not be null, irregardless of whether the command execution was successful or not. The semantics of this is determined by each implementor of this object.

Parameters:
results - the command response data

getException

public Throwable getException()
Returns the exception that was the cause of a failed command. This typically will be 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.

Specified by:
getException in interface CommandResponse
Returns:
exception an exception that was the cause of a failed command

setException

protected void setException(Throwable exception)
Sets the exception that was the result of a failed command. Subclasses may or may not decide to include an exception, even if the command failed.

Parameters:
exception - an exception that was the result of a failed command (may be null)

getCommand

public Command getCommand()
Description copied from interface: CommandResponse
If the command was issued with Command.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().

Specified by:
getCommand in interface CommandResponse
Returns:
the command that was executed or null if not available
See Also:
CommandResponse.getCommand()

setCommand

protected void setCommand(Command command)
Sets the command that was executed and whose results are being returned in this response object. Note that if the Command.isCommandInResponse() is false, this method does nothing.

Parameters:
command - the command that was executed

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.