1 package org.smartcomps.twister.engine.priv.core.definition.impl;
2
3 import org.smartcomps.twister.engine.priv.core.definition.Activity;
4 import org.smartcomps.twister.engine.priv.core.definition.TwisterProcess;
5 import org.smartcomps.twister.engine.priv.core.definition.CorrelationSet;
6 import org.smartcomps.twister.engine.priv.core.definition.Property;
7 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance;
8 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory;
9 import org.smartcomps.twister.engine.exception.EngineException;
10 import org.smartcomps.twister.common.persistence.DBSessionException;
11 import org.smartcomps.twister.common.persistence.XMLSessionException;
12
13 import java.util.Collection;
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.Map;
17
18 /***
19 * Persistent implementation of the TwisterProcess interface.
20 * @see org.smartcomps.twister.engine.priv.core.definition.TwisterProcess
21 */
22 public class ProcessImpl implements TwisterProcess {
23
24 private Long id;
25 private String name;
26
27 private ActivityImpl activity;
28 private Collection instances = new HashSet();
29 private Collection correlationSets = new HashSet();
30 private Collection properties = new HashSet();
31
32 private ProcessInstanceFactory piFactory = new ProcessInstanceFactory();
33
34 public Long getId() {
35 return id;
36 }
37
38 public void setId(Long id) {
39 this.id = id;
40 }
41
42 public String getName() {
43 return name;
44 }
45
46 public void setName(String name) {
47 this.name = name;
48 }
49
50 public Activity getActivity() {
51 return activity;
52 }
53
54 public void setActivity(Activity activity) {
55 this.activity = (ActivityImpl)activity;
56 }
57
58 public Collection getInstances() {
59 return this.instances;
60 }
61
62 public void setInstances(Collection instances) {
63 this.instances = instances;
64 }
65
66 public void addInstance(ProcessInstance context) {
67 this.instances.add(context);
68 }
69
70 public Collection getCorrelationSets() {
71 return correlationSets;
72 }
73
74 public CorrelationSet getCorrelationSet(String setName) {
75 CorrelationSet result = null;
76 for (Iterator corIter = correlationSets.iterator(); corIter.hasNext();) {
77 CorrelationSet correlationSet = (CorrelationSet) corIter.next();
78 if (correlationSet.getName().equals(setName)) {
79 result = correlationSet;
80 }
81 }
82 return result;
83 }
84
85 public void setCorrelationSets(Collection correlationSets) {
86 this.correlationSets = correlationSets;
87 }
88
89 public void addCorrelationSet(CorrelationSet set) {
90 this.correlationSets.add(set);
91 }
92
93 public Collection getProperties() {
94 return properties;
95 }
96
97 public Property getProperty(String propName) {
98 Property result = null;
99 for (Iterator propIter = properties.iterator(); propIter.hasNext();) {
100 Property property = (Property) propIter.next();
101 if (property.getName().equals(propName)) {
102 result = property;
103 }
104 }
105 return result;
106 }
107
108 public void setProperties(Collection properties) {
109 this.properties = properties;
110 }
111
112 public void addProperty(Property prop) {
113 this.properties.add(prop);
114 }
115
116 public ProcessInstance execute(String correlationSetName, Map correlation) throws EngineException {
117 ProcessInstance instance = null;
118 try {
119 instance = getProcessInstanceFactory().createProcessInstance(this, correlationSetName, correlation);
120 } catch (DBSessionException e) {
121 throw new EngineException(e);
122 } catch (XMLSessionException e) {
123 e.printStackTrace();
124 }
125
126 return instance;
127 }
128
129 protected ProcessInstanceFactory getProcessInstanceFactory() {
130 if (this.piFactory == null) {
131 piFactory = new ProcessInstanceFactory();
132 }
133 return piFactory;
134 }
135
136 }
This page was automatically generated by Maven