org.apache.wiki.workflow
Class AbstractStep

java.lang.Object
  extended by org.apache.wiki.workflow.AbstractStep
All Implemented Interfaces:
Serializable, Step
Direct Known Subclasses:
Decision, Task

public abstract class AbstractStep
extends Object
implements Step

Abstact superclass that provides a complete implementation of most Step methods; subclasses need only implement execute() and getActor().

Since:
2.5
See Also:
Serialized Form

Constructor Summary
protected AbstractStep(String messageKey)
          Protected constructor that creates a new Step with a specified message key.
  AbstractStep(Workflow workflow, String messageKey)
          Constructs a new Step belonging to a specified Workflow and having a specified message key.
 
Method Summary
protected  void addError(String message)
          Protected helper method that adds a String representing an error message to the Step's cached errors list.
 void addSuccessor(Outcome outcome, Step step)
          Adds a successor Step to this one, which will be triggered by a supplied Outcome.
abstract  Outcome execute()
           Executes the processing for this Step and returns an Outcome indicating if it succeeded (Outcome.STEP_COMPLETE or Outcome.STEP_ABORT).
abstract  Principal getActor()
          The Principal responsible for completing this Step, such as a system user or actor assigned to a Decision.
 Collection getAvailableOutcomes()
          Returns a Collection of available outcomes, such as "approve", "deny" or "reassign", in the order in which they were added via Step.addSuccessor(Outcome, Step).
 Date getEndTime()
          The end time for this Step.
 List getErrors()
          Returns a List of error strings generated by this Step.
 Serializable[] getMessageArguments()
          Returns the message arguments for this Step, typically by delegating to the parent Workflow's Workflow.getMessageArguments() method.
 String getMessageKey()
          Message key for human-friendly name of this Step, including any parameter substitutions.
 Outcome getOutcome()
          Returns the Outcome of this Step's processing; by default, Outcome.STEP_CONTINUE.
 Principal getOwner()
          Convenience method that returns the owner of the Workflow by delegating to Workflow.getOwner().
 Date getStartTime()
          The start time for this Step.
 Step getSuccessor(Outcome outcome)
          Identifies the next Step for a particular Outcome; if there is no next Step for this Outcome, this method returns null.
 Workflow getWorkflow()
          Gets the Workflow that is the parent of this Step.
 boolean isCompleted()
          Determines whether the Step is completed; if not, it is by definition awaiting action by the owner or in process.
 boolean isStarted()
          Determines whether the Step has started.
 void setOutcome(Outcome outcome)
          Sets the current Outcome for the step.
protected  void setWorkflow(Workflow workflow)
          Protected method that sets the parent Workflow post-construction.
 void start()
          Starts the Step, and sets the start time to the moment when this method is first invoked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStep

protected AbstractStep(String messageKey)
Protected constructor that creates a new Step with a specified message key. After construction, the protected method setWorkflow(Workflow) should be called.

Parameters:
messageKey - the Step's message key, such as decision.editPageApproval. By convention, the message prefix should be a lower-case version of the Step's type, plus a period (e.g., task. and decision.).

AbstractStep

public AbstractStep(Workflow workflow,
                    String messageKey)
Constructs a new Step belonging to a specified Workflow and having a specified message key.

Parameters:
workflow - the workflow the Step belongs to
messageKey - the Step's message key, such as decision.editPageApproval. By convention, the message prefix should be a lower-case version of the Step's type, plus a period (e.g., task. and decision.).
Method Detail

addSuccessor

public final void addSuccessor(Outcome outcome,
                               Step step)
Adds a successor Step to this one, which will be triggered by a supplied Outcome. Implementations should respect the order in which Outcomes are added; Step.getAvailableOutcomes() should return them in the same order they were added.

Specified by:
addSuccessor in interface Step
Parameters:
outcome - the Outcome triggering a particular successor Step
step - the Step to associated with this Outcomes (null denotes no Steps)

getAvailableOutcomes

public final Collection getAvailableOutcomes()
Returns a Collection of available outcomes, such as "approve", "deny" or "reassign", in the order in which they were added via Step.addSuccessor(Outcome, Step). Concrete implementations should always return a defensive copy of the outcomes, not the original backing collection.

Specified by:
getAvailableOutcomes in interface Step
Returns:
the set of outcomes

getErrors

public final List getErrors()
Returns a List of error strings generated by this Step. If this Step generated no errors, this method returns a zero-length array.

Specified by:
getErrors in interface Step
Returns:
the errors

execute

public abstract Outcome execute()
                         throws WikiException

Executes the processing for this Step and returns an Outcome indicating if it succeeded (Outcome.STEP_COMPLETE or Outcome.STEP_ABORT). Processing instructions can do just about anything, such as executing custom business logic or changing the Step's final outcome via Step.setOutcome(Outcome). A return value of STEP_COMPLETE indicates that the instructions executed completely, without errors; STEP_ABORT indicates that the Step and its parent Workflow should be aborted (that is, fail silently without error). If the execution step encounters any errors, it should throw a WikiException or a subclass.

Note that successful execution of this methods does not necessarily mean that the Step is considered "complete"; rather, it just means that it has executed. Therefore, it is possible that execute could run multiple times.

Specified by:
execute in interface Step
Returns:
the result of the Step, expressed as an Outcome
Throws:
WikiException - if the step encounters errors while executing

getActor

public abstract Principal getActor()
The Principal responsible for completing this Step, such as a system user or actor assigned to a Decision.

Specified by:
getActor in interface Step
Returns:
the responsible Principal

getEndTime

public final Date getEndTime()
The end time for this Step. This value should be set when the step completes. Returns Workflow.TIME_NOT_SET if not completed yet.

Specified by:
getEndTime in interface Step
Returns:
the end time

getMessageArguments

public final Serializable[] getMessageArguments()
Returns the message arguments for this Step, typically by delegating to the parent Workflow's Workflow.getMessageArguments() method.

Specified by:
getMessageArguments in interface Step
Returns:
the message arguments.

getMessageKey

public final String getMessageKey()
Message key for human-friendly name of this Step, including any parameter substitutions. By convention, the message prefix should be a lower-case version of the Step's type, plus a period (e.g., task. and decision.).

Specified by:
getMessageKey in interface Step
Returns:
the message key for this Step.

getOutcome

public final Outcome getOutcome()
Returns the Outcome of this Step's processing; by default, Outcome.STEP_CONTINUE.

Specified by:
getOutcome in interface Step
Returns:
the outcome

getOwner

public Principal getOwner()
Convenience method that returns the owner of the Workflow by delegating to Workflow.getOwner().

Specified by:
getOwner in interface Step
Returns:
the owner of the Workflow

getStartTime

public final Date getStartTime()
The start time for this Step. Returns Workflow.TIME_NOT_SET if not started yet.

Specified by:
getStartTime in interface Step
Returns:
the start time

getWorkflow

public final Workflow getWorkflow()
Gets the Workflow that is the parent of this Step.

Specified by:
getWorkflow in interface Step
Returns:
the workflow

isCompleted

public final boolean isCompleted()
Determines whether the Step is completed; if not, it is by definition awaiting action by the owner or in process. If a Step has completed, it must also return a non-null result for Step.getOutcome().

Specified by:
isCompleted in interface Step
Returns:
true if the Step has completed; false if not.

isStarted

public final boolean isStarted()
Determines whether the Step has started.

Specified by:
isStarted in interface Step
Returns:
true if the Step has started; false if not.

setOutcome

public final void setOutcome(Outcome outcome)
Sets the current Outcome for the step. If the Outcome is a "completion" Outcome, it should also sets the completon time and mark the Step as complete. Once a Step has been marked complete, this method cannot be called again. If the supplied Outcome is not in the set returned by Step.getAvailableOutcomes(), or is not Outcome.STEP_CONTINUE or Outcome.STEP_ABORT, this method returns an IllegalArgumentException. If the caller attempts to set an Outcome and the Step has already completed, this method throws an IllegalStateException.

Specified by:
setOutcome in interface Step
Parameters:
outcome - whether the step should be considered completed

start

public final void start()
                 throws WikiException
Starts the Step, and sets the start time to the moment when this method is first invoked. If this Step has already been started, this method throws an IllegalStateException. If the Step cannot be started because the underlying implementation encounters an error, it the implementation should throw a WikiException.

Specified by:
start in interface Step
Throws:
WikiException - if the step encounters errors while starting

getSuccessor

public final Step getSuccessor(Outcome outcome)
Identifies the next Step for a particular Outcome; if there is no next Step for this Outcome, this method returns null.

Specified by:
getSuccessor in interface Step
Parameters:
outcome - the outcome
Returns:
the next step

setWorkflow

protected final void setWorkflow(Workflow workflow)
Protected method that sets the parent Workflow post-construction.

Parameters:
workflow - the parent workflow to set

addError

protected final void addError(String message)
Protected helper method that adds a String representing an error message to the Step's cached errors list.

Parameters:
message - the error message


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.