1 package org.enhydra.shark.xpdl.elements; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.Map ; 7 8 import org.enhydra.shark.xpdl.XMLAttribute; 9 import org.enhydra.shark.xpdl.XMLCollectionElement; 10 import org.enhydra.shark.xpdl.XMLUtil; 11 import org.enhydra.shark.xpdl.XPDLConstants; 12 13 18 public class WorkflowProcess extends XMLCollectionElement { 19 20 protected transient ArrayList startingActivities; 21 protected transient ArrayList endingActivities; 22 23 public WorkflowProcess (WorkflowProcesses parent) { 24 super(parent, true); 25 } 26 27 protected void fillStructure () { 28 XMLAttribute attrName=new XMLAttribute(this,"Name", false); 29 XMLAttribute attrAccessLevel= 30 new XMLAttribute(this, 31 "AccessLevel", 32 false,new String [] { 33 "", 34 XPDLConstants.ACCESS_LEVEL_PUBLIC, 35 XPDLConstants.ACCESS_LEVEL_PRIVATE 36 }, 0); 37 ProcessHeader refProcessHeader=new ProcessHeader(this); 38 RedefinableHeader refRedefinableHeader=new RedefinableHeader(this); FormalParameters refFormalParameters=new FormalParameters(this); 40 DataFields refDataFields=new DataFields(this); Participants refParticipants=new Participants(this); Applications refApplications=new Applications(this); ActivitySets refActivitySets=new ActivitySets(this); Activities refActivities=new Activities(this); Transitions refTransitions=new Transitions(this); ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 48 super.fillStructure(); 49 add(attrName); 50 add(attrAccessLevel); 51 add(refProcessHeader); 52 add(refRedefinableHeader); 53 add(refFormalParameters); 54 add(refDataFields); 55 add(refParticipants); 56 add(refApplications); 57 add(refActivitySets); 58 add(refActivities); 59 add(refTransitions); 60 add(refExtendedAttributes); 61 } 62 63 public void initCaches () { 64 super.initCaches(); 65 Iterator it=getActivities().toElements().iterator(); 66 while (it.hasNext()) { 67 Activity act=(Activity)it.next(); 68 ArrayList trsI=act.getIncomingTransitions(); 69 ArrayList trsNEO=act.getNonExceptionalOutgoingTransitions(); 70 if (trsI.size()==0) { 72 startingActivities.add(act); 73 } else if (trsI.size()==1) { 75 Transition t=(Transition)trsI.get(0); 76 if (t.getFrom().equals(t.getTo())) { 77 startingActivities.add(act); 78 } 79 } 80 if (trsNEO.size()==0) { 81 endingActivities.add(act); 82 } else if (trsNEO.size()==1) { 83 Transition t=(Transition)trsNEO.get(0); 84 if (t.getFrom().equals(t.getTo())) { 85 endingActivities.add(act); 86 } 87 } 88 } 89 } 90 91 public void clearCaches () { 92 startingActivities=new ArrayList (); 93 endingActivities=new ArrayList (); 94 super.clearCaches(); 95 } 96 97 public ArrayList getStartingActivities () { 98 if (!isReadOnly) { 99 throw new RuntimeException ("This method can be used only in read-only mode!"); 100 } 101 return startingActivities; 102 } 103 104 public ArrayList getEndingActivities () { 105 if (!isReadOnly) { 106 throw new RuntimeException ("This method can be used only in read-only mode!"); 107 } 108 return endingActivities; 109 } 110 111 115 public Map getAllVariables () { 116 Map m=new HashMap (); 117 Iterator it=getDataFields().toElements().iterator(); 118 while (it.hasNext()) { 119 DataField df=(DataField)it.next(); 120 m.put(df.getId(),df); 121 } 122 it=XMLUtil.getPackage(this).getDataFields().toElements().iterator(); 123 while (it.hasNext()) { 124 DataField df=(DataField)it.next(); 125 if (!m.containsKey(df.getId())) { 126 m.put(df.getId(),df); 127 } 128 } 129 it=getFormalParameters().toElements().iterator(); 130 while (it.hasNext()) { 131 FormalParameter fp=(FormalParameter)it.next(); 132 if (!m.containsKey(fp.getId())) { 133 m.put(fp.getId(),fp); 134 } 135 } 136 return m; 137 } 138 139 public Application getApplication (String Id) { 140 return getApplications().getApplication(Id); 141 } 142 143 public Participant getParticipant(String Id) { 144 return getParticipants().getParticipant(Id); 145 } 146 147 public DataField getDataField (String Id) { 148 return getDataFields().getDataField(Id); 149 } 150 151 public FormalParameter getFormalParameter (String Id) { 152 return getFormalParameters().getFormalParameter(Id); 153 } 154 155 public ActivitySet getActivitySet (String Id) { 156 return getActivitySets().getActivitySet(Id); 157 } 158 159 public Activity getActivity (String Id) { 160 return getActivities().getActivity(Id); 161 } 162 163 public Transition getTransition (String Id) { 164 return getTransitions().getTransition(Id); 165 } 166 167 public String getName() { 168 return get("Name").toValue(); 169 } 170 public void setName(String name) { 171 set("Name",name); 172 } 173 public XMLAttribute getAccessLevelAttribute() { 174 return (XMLAttribute)get("AccessLevel"); 175 } 176 public String getAccessLevel() { 177 return getAccessLevelAttribute().toValue(); 178 } 179 public void setAccessLevelNONE() { 180 getAccessLevelAttribute().setValue(""); 181 } 182 public void setAccessLevelPUBLIC() { 183 getAccessLevelAttribute().setValue(XPDLConstants.ACCESS_LEVEL_PUBLIC); 184 } 185 public void setAccessLevelPRIVATE() { 186 getAccessLevelAttribute().setValue(XPDLConstants.ACCESS_LEVEL_PRIVATE); 187 } 188 public Applications getApplications() { 189 return (Applications)get("Applications"); 190 } 191 public DataFields getDataFields() { 192 return (DataFields)get("DataFields"); 193 } 194 public ExtendedAttributes getExtendedAttributes() { 195 return (ExtendedAttributes)get("ExtendedAttributes"); 196 } 197 public ProcessHeader getProcessHeader() { 198 return (ProcessHeader)get("ProcessHeader"); 199 } 200 public Participants getParticipants() { 201 return (Participants)get("Participants"); 202 } 203 public RedefinableHeader getRedefinableHeader() { 204 return (RedefinableHeader)get("RedefinableHeader"); 205 } 206 public Activities getActivities() { 207 return (Activities)get("Activities"); 208 } 209 public Transitions getTransitions() { 210 return (Transitions)get("Transitions"); 211 } 212 public ActivitySets getActivitySets() { 213 return (ActivitySets)get("ActivitySets"); 214 } 215 public FormalParameters getFormalParameters() { 216 return (FormalParameters)get("FormalParameters"); 217 } 218 219 } 220 | Popular Tags |