View Javadoc
1 package org.smartcomps.twister.engine.priv.core.dynamic.impl; 2 3 import org.smartcomps.twister.engine.priv.core.dynamic.WhileEC; 4 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext; 5 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory; 6 import org.smartcomps.twister.engine.priv.core.definition.Activity; 7 import org.smartcomps.twister.engine.priv.core.definition.While; 8 import org.smartcomps.twister.engine.priv.core.definition.impl.WhileImpl; 9 import org.smartcomps.twister.engine.priv.expression.ExpressionProcessorFactory; 10 import org.smartcomps.twister.engine.exception.ExecutionException; 11 import org.smartcomps.twister.engine.exception.XPathEvaluationException; 12 import org.smartcomps.twister.common.persistence.DBSessionException; 13 14 import java.util.Collection; 15 16 /*** 17 * Persistent implementation of the WhileEC interface. 18 * @see org.smartcomps.twister.engine.priv.core.dynamic.WhileEC 19 */ 20 public class WhileECImpl extends StructuredECImpl implements WhileEC { 21 22 public void execute() { 23 executeContext(); 24 } 25 26 public void notifyExecution(ExecutionContext ec) { 27 this.setStatus(ACTIVE); 28 if (getInstance() == null) { 29 getContainer().notifyExecution(this); 30 } else { 31 getInstance().notifyExecution(this); 32 } 33 } 34 35 public void notifyTermination(ExecutionContext ec) { 36 executeContext(); 37 } 38 39 private boolean isTrueCondition() throws XPathEvaluationException { 40 return ExpressionProcessorFactory.getBPELExpressionProcessor().evaluateAsBoolean( 41 fetchInstance(), ((While)getActivity()).getCondition()); 42 } 43 44 private void executeContext() { 45 Activity activity = (Activity) getActivity().getActivities().get(0); 46 47 // Evaluating while condition to see if we're going to loop again 48 boolean conditionEval = false; 49 try { 50 conditionEval = isTrueCondition(); 51 } catch (XPathEvaluationException e) { 52 throw new ExecutionException(e); 53 } 54 55 System.out.println("*************** Executing while with cond : " + conditionEval); 56 System.out.println("Condition " + ((While)getActivity()).getCondition()); 57 58 if (activity != null && conditionEval) { 59 // If there are activities in this while and condition evaluates to true 60 // executing the child activity (and therefore eventually looping) 61 Activity childActivity = (Activity) ((WhileImpl)getActivity()).getActivities().get(0); 62 ExecutionContext context = null; 63 try { 64 context = ExecutionContextFactory.createExecutionContext(childActivity, this); 65 } catch (DBSessionException e) { 66 throw new ExecutionException("An error occured when trying to create an execution context " + 67 "for activity " + childActivity + " in while execution context " + this, e); 68 } 69 context.execute(); 70 } else { 71 // Finished looping, while completes and notifies its container 72 this.setStatus(COMPLETED); 73 if (getInstance() == null) { 74 getContainer().notifyTermination(this); 75 } else { 76 getInstance().notifyTermination(this); 77 } 78 } 79 } 80 81 public Activity getActivityForChildContext(ExecutionContext ec) { 82 return (Activity) getActivity().getActivities().get(0); 83 } 84 85 public ExecutionContext getExecution(Activity childActivity) { 86 if (getExecutionContexts().size() > 0) { 87 return (ExecutionContext) getExecutionContexts().get(getExecutionContexts().size() - 1); 88 } else { 89 return null; 90 } 91 } 92 }

This page was automatically generated by Maven