KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 public class Activity extends XMLCollectionElement {
18
19    protected transient ArrayList JavaDoc outgoingTransitions;
20    protected transient ArrayList JavaDoc incomingTransitions;
21    protected transient ArrayList JavaDoc exceptionalOutgoingTransitions;
22    protected transient ArrayList JavaDoc 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); // min=0
31
Limit refLimit=new Limit(this); // min=0
32
// can be Route, BlockActivity or Implementation
33
ActivityTypes refType=new ActivityTypes(this);
34       Performer refPerformer=new Performer(this);// min=0
35
StartMode refStartMode=new StartMode(this); // min=0
36
FinishMode refFinishMode=new FinishMode(this); // min=0
37
Priority refPriority=new Priority(this); // min=0
38
// we use Deadlines instead of Deadline
39
Deadlines refDeadlines=new Deadlines(this); // min=0
40
SimulationInformation refSimulationInformation=new SimulationInformation(this); // min=0
41
Icon refIcon=new Icon(this); // min=0
42
Documentation refDocumentation=new Documentation(this); // min=0
43
TransitionRestrictions refTransitionRestrictions=new TransitionRestrictions(this); // min=0
44
ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
45

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 JavaDoc trefs=null;
73       if (trs.size()>0) {
74          trefs=((TransitionRestriction)trs.get(0)).getSplit().getTransitionRefs().toElements();
75       } else {
76          trefs=new ArrayList JavaDoc();
77       }
78       
79       Iterator JavaDoc 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 JavaDoc();
106       incomingTransitions=new ArrayList JavaDoc();
107       exceptionalOutgoingTransitions=new ArrayList JavaDoc();
108       nonExceptionalOutgoingTransitions=new ArrayList JavaDoc();
109    }
110
111    protected void putTransitionInTheRightList (Transition t) {
112       Condition condition = t.getCondition();
113       String JavaDoc 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 JavaDoc getOutgoingTransitions () {
123       if (!isReadOnly) {
124          throw new RuntimeException JavaDoc("This method can be used only in read-only mode!");
125       }
126       return outgoingTransitions;
127    }
128    
129    public ArrayList JavaDoc getIncomingTransitions () {
130       if (!isReadOnly) {
131          throw new RuntimeException JavaDoc("This method can be used only in read-only mode!");
132       }
133       return incomingTransitions;
134    }
135
136    public ArrayList JavaDoc getNonExceptionalOutgoingTransitions () {
137       if (!isReadOnly) {
138          throw new RuntimeException JavaDoc("This method can be used only in read-only mode!");
139       }
140       return nonExceptionalOutgoingTransitions;
141    }
142
143    public ArrayList JavaDoc getExceptionalOutgoingTransitions () {
144       if (!isReadOnly) {
145          throw new RuntimeException JavaDoc("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 JavaDoc("The activity type is not SubFlow!");
188       }
189       return XMLUtil.isSubflowSynchronous(this);
190    }
191    
192    public String JavaDoc getName() {
193       return get("Name").toValue();
194    }
195    public void setName(String JavaDoc name) {
196       set("Name",name);
197    }
198    public Deadlines getDeadlines() {
199       return (Deadlines)get("Deadlines");
200    }
201    public String JavaDoc getDescription() {
202       return get("Description").toValue();
203    }
204    public void setDescription(String JavaDoc description) {
205       set("Description",description);
206    }
207    public String JavaDoc getDocumentation() {
208       return get("Documentation").toValue();
209    }
210    public void setDocumentation(String JavaDoc 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 JavaDoc getIcon() {
220       return get("Icon").toValue();
221    }
222    public void setIcon(String JavaDoc icon) {
223       set("Icon",icon);
224    }
225    public String JavaDoc getLimit() {
226       return get("Limit").toValue();
227    }
228    public void setLimit(String JavaDoc limit) {
229       set("Limit",limit);
230    }
231    public String JavaDoc getPerformer() {
232       return get("Performer").toValue();
233    }
234    public void setPerformer(String JavaDoc performer) {
235       set("Performer",performer);
236    }
237    public String JavaDoc getPriority() {
238       return get("Priority").toValue();
239    }
240    public void setPriority(String JavaDoc 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