001: /*
002: * Created on Jul 14, 2003
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl.bpm.condition;
008:
009: import java.util.ArrayList;
010: import java.util.HashMap;
011:
012: import org.xdev.base.xssl.*;
013:
014: /**
015: * @author AYegorov
016: *
017: * To change the template for this generated type comment go to
018: * Window>Preferences>Java>Code Generation>Code and Comments
019: */
020: public class Condition extends XSSLActionIterator {
021: private Object returnValue = null;
022:
023: /**
024: * @param id
025: */
026: public Condition(String id) {
027: super (id);
028: // TODO Auto-generated constructor stub
029: }
030:
031: /**
032: * @param id
033: * @param properties
034: */
035: public Condition(String id, HashMap properties) {
036: super (id, properties);
037: // TODO Auto-generated constructor stub
038: }
039:
040: /* (non-Javadoc)
041: * @see org.xdev.base.transaction.TemplateAbstractAction#process()
042: */
043: protected void set() throws Exception {
044: Exception ex = null;
045: XSSLAction ifCondition = (XSSLAction) this .getElement(0);
046: XSSLAction thenExpression = (XSSLAction) this .getElement(1);
047: if (ifCondition.execute(this )) {
048:
049: this .logDebug("If condition is true...");
050:
051: thenExpression.execute(this );
052: if (thenExpression instanceof XSSLReturn) {
053: this .returnValue = ((XSSLReturn) thenExpression)
054: .getObjectValue();
055: }
056: ex = thenExpression.getException();
057: thenExpression = null;
058: this .iterationIndex = this .getCount();
059: } else {
060:
061: this .logDebug("If condition is false...");
062:
063: this .iterationIndex = 2;
064: }
065: ifCondition = null;
066: if (ex != null) {
067: throw ex;
068: }
069: }
070:
071: protected int setIterationIndex() {
072: return this .iterationIndex;
073: }
074:
075: public Object getObjectValue() {
076: return this .returnValue;
077: }
078:
079: /* (non-Javadoc)
080: * @see org.xdev.base.transaction.AbstractTransactionIterator#invoke(org.xdev.base.transaction.AbstractTransaction)
081: */
082: protected void invoke(XSSLAction elseCondition) throws Exception {
083: Exception ex = null;
084:
085: this .logDebug("Else condition: " + elseCondition);
086:
087: if (elseCondition.getExecutionStatus()) {
088: if (this .iterationSize > this .iterationIndex + 1) {
089: XSSLAction elseResult = (XSSLAction) this
090: .getElement(this .iterationIndex++);
091: if (elseResult instanceof XSSLReturn) {
092: this .returnValue = ((XSSLReturn) elseResult)
093: .getObjectValue();
094: this .breakIteration();
095: }
096: ex = elseResult.getException();
097: elseResult = null;
098: } else {
099: if (elseCondition instanceof XSSLReturn) {
100: this .returnValue = ((XSSLReturn) elseCondition)
101: .getObjectValue();
102: this.breakIteration();
103: }
104: }
105: if (ex == null) {
106: ex = elseCondition.getException();
107: }
108: }
109: if (ex != null) {
110: throw ex;
111: }
112: }
113: }
|