View Javadoc
1 package org.smartcomps.twister.engine.priv.core.definition.impl; 2 3 import org.smartcomps.twister.engine.exception.ProcessStructuralException; 4 import org.smartcomps.twister.engine.priv.core.definition.Activity; 5 import org.smartcomps.twister.engine.priv.core.definition.Switch; 6 7 import java.util.ArrayList; 8 import java.util.List; 9 import java.util.SortedMap; 10 import java.util.TreeMap; 11 12 /*** 13 * Persistent implementation of the Switch interface. 14 * @see org.smartcomps.twister.engine.priv.core.definition.Switch 15 */ 16 public class SwitchImpl extends StructuredActivityImpl implements Switch { 17 18 private List conditions = new ArrayList(); 19 20 public void addCondition(String condition, Activity activity) { 21 int actPos = getActivities().indexOf(activity); 22 23 if (actPos < 0) throw new ProcessStructuralException("Activity has not been attributed to " + 24 "this Pick container at creation time."); 25 if (actPos != conditions.size()) throw new ProcessStructuralException("Conditions must be " + 26 "added in the same order as activities have been added in this container when they " + 27 "have been created, please check the ActivityFactory.createActivity method."); 28 29 conditions.add(condition); 30 } 31 32 public List getConditions() { 33 return conditions; 34 } 35 36 public SortedMap getActivityConditions() { 37 TreeMap orderedMap = new TreeMap(); 38 for (int m = 0; m < getActivities().size(); m++) { 39 Activity activity = (Activity) getActivities().get(m); 40 if (m < conditions.size()) { 41 orderedMap.put(activity, conditions.get(m)); 42 } else { 43 orderedMap.put(activity, ""); 44 } 45 } 46 return orderedMap; 47 } 48 49 public void setConditions(List conditions) { 50 this.conditions = conditions; 51 } 52 53 public String getCondition(int index) { 54 return (String) conditions.get(index); 55 } 56 57 public void setOtherwise(Activity activity) { 58 Activity last = (Activity) getActivities().get(getActivities().size() - 1); 59 if (!last.equals(activity)) { 60 throw new ProcessStructuralException("The otherwise activity must have been created and " + 61 "included in this container in the last position."); 62 } 63 } 64 }

This page was automatically generated by Maven