4 Replies Latest reply on May 29, 2008 6:25 AM by Walter Taus

    Trying to implement a loop in JPDL

    Walter Taus Newbie

      Hello,

      I have tried to implement a loop in JPDL. My source looks as follows

      <?xml version="1.0" encoding="UTF-8"?>
      <process-definition xmlns="" name="Pool">
      <start-state name="StartState1212041906165">
      <transition to="LoopBefore3/LoopBefore3LoopCounterInit"></transition>
      </start-state>
      <super-state name="LoopBefore3">
      <node name="LoopBefore3LoopCounterInit">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      executionContext.setVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter", 0);
      executionContext.leaveNode();
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3LoopDecision"></transition>
      </node>
      <decision name="LoopBefore3LoopDecision">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3"></transition>
      <transition name="To_mTMyICyoEd2cO4xcRmnV4w" to="../End/End">
      <condition expression="#{contextInstance.variables['_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter']>= '3'}"></condition>
      </transition>
      </decision>
      <task-node name="LoopBefore3">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      executionContext.leaveNode();
      </expression></script></event>
      <event type="node-leave">
      <script><expression>
      executionContext.setVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter", executionContext.getVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter") + 1);
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3LoopDecision"></transition>
      <task name="LoopBefore3"></task>
      </task-node>
      </super-state>
      <super-state name="End">
      <end-state name="End">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      </expression></script></event>
      </end-state>
      </super-state>
      </process-definition>
      

      I receive the following at the Console:
      StartState1212041906165
      LoopBefore3LoopCounterInit entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      End entered
      LoopBefore3LoopDecision entered
      End entered
      

      I am totally puzzled with this result, as I am hitting twice the end-state. The first time entering the end state does not seem to have any effect. Can anyone explain what I am doing wrong here.

      Thanks,
      Walter