1 package org.smartcomps.twister.engine.priv.core.definition.impl;
2
3 import org.smartcomps.twister.engine.exception.ProcessStructuralException;
4 import org.smartcomps.twister.engine.exception.EngineException;
5 import org.smartcomps.twister.engine.priv.core.definition.Activity;
6 import org.smartcomps.twister.engine.priv.core.definition.StructuredActivity;
7 import org.smartcomps.twister.engine.priv.core.definition.TwisterProcess;
8 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory;
9 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext;
10 import org.smartcomps.twister.engine.priv.core.dynamic.StructuredEC;
11 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance;
12 import org.smartcomps.twister.common.persistence.DBSessionException;
13
14 import java.util.Set;
15 import java.util.HashSet;
16 import java.util.Map;
17
18 /***
19 * Persistent implementation of the Activity interface.
20 * @see org.smartcomps.twister.engine.priv.core.definition.Activity
21 * @hibernate.class table="ACTIVITY" discriminator-value="ACT"
22 * @hibernate.discriminator column="DISCRIM"
23 */
24 public abstract class ActivityImpl implements Activity, Comparable {
25
26 private Long id;
27 private String name;
28 private String joinCondition;
29 private Set sourceLinks = new HashSet();
30 private Set targetLinks = new HashSet();
31 private StructuredActivityImpl activityContainer;
32 private Set processSet = new HashSet();
33
34 // This is a purely technical field to indicate the position of the activity within
35 // its container. It should be managed by Hibernate in the future but right now
36 // there's no other choice than this.
37 private int index;
38
39 /***
40 * @hibernate.id generator-class="native" type="long"
41 */
42 public Long getId() {
43 return id;
44 }
45
46 public void setId(Long id) {
47 this.id = id;
48 }
49
50 /***
51 * @hibernate.property length="50"
52 */
53 public String getName() {
54 return name;
55 }
56
57 public void setName(String name) {
58 this.name = name;
59 }
60
61 /***
62 * @hibernate.property length="300"
63 */
64 public String getJoinCondition() {
65 return joinCondition;
66 }
67
68 public void setJoinCondition(String joinCondition) {
69 this.joinCondition = joinCondition;
70 }
71
72 /***
73 * @hibernate.set inverse="true" role="sourceLinks"
74 * @hibernate.collection-key column="TGT_ACT_ID"
75 * @hibernate.collection-one-to-many class="org.smartcomps.twister.engine.priv.core.definition.impl.LinkImpl"
76 */
77 public Set getSourceLinks() {
78 return sourceLinks;
79 }
80
81 public void setSourceLinks(Set sourceLinks) {
82 this.sourceLinks = sourceLinks;
83 }
84
85 /***
86 * @hibernate.set inverse="true" role="targetLinks"
87 * @hibernate.collection-key column="SRC_ACT_ID"
88 * @hibernate.collection-one-to-many class="org.smartcomps.twister.engine.priv.core.definition.impl.LinkImpl"
89 */
90 public Set getTargetLinks() {
91 return targetLinks;
92 }
93
94 public void setTargetLinks(Set targetLinks) {
95 this.targetLinks = targetLinks;
96 }
97
98 public StructuredActivity getContainer() {
99 return activityContainer;
100 }
101
102 public void setContainer(StructuredActivity stucturedActivity) {
103 this.activityContainer = (StructuredActivityImpl) stucturedActivity;
104 }
105
106 public TwisterProcess getProcess() {
107 if (processSet == null || processSet.size() != 1) return null;
108 return (TwisterProcess) processSet.iterator().next();
109 }
110
111 public void setProcess(TwisterProcess process) {
112 HashSet processSet = new HashSet(1);
113 processSet.add(process);
114 this.processSet = processSet;
115 }
116
117 public TwisterProcess fetchProcess() {
118 if (getContainer() == null) {
119 return getProcess();
120 } else {
121 StructuredActivity container = this.getContainer();
122 while (container.getContainer() != null) container = container.getContainer();
123 return container.getProcess();
124 }
125 }
126
127 /***
128 * TECHNICAL, DO NOT USE
129 * @hibernate.many-to-one class="org.smartcomps.twister.engine.priv.core.definition.impl.ActivityImpl" column="SRC_ACT_ID"
130 */
131 public StructuredActivityImpl getActivityContainer() {
132 return activityContainer;
133 }
134
135 /***
136 * TECHNICAL, DO NOT USE
137 */
138 public void setActivityContainer(StructuredActivityImpl activityContainer) {
139 this.activityContainer = activityContainer;
140 }
141
142 /***
143 * TECHNICAL, DO NOT USE
144 * Only one activity in a processSet really has a processSet, therefore
145 * this method will often return null ; use the getContainer method
146 * instead, that always returns the right container (the real activity
147 * container or the processSet if it's a root activity).
148 * @hibernate.set inverse="true" role="processSet"
149 * @hibernate.collection-key column="ACTIVITY_ID"
150 * @hibernate.collection-one-to-many class="org.smartcomps.twister.engine.priv.core.definition.impl.ProcessImpl"
151 */
152 public Set getProcessSet() {
153 return processSet;
154 }
155
156 /***
157 * TECHNICAL, DO NOT USE
158 */
159 public void setProcessSet(Set processSet) {
160 this.processSet = processSet;
161 }
162
163 /***
164 * TECHNICAL, DO NOT USE
165 */
166 public int getIndex() {
167 return index;
168 }
169
170 /***
171 * TECHNICAL, DO NOT USE
172 */
173 public void setIndex(int index) {
174 this.index = index;
175 }
176
177 protected ExecutionContext createContextTree(String correlationSetName, Map correlation) throws EngineException {
178 ExecutionContext context = null;
179 if (getContainer() != null) {
180 StructuredEC parentContext = (StructuredEC)
181 ((StructuredActivityImpl)getContainer()).createContextTree(correlationSetName, correlation);
182 try {
183 context = ExecutionContextFactory.createExecutionContext(this, parentContext);
184 } catch (DBSessionException e) {
185 throw new EngineException(e);
186 }
187 } else if (getProcess() != null) {
188 ProcessInstance parentContext = ((ProcessImpl)getProcess()).execute(correlationSetName, correlation);
189 try {
190 context = ExecutionContextFactory.createExecutionContext(this, parentContext);
191 } catch (DBSessionException e) {
192 throw new EngineException(e);
193 }
194 } else {
195 throw new ProcessStructuralException("The activity " + getId() +
196 " has no process nor container, this shouldn't be possible");
197 }
198
199 return context;
200 }
201
202 public int compareTo(Object o) {
203 if (o instanceof ActivityImpl) {
204 if (((ActivityImpl)o).getIndex() > this.getIndex()) return -1;
205 else if (((ActivityImpl)o).getIndex() == this.getIndex()) return 0;
206 else return 1;
207 }
208 return 0;
209 }
210 }
This page was automatically generated by Maven