1 17 18 19 20 package org.apache.lenya.workflow.impl; 21 22 import org.apache.lenya.workflow.Action; 23 import org.apache.lenya.workflow.Condition; 24 import org.apache.lenya.workflow.Event; 25 import org.apache.lenya.workflow.Situation; 26 import org.apache.lenya.workflow.Transition; 27 import org.apache.lenya.workflow.WorkflowException; 28 import org.apache.lenya.workflow.WorkflowInstance; 29 import org.apache.log4j.Category; 30 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 35 38 public class TransitionImpl implements Transition { 39 40 private static final Category log = Category.getInstance(TransitionImpl.class); 41 42 47 protected TransitionImpl(StateImpl sourceState, StateImpl destinationState) { 48 source = sourceState; 49 destination = destinationState; 50 } 51 52 private List actions = new ArrayList (); 53 private boolean isSynchronized = false; 54 55 59 public Action[] getActions() { 60 return (Action[]) actions.toArray(new Action[actions.size()]); 61 } 62 63 67 public void addAction(Action action) { 68 actions.add(action); 69 } 70 71 private List conditions = new ArrayList (); 72 73 77 public Condition[] getConditions() { 78 return (Condition[]) conditions.toArray(new Condition[conditions.size()]); 79 } 80 81 85 public void addCondition(Condition condition) { 86 conditions.add(condition); 87 } 88 89 private Event event; 90 91 95 public Event getEvent() { 96 return event; 97 } 98 99 103 public void setEvent(Event anEvent) { 104 event = anEvent; 105 } 106 107 private StateImpl source; 108 109 113 public StateImpl getSource() { 114 return source; 115 } 116 117 private StateImpl destination; 118 119 123 public StateImpl getDestination() { 124 return destination; 125 } 126 127 134 public boolean canFire(Situation situation, WorkflowInstance instance) throws WorkflowException { 135 Condition[] conditions = getConditions(); 136 boolean canFire = true; 137 138 int i = 0; 139 while (canFire && i < conditions.length) { 140 canFire = canFire && conditions[i].isComplied(situation, instance); 141 if (log.isDebugEnabled()) { 142 log.debug("Condition [" + conditions[i] + "] returns [" + canFire + "]"); 143 } 144 i++; 145 } 146 147 return canFire; 148 } 149 150 153 public String toString() { 154 String string = getEvent().getName() + " ["; 155 Condition[] conditions = getConditions(); 156 157 for (int i = 0; i < conditions.length; i++) { 158 if (i > 0) { 159 string += ", "; 160 } 161 162 string += conditions[i].toString(); 163 } 164 165 string += "]"; 166 167 Action[] actions = getActions(); 168 169 if (actions.length > 0) { 170 string += " / "; 171 172 for (int i = 0; i < actions.length; i++) { 173 if (i > 0) { 174 string += ", "; 175 } 176 177 string += actions[i].toString(); 178 } 179 } 180 181 return string; 182 } 183 184 188 public boolean isSynchronized() { 189 return isSynchronized; 190 } 191 192 196 protected void setSynchronized(boolean isSynchronized) { 197 this.isSynchronized = isSynchronized; 198 } 199 200 } 201 | Popular Tags |