001: package org.enhydra.shark.xpdl.elements;
002:
003: import java.util.ArrayList;
004: import java.util.Iterator;
005:
006: import org.enhydra.shark.xpdl.XMLAttribute;
007: import org.enhydra.shark.xpdl.XMLCollectionElement;
008: import org.enhydra.shark.xpdl.XMLElement;
009: import org.enhydra.shark.xpdl.XMLUtil;
010: import org.enhydra.shark.xpdl.XPDLConstants;
011:
012: /**
013: * Represents coresponding element from XPDL schema.
014: *
015: * @author Sasa Bojanic
016: */
017: public class Activity extends XMLCollectionElement {
018:
019: protected transient ArrayList outgoingTransitions;
020: protected transient ArrayList incomingTransitions;
021: protected transient ArrayList exceptionalOutgoingTransitions;
022: protected transient ArrayList nonExceptionalOutgoingTransitions;
023: protected transient ArrayList exceptionalIncomingTransitions;
024: protected transient ArrayList nonExceptionalIncomingTransitions;
025:
026: public Activity(Activities acts) {
027: super (acts, true);
028: }
029:
030: protected void fillStructure() {
031: XMLAttribute attrName = new XMLAttribute(this , "Name", false);
032: Description refDescription = new Description(this ); // min=0
033: Limit refLimit = new Limit(this ); // min=0
034: // can be Route, BlockActivity or Implementation
035: ActivityTypes refType = new ActivityTypes(this );
036: Performer refPerformer = new Performer(this );// min=0
037: StartMode refStartMode = new StartMode(this ); // min=0
038: FinishMode refFinishMode = new FinishMode(this ); // min=0
039: Priority refPriority = new Priority(this ); // min=0
040: // we use Deadlines instead of Deadline
041: Deadlines refDeadlines = new Deadlines(this ); // min=0
042: SimulationInformation refSimulationInformation = new SimulationInformation(
043: this ); // min=0
044: Icon refIcon = new Icon(this ); // min=0
045: Documentation refDocumentation = new Documentation(this ); // min=0
046: TransitionRestrictions refTransitionRestrictions = new TransitionRestrictions(
047: this ); // min=0
048: ExtendedAttributes refExtendedAttributes = new ExtendedAttributes(
049: this ); // min=0
050:
051: super .fillStructure();
052: add(attrName);
053: add(refDescription);
054: add(refLimit);
055: add(refType);
056: add(refPerformer);
057: add(refStartMode);
058: add(refFinishMode);
059: add(refPriority);
060: add(refDeadlines);
061: add(refSimulationInformation);
062: add(refIcon);
063: add(refDocumentation);
064: add(refTransitionRestrictions);
065: add(refExtendedAttributes);
066: }
067:
068: public void initCaches() {
069: super .initCaches();
070: Transitions ts;
071: if (getParent().getParent() instanceof WorkflowProcess) {
072: ts = ((WorkflowProcess) getParent().getParent())
073: .getTransitions();
074: } else {
075: ts = ((ActivitySet) getParent().getParent())
076: .getTransitions();
077: }
078: TransitionRestrictions trs = getTransitionRestrictions();
079: ArrayList trefs = null;
080: if (trs.size() > 0) {
081: trefs = ((TransitionRestriction) trs.get(0)).getSplit()
082: .getTransitionRefs().toElements();
083: } else {
084: trefs = new ArrayList();
085: }
086:
087: Iterator it = trefs.iterator();
088: while (it.hasNext()) {
089: TransitionRef tref = (TransitionRef) it.next();
090: Transition t = ts.getTransition(tref.getId());
091: outgoingTransitions.add(t);
092: putTransitionInTheRightList(t, true);
093: }
094: it = ts.toElements().iterator();
095: while (it.hasNext()) {
096: Transition t = (Transition) it.next();
097: if (!outgoingTransitions.contains(t)
098: && t.getFrom().equals(getId())) {
099: outgoingTransitions.add(t);
100: putTransitionInTheRightList(t, true);
101: }
102: if (t.getTo().equals(getId())) {
103: incomingTransitions.add(t);
104: putTransitionInTheRightList(t, false);
105: }
106: }
107: }
108:
109: public void clearCaches() {
110: clearInternalCaches();
111: super .clearCaches();
112: }
113:
114: protected void clearInternalCaches() {
115: outgoingTransitions = new ArrayList();
116: incomingTransitions = new ArrayList();
117: exceptionalOutgoingTransitions = new ArrayList();
118: nonExceptionalOutgoingTransitions = new ArrayList();
119: exceptionalIncomingTransitions = new ArrayList();
120: nonExceptionalIncomingTransitions = new ArrayList();
121: }
122:
123: protected void putTransitionInTheRightList(Transition t,
124: boolean outg) {
125: Condition condition = t.getCondition();
126: String condType = condition.getType();
127: if (condType.equals(XPDLConstants.CONDITION_TYPE_EXCEPTION)
128: || condType
129: .equals(XPDLConstants.CONDITION_TYPE_DEFAULTEXCEPTION)) {
130: if (outg) {
131: exceptionalOutgoingTransitions.add(t);
132: } else {
133: exceptionalIncomingTransitions.add(t);
134: }
135: } else {
136: if (outg) {
137: nonExceptionalOutgoingTransitions.add(t);
138: } else {
139: nonExceptionalIncomingTransitions.add(t);
140: }
141: }
142: }
143:
144: public ArrayList getOutgoingTransitions() {
145: if (!isReadOnly) {
146: throw new RuntimeException(
147: "This method can be used only in read-only mode!");
148: }
149: return outgoingTransitions;
150: }
151:
152: public ArrayList getIncomingTransitions() {
153: if (!isReadOnly) {
154: throw new RuntimeException(
155: "This method can be used only in read-only mode!");
156: }
157: return incomingTransitions;
158: }
159:
160: public ArrayList getNonExceptionalOutgoingTransitions() {
161: if (!isReadOnly) {
162: throw new RuntimeException(
163: "This method can be used only in read-only mode!");
164: }
165: return nonExceptionalOutgoingTransitions;
166: }
167:
168: public ArrayList getExceptionalOutgoingTransitions() {
169: if (!isReadOnly) {
170: throw new RuntimeException(
171: "This method can be used only in read-only mode!");
172: }
173: return exceptionalOutgoingTransitions;
174: }
175:
176: public ArrayList getNonExceptionalIncomingTransitions() {
177: if (!isReadOnly) {
178: throw new RuntimeException(
179: "This method can be used only in read-only mode!");
180: }
181: return nonExceptionalIncomingTransitions;
182: }
183:
184: public ArrayList getExceptionalIncomingTransitions() {
185: if (!isReadOnly) {
186: throw new RuntimeException(
187: "This method can be used only in read-only mode!");
188: }
189: return exceptionalIncomingTransitions;
190: }
191:
192: public boolean isAndTypeSplit() {
193: return XMLUtil.isANDTypeSplitOrJoin(this , 0);
194: }
195:
196: public boolean isAndTypeJoin() {
197: return XMLUtil.isANDTypeSplitOrJoin(this , 1);
198: }
199:
200: public int getActivityStartMode() {
201: return XMLUtil.getStartMode(this );
202: }
203:
204: public int getActivityFinishMode() {
205: return XMLUtil.getFinishMode(this );
206: }
207:
208: public int getActivityType() {
209: XMLElement ch = getActivityTypes().getChoosen();
210: if (ch instanceof Route) {
211: return XPDLConstants.ACTIVITY_TYPE_ROUTE;
212: } else if (ch instanceof Implementation) {
213: ch = ((Implementation) ch).getImplementationTypes()
214: .getChoosen();
215: if (ch instanceof Tools) {
216: return XPDLConstants.ACTIVITY_TYPE_TOOL;
217: } else if (ch instanceof SubFlow) {
218: return XPDLConstants.ACTIVITY_TYPE_SUBFLOW;
219: } else {
220: return XPDLConstants.ACTIVITY_TYPE_NO;
221: }
222: } else {
223: return XPDLConstants.ACTIVITY_TYPE_BLOCK;
224: }
225:
226: }
227:
228: public boolean isSubflowSynchronous() {
229: if (getActivityType() != XPDLConstants.ACTIVITY_TYPE_SUBFLOW) {
230: throw new RuntimeException(
231: "The activity type is not SubFlow!");
232: }
233: return XMLUtil.isSubflowSynchronous(this );
234: }
235:
236: public String getName() {
237: return get("Name").toValue();
238: }
239:
240: public void setName(String name) {
241: set("Name", name);
242: }
243:
244: public Deadlines getDeadlines() {
245: return (Deadlines) get("Deadlines");
246: }
247:
248: public String getDescription() {
249: return get("Description").toValue();
250: }
251:
252: public void setDescription(String description) {
253: set("Description", description);
254: }
255:
256: public String getDocumentation() {
257: return get("Documentation").toValue();
258: }
259:
260: public void setDocumentation(String documentation) {
261: set("Documentation", documentation);
262: }
263:
264: public ExtendedAttributes getExtendedAttributes() {
265: return (ExtendedAttributes) get("ExtendedAttributes");
266: }
267:
268: public FinishMode getFinishMode() {
269: return (FinishMode) get("FinishMode");
270: }
271:
272: public String getIcon() {
273: return get("Icon").toValue();
274: }
275:
276: public void setIcon(String icon) {
277: set("Icon", icon);
278: }
279:
280: public String getLimit() {
281: return get("Limit").toValue();
282: }
283:
284: public void setLimit(String limit) {
285: set("Limit", limit);
286: }
287:
288: public String getPerformer() {
289: return get("Performer").toValue();
290: }
291:
292: public void setPerformer(String performer) {
293: set("Performer", performer);
294: }
295:
296: public String getPriority() {
297: return get("Priority").toValue();
298: }
299:
300: public void setPriority(String priority) {
301: set("Priority", priority);
302: }
303:
304: public SimulationInformation getSimulationInformation() {
305: return (SimulationInformation) get("SimulationInformation");
306: }
307:
308: public StartMode getStartMode() {
309: return (StartMode) get("StartMode");
310: }
311:
312: public TransitionRestrictions getTransitionRestrictions() {
313: return (TransitionRestrictions) get("TransitionRestrictions");
314: }
315:
316: public ActivityTypes getActivityTypes() {
317: return (ActivityTypes) get("Type");
318: }
319:
320: }
|