org.keridwen.core.messaging
Class AbstractCommand<ResultType,MessageType>

java.lang.Object
  extended by org.keridwen.core.messaging.AbstractCommand<ResultType,MessageType>
Type Parameters:
ResultType - the return type of the command
MessageType - the message type to be handled by the command
All Implemented Interfaces:
Controllable, Progressable, Command<ResultType,MessageType>

public abstract class AbstractCommand<ResultType,MessageType>
extends Object
implements Command<ResultType,MessageType>

This class provides default implementations for methods common to most Commands.


Constructor Summary
AbstractCommand(String aLabel, String aDescription, boolean isInterruptible, boolean isUndoable, boolean isPausable, boolean isProgressDetermined)
          Builds a command with the given label, description and control properties.
AbstractCommand(String aLabel, String aDescription, boolean isInterruptible, boolean isUndoable, boolean isPausable, boolean isProgressDetermined, CommandLogLevel aLogLevel)
          Builds a command with the given label, description and control properties.
 
Method Summary
 void addControllableListener(ControllableListener listener)
           
 void addProgressableListener(ProgressableListener listener)
           
 boolean checkPreConditions()
          Check that the Command preconditions are fulfilled.
 void clearControllableListener()
           
 void clearProgressableListener()
           
 ResultType execute(MessageType message)
          Executes the Command's logic with a given message.
 DataModel getApplicationModel()
          Gets the data model of the application.
 DataModel getBundleModel()
          Gets the data model of the bundle.
 String getDescription()
          Returns the localized Command description.
 String getLabel()
          Returns the localized Command name.
 CommandLogLevel getLogLevel()
          Gets the verbosity level at which this command should be logged.
 int getProgress()
           
 ControllableState getState()
           
 void interrupt()
           
 boolean isDetermined()
           
 boolean isInterrupted()
           
 boolean isInterruptible()
           
 boolean isPausable()
           
 boolean isUndoable()
          Checks whether the Command can be undone by the user.
protected  void notifyProgressChanged(int newProgress)
          Method called when the command progress has changed.
protected  void notifyStatusChanged(ControllableState newStatus)
          Method called when the command status has changed.
abstract  void pause()
           
 void removeControllableListener(ControllableListener listener)
           
 void removeProgressableListener(ProgressableListener listener)
           
abstract  void resume()
           
abstract  ResultType run(MessageType message)
          This method is the concrete business implementation of what the command should do.
protected  void setCommandStatus(ControllableState newStatus)
          Sets the command status to the provided value and notifies the listeners.
 void setModels(DataModel anApplicationModel, DataModel aBundleModel)
          Initializes the models of that the command can access.
protected  void setProgress(int newProgress)
          Updates the value of the command progress and warns the listeners.
abstract  void undo()
          Undo the Command actions.
abstract  boolean validatePostConditions()
          Sets all postconditions to true if they have been validated by the Command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommand

public AbstractCommand(String aLabel,
                       String aDescription,
                       boolean isInterruptible,
                       boolean isUndoable,
                       boolean isPausable,
                       boolean isProgressDetermined)
Builds a command with the given label, description and control properties.

Parameters:
aLabel - the localized name of the command
aDescription - the localized description of the command.
isInterruptible - boolean indicating whether the command can be interrupted.
isUndoable - boolean indicating whether the command can be undone.

AbstractCommand

public AbstractCommand(String aLabel,
                       String aDescription,
                       boolean isInterruptible,
                       boolean isUndoable,
                       boolean isPausable,
                       boolean isProgressDetermined,
                       CommandLogLevel aLogLevel)
Builds a command with the given label, description and control properties.

Parameters:
aLabel -
aDescription -
isInterruptible -
isUndoable -
isPausable -
isProgressDetermined -
aLogLevel -
Method Detail

undo

public abstract void undo()
Description copied from interface: Command
Undo the Command actions.

Specified by:
undo in interface Command<ResultType,MessageType>

pause

public abstract void pause()
Specified by:
pause in interface Controllable

resume

public abstract void resume()
Specified by:
resume in interface Controllable

validatePostConditions

public abstract boolean validatePostConditions()
Description copied from interface: Command
Sets all postconditions to true if they have been validated by the Command.

Specified by:
validatePostConditions in interface Command<ResultType,MessageType>
Returns:
true if all postconditions have been validated, false if at least one condition has not been validated.

run

public abstract ResultType run(MessageType message)
                        throws CommandException
This method is the concrete business implementation of what the command should do.

Parameters:
message - the input message of the command
Returns:
the return value of the command
Throws:
CommandException - any exception raised during execution

notifyStatusChanged

protected final void notifyStatusChanged(ControllableState newStatus)
Method called when the command status has changed.

Parameters:
newStatus - the new command status

notifyProgressChanged

protected final void notifyProgressChanged(int newProgress)
Method called when the command progress has changed.

Parameters:
newProgress - the new command progress

setProgress

protected final void setProgress(int newProgress)
Updates the value of the command progress and warns the listeners.

Parameters:
newProgress - the new progress value

execute

public final ResultType execute(MessageType message)
                         throws CommandException
Description copied from interface: Command
Executes the Command's logic with a given message.

Specified by:
execute in interface Command<ResultType,MessageType>
Parameters:
message - the message to use for the execution.
Returns:
the result of the command execution
Throws:
CommandException - exceptions raised during the execution of the command.

interrupt

public void interrupt()
Specified by:
interrupt in interface Controllable

isInterrupted

public final boolean isInterrupted()
Specified by:
isInterrupted in interface Controllable

isInterruptible

public final boolean isInterruptible()
Specified by:
isInterruptible in interface Controllable

isUndoable

public final boolean isUndoable()
Description copied from interface: Command
Checks whether the Command can be undone by the user.

Specified by:
isUndoable in interface Command<ResultType,MessageType>
Returns:
true if the Command can be undone, false otherwise

isDetermined

public final boolean isDetermined()
Specified by:
isDetermined in interface Progressable

getProgress

public final int getProgress()
Specified by:
getProgress in interface Progressable

getState

public final ControllableState getState()
Specified by:
getState in interface Controllable
Specified by:
getState in interface Progressable

setCommandStatus

protected final void setCommandStatus(ControllableState newStatus)
Sets the command status to the provided value and notifies the listeners.

Parameters:
newStatus - the command status to set.

getLabel

public final String getLabel()
Description copied from interface: Command
Returns the localized Command name.

Specified by:
getLabel in interface Command<ResultType,MessageType>
Returns:
the command name

getDescription

public final String getDescription()
Description copied from interface: Command
Returns the localized Command description.

Specified by:
getDescription in interface Command<ResultType,MessageType>
Returns:
the command description

addProgressableListener

public final void addProgressableListener(ProgressableListener listener)
Specified by:
addProgressableListener in interface Progressable

removeProgressableListener

public final void removeProgressableListener(ProgressableListener listener)
Specified by:
removeProgressableListener in interface Progressable

isPausable

public final boolean isPausable()
Specified by:
isPausable in interface Controllable

addControllableListener

public final void addControllableListener(ControllableListener listener)
Specified by:
addControllableListener in interface Controllable

removeControllableListener

public final void removeControllableListener(ControllableListener listener)
Specified by:
removeControllableListener in interface Controllable

clearControllableListener

public final void clearControllableListener()
Specified by:
clearControllableListener in interface Controllable

clearProgressableListener

public final void clearProgressableListener()
Specified by:
clearProgressableListener in interface Progressable

checkPreConditions

public final boolean checkPreConditions()
Description copied from interface: Command
Check that the Command preconditions are fulfilled.

Specified by:
checkPreConditions in interface Command<ResultType,MessageType>
Returns:
true is the preconditions of the command are all fulfilled.

setModels

public void setModels(DataModel anApplicationModel,
                      DataModel aBundleModel)
Description copied from interface: Command
Initializes the models of that the command can access.

Specified by:
setModels in interface Command<ResultType,MessageType>
Parameters:
anApplicationModel - the model of the application
aBundleModel - the model of the command bundle

getApplicationModel

public DataModel getApplicationModel()
Description copied from interface: Command
Gets the data model of the application.

Specified by:
getApplicationModel in interface Command<ResultType,MessageType>
Returns:
the data model of the application

getBundleModel

public DataModel getBundleModel()
Description copied from interface: Command
Gets the data model of the bundle.

Specified by:
getBundleModel in interface Command<ResultType,MessageType>
Returns:
the data model of the bundle

getLogLevel

public CommandLogLevel getLogLevel()
Description copied from interface: Command
Gets the verbosity level at which this command should be logged.

Specified by:
getLogLevel in interface Command<ResultType,MessageType>
Returns:
the log level


Copyright © 2010-2013 Artenum. All Rights Reserved.