Class ForLoop<InputType>

java.lang.Object
org.chenile.owiz.impl.CommandBase<InputType>
org.chenile.owiz.impl.Chain<InputType>
org.chenile.owiz.impl.ognl.ForLoop<InputType>
Type Parameters:
InputType -
All Implemented Interfaces:
AttachableCommand<InputType>, BypassableCommand<InputType>, Command<InputType>, OrchestrationAware<InputType>

public class ForLoop<InputType> extends Chain<InputType>
Repeatedly, execute the attached commands till the expression specified by condition evaluates to false. This command shows the power of the OWIZ XML Parser and its ability to create a custom Domain Specific Language without making changes to the parser itself.

This command has the four components of a typical 'for' loop:

  • Initialization - which is assumed to have happened before we get control to this command
  • Condition - which is an expression that is evaluated at the end of every execution
  • The Counter incrementation - which is performed at the end of executing all commands
  • The Loop body - which is all the commands contained in the for Loop
  • This command runs in two modes that are determined by the value of "evaluateAfterEveryCommand"

    If evaluateAfterEveryCommand is true then the condition is evaluated after every command. If it is condition is true then the command aborts after the command.Else it continues.

    If evaluateAfterEveryCommand is false then the condition is evaluated once after all the commands. If the condition is true then it repeats.

    Please see the test case for a good example of this.

    • Field Details

    • Constructor Details

      • ForLoop

        public ForLoop()
    • Method Details

      • shouldRepeat

        protected boolean shouldRepeat(InputType context) throws Exception
        Determines if the loop should repeat. If the condition expression does not exist, it will evaluate to false.

        The increment command (if it exists) is then executed before evaluating the condition using OGNL

        Note that if the incrementCommand does not exist, then the body of the loop must have done the incrementation (just like a normal for loop). Else there can be an infinite loop!

        Parameters:
        context - the execution context
        Returns:
        true if loops should repeat, false otherwise.
        Throws:
        Exception - OGNL exception
      • isConditionTrue

        protected boolean isConditionTrue(InputType context) throws Exception
        Throws:
        Exception
      • shouldStopChain

        protected boolean shouldStopChain(InputType context) throws Exception
        Description copied from class: Chain
        AN extension point to allow sub classes to stop a chain if a condition is satisfied.
        Overrides:
        shouldStopChain in class Chain<InputType>
        Parameters:
        context - containing the data required.
        Returns:
        false by default.
        Throws:
        Exception - .
      • doExecute

        protected void doExecute(InputType context) throws Exception
        Overrides:
        doExecute in class Chain<InputType>
        Throws:
        Exception
      • attachCommand

        public void attachCommand(AttachmentDescriptor<InputType> attachmentDescriptor, CommandDescriptor<InputType> command)
        Description copied from class: Chain
        Allow a command to attach itself to this chain. If the index is not specified then the attachment order defines the execution order. Else if index is explicitly specified then the execution order would be the ascending order of the index.
        Specified by:
        attachCommand in interface AttachableCommand<InputType>
        Overrides:
        attachCommand in class Chain<InputType>