1 package org.smartcomps.twister.engine.priv.core.dynamic.impl;
2
3 import org.smartcomps.twister.engine.priv.core.dynamic.StructuredEC;
4 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext;
5 import org.smartcomps.twister.engine.priv.core.dynamic.BasicEC;
6 import org.smartcomps.twister.engine.priv.core.definition.Activity;
7 import org.smartcomps.twister.engine.priv.core.definition.StructuredActivity;
8 import org.smartcomps.twister.engine.exception.EngineRuntimeException;
9
10 import java.util.*;
11
12 /***
13 * Please put some JavaDoc here.
14 */
15 public abstract class StructuredECImpl extends ExecutionContextImpl implements StructuredEC {
16
17 private StructuredActivity activity;
18 private Set executionContextsSet = new HashSet();
19
20 public StructuredActivity getActivity() {
21 return activity;
22 }
23
24 public void setActivity(StructuredActivity activity) {
25 this.activity = activity;
26 }
27
28 /***
29 * Do not use this method, its doesn't maintain activity indexes properly, use
30 * the addActivity method instead.
31 * @param exectutionContextsSet
32 */
33 public void setExecutionContextsSet(Set exectutionContextsSet) {
34 this.executionContextsSet = exectutionContextsSet;
35 }
36
37 public Set getExecutionContextsSet() {
38 return executionContextsSet;
39 }
40
41 public List getExecutionContexts() {
42 // Making sure the set is ordered before using it to create the List.
43 SortedSet sortedSet = new TreeSet(executionContextsSet);
44 return new ArrayList(sortedSet);
45 }
46
47 public void addExecutionContext(ExecutionContext ec) {
48 ExecutionContextImpl impl = (ExecutionContextImpl) ec;
49 impl.setIndex(nextECIndex());
50 getExecutionContextsSet().add(ec);
51 impl.setContainer(this);
52 }
53
54 /***
55 * Returns the origin activity of the passed child execution context.
56 * @param ec the execution context to get origin activity for
57 * @return
58 */
59 public abstract Activity getActivityForChildContext(ExecutionContext ec);
60
61 /***
62 * Returns the execution context created in this structured execution from
63 * the provided activity. If several execution contexts exist (like for a
64 * WhileEC for example), only the last created is returned.
65 * @param childActivity
66 * @return Collection of execution contexts corresponding to the provided activity
67 */
68 public abstract ExecutionContext getExecution(Activity childActivity);
69
70 /***
71 * Notifies the container that an activity within it is starting execution.
72 */
73 public abstract void notifyExecution(ExecutionContext ec);
74
75 /***
76 * Notifies the container that an activity within it has ended its termination.
77 */
78 public abstract void notifyTermination(ExecutionContext ec);
79
80 private int nextECIndex() {
81 int index = 0;
82 for (Iterator ecIterator = getExecutionContextsSet().iterator(); ecIterator.hasNext();) {
83 ExecutionContextImpl ecImpl = (ExecutionContextImpl) ecIterator.next();
84 if (ecImpl.getIndex() > index)
85 index = ecImpl.getIndex();
86 }
87 return index + 1;
88 }
89
90 }
This page was automatically generated by Maven