01: package org.enhydra.shark.xpdl.elements;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05:
06: import org.enhydra.shark.xpdl.XMLCollectionElement;
07:
08: /**
09: * Represents coresponding element from XPDL schema.
10: *
11: * @author Sasa Bojanic
12: */
13: public class ActivitySet extends XMLCollectionElement {
14:
15: protected transient ArrayList startingActivities;
16: protected transient ArrayList endingActivities;
17:
18: public ActivitySet(ActivitySets parent) {
19: super (parent, true);
20: }
21:
22: protected void fillStructure() {
23: Activities refActivities = new Activities(this );
24: Transitions refTransitions = new Transitions(this );
25:
26: super .fillStructure();
27: add(refActivities);
28: add(refTransitions);
29:
30: }
31:
32: public void initCaches() {
33: super .initCaches();
34: Iterator it = getActivities().toElements().iterator();
35: while (it.hasNext()) {
36: Activity act = (Activity) it.next();
37: ArrayList trsI = act.getIncomingTransitions();
38: ArrayList trsNEO = act
39: .getNonExceptionalOutgoingTransitions();
40: // the activity is starting one if it has no input transitions ...
41: if (trsI.size() == 0) {
42: startingActivities.add(act);
43: // or there is a one input transition, but it is a selfreference
44: } else if (trsI.size() == 1) {
45: Transition t = (Transition) trsI.get(0);
46: if (t.getFrom().equals(t.getTo())) {
47: startingActivities.add(act);
48: }
49: }
50: if (trsNEO.size() == 0) {
51: endingActivities.add(act);
52: } else if (trsNEO.size() == 1) {
53: Transition t = (Transition) trsNEO.get(0);
54: if (t.getFrom().equals(t.getTo())) {
55: endingActivities.add(act);
56: }
57: }
58: }
59: }
60:
61: public void clearCaches() {
62: startingActivities = new ArrayList();
63: endingActivities = new ArrayList();
64: super .clearCaches();
65: }
66:
67: public ArrayList getStartingActivities() {
68: if (!isReadOnly) {
69: throw new RuntimeException(
70: "This method can be used only in read-only mode!");
71: }
72: return startingActivities;
73: }
74:
75: public ArrayList getEndingActivities() {
76: if (!isReadOnly) {
77: throw new RuntimeException(
78: "This method can be used only in read-only mode!");
79: }
80: return endingActivities;
81: }
82:
83: public Activity getActivity(String Id) {
84: return getActivities().getActivity(Id);
85: }
86:
87: public Transition getTransition(String Id) {
88: return getTransitions().getTransition(Id);
89: }
90:
91: public Activities getActivities() {
92: return (Activities) get("Activities");
93: }
94:
95: public Transitions getTransitions() {
96: return (Transitions) get("Transitions");
97: }
98: }
|