001: package org.enhydra.shark.xpdl.elements;
002:
003: import java.util.ArrayList;
004: import java.util.HashMap;
005: import java.util.Iterator;
006: import java.util.Map;
007:
008: import org.enhydra.shark.xpdl.XMLAttribute;
009: import org.enhydra.shark.xpdl.XMLCollectionElement;
010: import org.enhydra.shark.xpdl.XMLUtil;
011: import org.enhydra.shark.xpdl.XPDLConstants;
012:
013: /**
014: * Represents coresponding element from XPDL schema.
015: *
016: * @author Sasa Bojanic
017: */
018: public class WorkflowProcess extends XMLCollectionElement {
019:
020: protected transient ArrayList startingActivities;
021: protected transient ArrayList endingActivities;
022: protected transient Map allVariables;
023:
024: public WorkflowProcess(WorkflowProcesses parent) {
025: super (parent, true);
026: }
027:
028: protected void fillStructure() {
029: XMLAttribute attrName = new XMLAttribute(this , "Name", false);
030: XMLAttribute attrAccessLevel = new XMLAttribute(this ,
031: "AccessLevel", false, new String[] {
032: XPDLConstants.ACCESS_LEVEL_NONE,
033: XPDLConstants.ACCESS_LEVEL_PUBLIC,
034: XPDLConstants.ACCESS_LEVEL_PRIVATE }, 0);
035: ProcessHeader refProcessHeader = new ProcessHeader(this );
036: RedefinableHeader refRedefinableHeader = new RedefinableHeader(
037: this ); // min=0
038: FormalParameters refFormalParameters = new FormalParameters(
039: this );
040: DataFields refDataFields = new DataFields(this ); // min=0
041: Participants refParticipants = new Participants(this ); // min=0
042: Applications refApplications = new Applications(this ); // min=0
043: ActivitySets refActivitySets = new ActivitySets(this ); // min=0
044: Activities refActivities = new Activities(this ); // min=0
045: Transitions refTransitions = new Transitions(this ); // min=0
046: ExtendedAttributes refExtendedAttributes = new ExtendedAttributes(
047: this ); // min=0
048:
049: super .fillStructure();
050: add(attrName);
051: add(attrAccessLevel);
052: add(refProcessHeader);
053: add(refRedefinableHeader);
054: add(refFormalParameters);
055: add(refDataFields);
056: add(refParticipants);
057: add(refApplications);
058: add(refActivitySets);
059: add(refActivities);
060: add(refTransitions);
061: add(refExtendedAttributes);
062: }
063:
064: public void initCaches() {
065: super .initCaches();
066: getAllVariables();
067: Iterator it = getActivities().toElements().iterator();
068: while (it.hasNext()) {
069: Activity act = (Activity) it.next();
070: ArrayList trsI = act.getIncomingTransitions();
071: ArrayList trsNEO = act
072: .getNonExceptionalOutgoingTransitions();
073: // the activity is starting one if it has no input transitions ...
074: if (trsI.size() == 0) {
075: startingActivities.add(act);
076: // or there is a one input transition, but it is a selfreference
077: } else if (trsI.size() == 1) {
078: Transition t = (Transition) trsI.get(0);
079: if (t.getFrom().equals(t.getTo())) {
080: startingActivities.add(act);
081: }
082: }
083: if (trsNEO.size() == 0) {
084: endingActivities.add(act);
085: } else if (trsNEO.size() == 1) {
086: Transition t = (Transition) trsNEO.get(0);
087: if (t.getFrom().equals(t.getTo())) {
088: endingActivities.add(act);
089: }
090: }
091: }
092: }
093:
094: public void clearCaches() {
095: startingActivities = new ArrayList();
096: endingActivities = new ArrayList();
097: allVariables = new HashMap();
098: super .clearCaches();
099: }
100:
101: public ArrayList getStartingActivities() {
102: if (!isReadOnly) {
103: throw new RuntimeException(
104: "This method can be used only in read-only mode!");
105: }
106: return startingActivities;
107: }
108:
109: public ArrayList getEndingActivities() {
110: if (!isReadOnly) {
111: throw new RuntimeException(
112: "This method can be used only in read-only mode!");
113: }
114: return endingActivities;
115: }
116:
117: /**
118: * Returns a list of all WorkflowProcess and Package DataFields, as well as
119: * all WorkflowProcess FormalParameters.
120: */
121: public Map getAllVariables() {
122: if (allVariables == null || allVariables.size() == 0) {
123: allVariables = new HashMap();
124: Iterator it = getDataFields().toElements().iterator();
125: while (it.hasNext()) {
126: DataField df = (DataField) it.next();
127: allVariables.put(df.getId(), df);
128: }
129: it = XMLUtil.getPackage(this ).getDataFields().toElements()
130: .iterator();
131: while (it.hasNext()) {
132: DataField df = (DataField) it.next();
133: if (!allVariables.containsKey(df.getId())) {
134: allVariables.put(df.getId(), df);
135: }
136: }
137: it = getFormalParameters().toElements().iterator();
138: while (it.hasNext()) {
139: FormalParameter fp = (FormalParameter) it.next();
140: if (!allVariables.containsKey(fp.getId())) {
141: allVariables.put(fp.getId(), fp);
142: }
143: }
144: }
145: Map toRet = new HashMap(allVariables);
146: if (!isReadOnly) {
147: allVariables.clear();
148: }
149: return toRet;
150: }
151:
152: public Application getApplication(String Id) {
153: return getApplications().getApplication(Id);
154: }
155:
156: public Participant getParticipant(String Id) {
157: return getParticipants().getParticipant(Id);
158: }
159:
160: public DataField getDataField(String Id) {
161: return getDataFields().getDataField(Id);
162: }
163:
164: public FormalParameter getFormalParameter(String Id) {
165: return getFormalParameters().getFormalParameter(Id);
166: }
167:
168: public ActivitySet getActivitySet(String Id) {
169: return getActivitySets().getActivitySet(Id);
170: }
171:
172: public Activity getActivity(String Id) {
173: Activity act = getActivities().getActivity(Id);
174: if (act == null) {
175: Iterator it = getActivitySets().toElements().iterator();
176: while (it.hasNext()) {
177: ActivitySet as = (ActivitySet) it.next();
178: act = as.getActivity(Id);
179: if (act != null) {
180: break;
181: }
182: }
183: }
184: return act;
185: }
186:
187: public Transition getTransition(String Id) {
188: Transition tra = getTransitions().getTransition(Id);
189: if (tra == null) {
190: Iterator it = getActivitySets().toElements().iterator();
191: while (it.hasNext()) {
192: ActivitySet as = (ActivitySet) it.next();
193: tra = as.getTransition(Id);
194: if (tra != null) {
195: break;
196: }
197: }
198: }
199: return tra;
200: }
201:
202: public String getName() {
203: return get("Name").toValue();
204: }
205:
206: public void setName(String name) {
207: set("Name", name);
208: }
209:
210: public XMLAttribute getAccessLevelAttribute() {
211: return (XMLAttribute) get("AccessLevel");
212: }
213:
214: public String getAccessLevel() {
215: return getAccessLevelAttribute().toValue();
216: }
217:
218: public void setAccessLevelNONE() {
219: getAccessLevelAttribute().setValue(
220: XPDLConstants.ACCESS_LEVEL_NONE);
221: }
222:
223: public void setAccessLevelPUBLIC() {
224: getAccessLevelAttribute().setValue(
225: XPDLConstants.ACCESS_LEVEL_PUBLIC);
226: }
227:
228: public void setAccessLevelPRIVATE() {
229: getAccessLevelAttribute().setValue(
230: XPDLConstants.ACCESS_LEVEL_PRIVATE);
231: }
232:
233: public Applications getApplications() {
234: return (Applications) get("Applications");
235: }
236:
237: public DataFields getDataFields() {
238: return (DataFields) get("DataFields");
239: }
240:
241: public ExtendedAttributes getExtendedAttributes() {
242: return (ExtendedAttributes) get("ExtendedAttributes");
243: }
244:
245: public ProcessHeader getProcessHeader() {
246: return (ProcessHeader) get("ProcessHeader");
247: }
248:
249: public Participants getParticipants() {
250: return (Participants) get("Participants");
251: }
252:
253: public RedefinableHeader getRedefinableHeader() {
254: return (RedefinableHeader) get("RedefinableHeader");
255: }
256:
257: public Activities getActivities() {
258: return (Activities) get("Activities");
259: }
260:
261: public Transitions getTransitions() {
262: return (Transitions) get("Transitions");
263: }
264:
265: public ActivitySets getActivitySets() {
266: return (ActivitySets) get("ActivitySets");
267: }
268:
269: public FormalParameters getFormalParameters() {
270: return (FormalParameters) get("FormalParameters");
271: }
272:
273: }
|