1 package org.enhydra.shark.xpdl.elements; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 6 import org.enhydra.shark.xpdl.XMLAttribute; 7 import org.enhydra.shark.xpdl.XMLCollectionElement; 8 import org.enhydra.shark.xpdl.XMLElement; 9 import org.enhydra.shark.xpdl.XMLUtil; 10 import org.enhydra.shark.xpdl.XPDLConstants; 11 12 17 public class Activity extends XMLCollectionElement { 18 19 protected transient ArrayList outgoingTransitions; 20 protected transient ArrayList incomingTransitions; 21 protected transient ArrayList exceptionalOutgoingTransitions; 22 protected transient ArrayList nonExceptionalOutgoingTransitions; 23 24 public Activity (Activities acts) { 25 super(acts, true); 26 } 27 28 protected void fillStructure () { 29 XMLAttribute attrName=new XMLAttribute(this,"Name", false); 30 Description refDescription=new Description(this); Limit refLimit=new Limit(this); ActivityTypes refType=new ActivityTypes(this); 34 Performer refPerformer=new Performer(this); StartMode refStartMode=new StartMode(this); FinishMode refFinishMode=new FinishMode(this); Priority refPriority=new Priority(this); Deadlines refDeadlines=new Deadlines(this); SimulationInformation refSimulationInformation=new SimulationInformation(this); Icon refIcon=new Icon(this); Documentation refDocumentation=new Documentation(this); TransitionRestrictions refTransitionRestrictions=new TransitionRestrictions(this); ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 46 super.fillStructure(); 47 add(attrName); 48 add(refDescription); 49 add(refLimit); 50 add(refType); 51 add(refPerformer); 52 add(refStartMode); 53 add(refFinishMode); 54 add(refPriority); 55 add(refDeadlines); 56 add(refSimulationInformation); 57 add(refIcon); 58 add(refDocumentation); 59 add(refTransitionRestrictions); 60 add(refExtendedAttributes); 61 } 62 63 public void initCaches () { 64 super.initCaches(); 65 Transitions ts; 66 if (getParent().getParent() instanceof WorkflowProcess) { 67 ts=((WorkflowProcess)getParent().getParent()).getTransitions(); 68 } else { 69 ts=((ActivitySet)getParent().getParent()).getTransitions(); 70 } 71 TransitionRestrictions trs=getTransitionRestrictions(); 72 ArrayList trefs=null; 73 if (trs.size()>0) { 74 trefs=((TransitionRestriction)trs.get(0)).getSplit().getTransitionRefs().toElements(); 75 } else { 76 trefs=new ArrayList (); 77 } 78 79 Iterator it=trefs.iterator(); 80 while (it.hasNext()) { 81 TransitionRef tref=(TransitionRef)it.next(); 82 Transition t=ts.getTransition(tref.getId()); 83 outgoingTransitions.add(t); 84 putTransitionInTheRightList(t); 85 } 86 it=ts.toElements().iterator(); 87 while (it.hasNext()) { 88 Transition t=(Transition)it.next(); 89 if (!outgoingTransitions.contains(t) && t.getFrom().equals(getId())) { 90 outgoingTransitions.add(t); 91 putTransitionInTheRightList(t); 92 } 93 if (t.getTo().equals(getId())) { 94 incomingTransitions.add(t); 95 } 96 } 97 } 98 99 public void clearCaches () { 100 clearInternalCaches(); 101 super.clearCaches(); 102 } 103 104 protected void clearInternalCaches () { 105 outgoingTransitions=new ArrayList (); 106 incomingTransitions=new ArrayList (); 107 exceptionalOutgoingTransitions=new ArrayList (); 108 nonExceptionalOutgoingTransitions=new ArrayList (); 109 } 110 111 protected void putTransitionInTheRightList (Transition t) { 112 Condition condition = t.getCondition(); 113 String condType=condition.getType(); 114 if (condType.equals(XPDLConstants.CONDITION_TYPE_EXCEPTION) || 115 condType.equals(XPDLConstants.CONDITION_TYPE_DEFAULTEXCEPTION)) { 116 exceptionalOutgoingTransitions.add(t); 117 } else { 118 nonExceptionalOutgoingTransitions.add(t); 119 } 120 } 121 122 public ArrayList getOutgoingTransitions () { 123 if (!isReadOnly) { 124 throw new RuntimeException ("This method can be used only in read-only mode!"); 125 } 126 return outgoingTransitions; 127 } 128 129 public ArrayList getIncomingTransitions () { 130 if (!isReadOnly) { 131 throw new RuntimeException ("This method can be used only in read-only mode!"); 132 } 133 return incomingTransitions; 134 } 135 136 public ArrayList getNonExceptionalOutgoingTransitions () { 137 if (!isReadOnly) { 138 throw new RuntimeException ("This method can be used only in read-only mode!"); 139 } 140 return nonExceptionalOutgoingTransitions; 141 } 142 143 public ArrayList getExceptionalOutgoingTransitions () { 144 if (!isReadOnly) { 145 throw new RuntimeException ("This method can be used only in read-only mode!"); 146 } 147 return exceptionalOutgoingTransitions; 148 } 149 150 public boolean isAndTypeSplit () { 151 return XMLUtil.isANDTypeSplitOrJoin(this,0); 152 } 153 154 public boolean isAndTypeJoin () { 155 return XMLUtil.isANDTypeSplitOrJoin(this,1); 156 } 157 158 public int getActivityStartMode () { 159 return XMLUtil.getStartMode(this); 160 } 161 162 public int getActivityFinishMode () { 163 return XMLUtil.getFinishMode(this); 164 } 165 166 public int getActivityType () { 167 XMLElement ch=getActivityTypes().getChoosen(); 168 if (ch instanceof Route) { 169 return XPDLConstants.ACTIVITY_TYPE_ROUTE; 170 } else if (ch instanceof Implementation) { 171 ch=((Implementation)ch).getImplementationTypes().getChoosen(); 172 if (ch instanceof Tools) { 173 return XPDLConstants.ACTIVITY_TYPE_TOOL; 174 } else if (ch instanceof SubFlow){ 175 return XPDLConstants.ACTIVITY_TYPE_SUBFLOW; 176 } else { 177 return XPDLConstants.ACTIVITY_TYPE_NO; 178 } 179 } else { 180 return XPDLConstants.ACTIVITY_TYPE_BLOCK; 181 } 182 183 } 184 185 public boolean isSubflowSynchronous () { 186 if (getActivityType()!=XPDLConstants.ACTIVITY_TYPE_SUBFLOW) { 187 throw new RuntimeException ("The activity type is not SubFlow!"); 188 } 189 return XMLUtil.isSubflowSynchronous(this); 190 } 191 192 public String getName() { 193 return get("Name").toValue(); 194 } 195 public void setName(String name) { 196 set("Name",name); 197 } 198 public Deadlines getDeadlines() { 199 return (Deadlines)get("Deadlines"); 200 } 201 public String getDescription() { 202 return get("Description").toValue(); 203 } 204 public void setDescription(String description) { 205 set("Description",description); 206 } 207 public String getDocumentation() { 208 return get("Documentation").toValue(); 209 } 210 public void setDocumentation(String documentation) { 211 set("Documentation",documentation); 212 } 213 public ExtendedAttributes getExtendedAttributes() { 214 return (ExtendedAttributes)get("ExtendedAttributes"); 215 } 216 public FinishMode getFinishMode() { 217 return (FinishMode)get("FinishMode"); 218 } 219 public String getIcon() { 220 return get("Icon").toValue(); 221 } 222 public void setIcon(String icon) { 223 set("Icon",icon); 224 } 225 public String getLimit() { 226 return get("Limit").toValue(); 227 } 228 public void setLimit(String limit) { 229 set("Limit",limit); 230 } 231 public String getPerformer() { 232 return get("Performer").toValue(); 233 } 234 public void setPerformer(String performer) { 235 set("Performer",performer); 236 } 237 public String getPriority() { 238 return get("Priority").toValue(); 239 } 240 public void setPriority(String priority) { 241 set("Priority",priority); 242 } 243 public SimulationInformation getSimulationInformation() { 244 return (SimulationInformation)get("SimulationInformation"); 245 } 246 public StartMode getStartMode() { 247 return (StartMode)get("StartMode"); 248 } 249 public TransitionRestrictions getTransitionRestrictions() { 250 return (TransitionRestrictions)get("TransitionRestrictions"); 251 } 252 public ActivityTypes getActivityTypes() { 253 return (ActivityTypes)get("Type"); 254 } 255 256 } 257 258 | Popular Tags |