Packageorg.spicefactory.parsley.core.messaging.command.impl
Classpublic class AbstractCommand
InheritanceAbstractCommand Inheritance Object
Implements Command

Abstract base class for Commands. In most cases custom Command implementations can simply extend this class and invoke one of the protected methods when the Command completed its execution.



Public Properties
 PropertyDefined By
  message : Message
[read-only] The message that triggered the Command.
AbstractCommand
  returnValue : *
[read-only] The return value from the Command execution.
AbstractCommand
  selector : *
[read-only]
AbstractCommand
  status : CommandStatus
[read-only] The current status of the command.
AbstractCommand
Public Methods
 MethodDefined By
  
AbstractCommand(returnValue:*, message:Message)
Creates a new instance.
AbstractCommand
  
Adds an observer to be invoked when this Command changes its status.
AbstractCommand
  
addStatusHandler(handler:Function, ... params):void
Adds a handler function to invoke when the Command changes its status.
AbstractCommand
  
Returns the observers directly added to this command, matching the specified status.
AbstractCommand
  
getResult(targetType:ClassInfo):*
Returns the result for the specified target type.
AbstractCommand
  
hasObserver(status:CommandStatus):Boolean
Indicates whether at least one observer has been added directly to this command, matching the specified status.
AbstractCommand
  
setResult(result:Object, status:CommandStatus = null):void
Sets (and potentially overrides) the result of this command.
AbstractCommand
Protected Methods
 MethodDefined By
  
cancel():void
Signals that the Command execution has been cancelled.
AbstractCommand
  
complete(result:* = null):void
Signals that the Command has successfully completed and specifies the result to be passed to result handlers.
AbstractCommand
  
error(result:* = null):void
Signals that the Command finished with an error and specifies the value to be passed to error handlers.
AbstractCommand
  
selectErrorValue(result:*, targetType:ClassInfo):*
Selects the value to be passed to an error handler based on the specified target type.
AbstractCommand
  
selectResultValue(result:*, targetType:ClassInfo):*
Selects the value to be passed to a result handler based on the specified target type.
AbstractCommand
  
start():void
Signals that the command is now active.
AbstractCommand
Property Detail
messageproperty
message:Message  [read-only]

The message that triggered the Command.


Implementation
    public function get message():Message
returnValueproperty 
returnValue:*  [read-only]

The return value from the Command execution.


Implementation
    public function get returnValue():*
selectorproperty 
selector:*  [read-only]


Implementation
    public function get selector():*
statusproperty 
status:CommandStatus  [read-only]

The current status of the command.


Implementation
    public function get status():CommandStatus
Constructor Detail
AbstractCommand()Constructor
public function AbstractCommand(returnValue:*, message:Message)

Creates a new instance.

Parameters
returnValue:* — the value returned by the method executing the command
 
message:Message — the message that triggered the command execution
Method Detail
addObserver()method
public function addObserver(observer:CommandObserver):void

Adds an observer to be invoked when this Command changes its status. In contrast to the simple status handler functions, an observer will be executed within the regular MessageRouter processing together with any matching observers registered directly for the scope. This means that they will also adhere to all error handling rules configured for that scope. Therefor an observer should always be preferred over a simple status handler for any functionality that calls back into application code.

Parameters

observer:CommandObserver — the observer to be invoked upon command completion

addStatusHandler()method 
public function addStatusHandler(handler:Function, ... params):void

Adds a handler function to invoke when the Command changes its status. This may either be a successful completion, or due to cancellation or an error. Should only be used for internal extension logic, any callback that calls back into application code should use the addObserver method.

Parameters

handler:Function — the handler to invoke upon command completion
 
... params — any additional parameters that should be passed to the handler in addition to the Command itself

cancel()method 
protected function cancel():void

Signals that the Command execution has been cancelled.

complete()method 
protected function complete(result:* = null):void

Signals that the Command has successfully completed and specifies the result to be passed to result handlers.

Parameters

result:* (default = null) — the result to be passed to result handlers

error()method 
protected function error(result:* = null):void

Signals that the Command finished with an error and specifies the value to be passed to error handlers.

Parameters

result:* (default = null) — the error to be passed to error handlers

getObservers()method 
public function getObservers(status:CommandStatus):Array

Returns the observers directly added to this command, matching the specified status.

Parameters

status:CommandStatus — the status to return the matching commands for

Returns
Array — the observers directly added to this command, matching the specified status
getResult()method 
public function getResult(targetType:ClassInfo):*

Returns the result for the specified target type.

The type is only passed to the method to allow to select amongst multiple values (like choosing between ResultEvent.result and the event instance itself). Implementations should not throw an Error if the type does not match, as there might be a Converter registered for the target type.

This method should throw an error if the current status is EXECUTE or CANCEL.

Parameters

targetType:ClassInfo — The expected type on the target (parameter or property)

Returns
* — the best match for the specified target type
hasObserver()method 
public function hasObserver(status:CommandStatus):Boolean

Indicates whether at least one observer has been added directly to this command, matching the specified status.

Parameters

status:CommandStatus — the status to check the matching commands for

Returns
Boolean — true when at least one observer has been added directly to this command, matching the specified status
selectErrorValue()method 
protected function selectErrorValue(result:*, targetType:ClassInfo):*

Selects the value to be passed to an error handler based on the specified target type.

The type is only passed to the method to allow to select amongst multiple values (like choosing between FaultEvent.fault and the event instance itself). Implementations should not throw an Error if the type does not match, as there might be a Converter registered for the target type.

Parameters

result:* — the result that was passed to the error method
 
targetType:ClassInfo — The expected type on the target (parameter or property)

Returns
* — the best match for the specified target type
selectResultValue()method 
protected function selectResultValue(result:*, targetType:ClassInfo):*

Selects the value to be passed to a result handler based on the specified target type.

The type is only passed to the method to allow to select amongst multiple values (like choosing between ResultEvent.result and the event instance itself). Implementations should not throw an Error if the type does not match, as there might be a Converter registered for the target type.

Parameters

result:* — the result that was passed to the complete method
 
targetType:ClassInfo — The expected type on the target (parameter or property)

Returns
* — the best match for the specified target type
setResult()method 
public function setResult(result:Object, status:CommandStatus = null):void

Sets (and potentially overrides) the result of this command. When a CommandStatus is passed to this method, the status of this command will also change. This is useful in cases where a regular result must be interpreted as an error condition or vice versa. When the status changes any active processor for command observers will rewind and start processing again.

Parameters

result:Object — the new result to set for this command
 
status:CommandStatus (default = null) — the new status for this command

start()method 
protected function start():void

Signals that the command is now active. Any invocation of the complete, cancel or error method before this method was invoked will lead to a delayed execution as they are treated as stemming from a command that synchronously finished its execution.

This method should usually be called at the very end of the constructor of the command.