KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > xpdl > elements > WorkflowProcess


1 package org.enhydra.shark.xpdl.elements;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
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 /**
14  * Represents coresponding element from XPDL schema.
15  *
16  * @author Sasa Bojanic
17  */

18 public class WorkflowProcess extends XMLCollectionElement {
19
20    protected transient ArrayList JavaDoc startingActivities;
21    protected transient ArrayList JavaDoc 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 JavaDoc[] {
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); // min=0
39
FormalParameters refFormalParameters=new FormalParameters(this);
40       DataFields refDataFields=new DataFields(this); // min=0
41
Participants refParticipants=new Participants(this); // min=0
42
Applications refApplications=new Applications(this); // min=0
43
ActivitySets refActivitySets=new ActivitySets(this); // min=0
44
Activities refActivities=new Activities(this); // min=0
45
Transitions refTransitions=new Transitions(this); // min=0
46
ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
47

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 JavaDoc it=getActivities().toElements().iterator();
66       while (it.hasNext()) {
67          Activity act=(Activity)it.next();
68          ArrayList JavaDoc trsI=act.getIncomingTransitions();
69          ArrayList JavaDoc trsNEO=act.getNonExceptionalOutgoingTransitions();
70          // the activity is starting one if it has no input transitions ...
71
if (trsI.size()==0) {
72             startingActivities.add(act);
73             // or there is a one input transition, but it is a selfreference
74
} 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 JavaDoc();
93       endingActivities=new ArrayList JavaDoc();
94       super.clearCaches();
95    }
96
97    public ArrayList JavaDoc getStartingActivities () {
98       if (!isReadOnly) {
99          throw new RuntimeException JavaDoc("This method can be used only in read-only mode!");
100       }
101       return startingActivities;
102    }
103
104    public ArrayList JavaDoc getEndingActivities () {
105       if (!isReadOnly) {
106          throw new RuntimeException JavaDoc("This method can be used only in read-only mode!");
107       }
108       return endingActivities;
109    }
110
111    /**
112     * Returns a list of all WorkflowProcess and Package DataFields, as well as
113     * all WorkflowProcess FormalParameters.
114     */

115    public Map JavaDoc getAllVariables () {
116       Map JavaDoc m=new HashMap JavaDoc();
117       Iterator JavaDoc 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 JavaDoc Id) {
140       return getApplications().getApplication(Id);
141    }
142
143    public Participant getParticipant(String JavaDoc Id) {
144       return getParticipants().getParticipant(Id);
145    }
146
147    public DataField getDataField (String JavaDoc Id) {
148       return getDataFields().getDataField(Id);
149    }
150
151    public FormalParameter getFormalParameter (String JavaDoc Id) {
152       return getFormalParameters().getFormalParameter(Id);
153    }
154
155    public ActivitySet getActivitySet (String JavaDoc Id) {
156       return getActivitySets().getActivitySet(Id);
157    }
158
159    public Activity getActivity (String JavaDoc Id) {
160       return getActivities().getActivity(Id);
161    }
162
163    public Transition getTransition (String JavaDoc Id) {
164       return getTransitions().getTransition(Id);
165    }
166
167    public String JavaDoc getName() {
168       return get("Name").toValue();
169    }
170    public void setName(String JavaDoc name) {
171       set("Name",name);
172    }
173    public XMLAttribute getAccessLevelAttribute() {
174       return (XMLAttribute)get("AccessLevel");
175    }
176    public String JavaDoc 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