1 package org
.argeo
.slc
.execution
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
9 import org
.apache
.commons
.lang
.math
.RandomUtils
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.process
.Executable
;
12 import org
.argeo
.slc
.test
.ExecutableTestRun
;
13 import org
.springframework
.beans
.factory
.BeanNameAware
;
14 import org
.springframework
.beans
.factory
.InitializingBean
;
15 import org
.springframework
.validation
.MapBindingResult
;
17 public class SimpleExecutionFlow
implements ExecutionFlow
, InitializingBean
,
19 private ExecutionSpec executionSpec
= new SimpleExecutionSpec();
20 private String name
= null;
21 private Map
<String
, Object
> parameters
= new HashMap
<String
, Object
>();
22 private List
<Executable
> executables
= new ArrayList
<Executable
>();
24 public SimpleExecutionFlow() {
28 public SimpleExecutionFlow(Map
<String
, Object
> parameters
) {
29 this.parameters
.putAll(parameters
);
32 public void execute() {
33 for (Executable executable
: executables
) {
38 public void afterPropertiesSet() throws Exception
{
39 // Validate execution specs
40 if (executionSpec
== null)
43 MapBindingResult errors
= new MapBindingResult(parameters
, "execution#"
45 for (String key
: executionSpec
.getAttributes().keySet()) {
46 ExecutionSpecAttribute executionSpecAttr
= executionSpec
47 .getAttributes().get(key
);
48 if (!parameters
.containsKey(key
)) {
49 Object defaultValue
= executionSpecAttr
.getValue();
50 if (defaultValue
== null)
51 errors
.rejectValue(key
, "Not set and no default value");
53 parameters
.put(key
, defaultValue
);
54 } else {// contains key
55 Object obj
= parameters
.get(key
);
56 if (executionSpecAttr
instanceof RefSpecAttribute
) {
57 RefSpecAttribute rsa
= (RefSpecAttribute
) executionSpecAttr
;
58 // TODO: make sure this will not cause pb with OSGi
59 Class targetClass
= rsa
.getTargetClass();
60 if (!targetClass
.isAssignableFrom(obj
.getClass())) {
62 + " not compatible with target class "
69 if (errors
.hasErrors())
70 throw new SlcException("Could not prepare execution flow: "
74 public void setBeanName(String name
) {
78 public void setExecutables(List
<Executable
> executables
) {
79 this.executables
= executables
;
82 public void setExecutionSpec(ExecutionSpec executionSpec
) {
83 this.executionSpec
= executionSpec
;
86 public void setParameters(Map
<String
, Object
> attributes
) {
87 this.parameters
= attributes
;
90 public String
getName() {
94 public ExecutionSpec
getExecutionSpec() {
98 public Object
getParameter(String name
) {
99 if (parameters
.containsKey(name
)) {
100 return parameters
.get(name
);
102 if (executionSpec
.getAttributes().containsKey(name
)) {
103 ExecutionSpecAttribute esa
= executionSpec
.getAttributes().get(
105 if (esa
.getValue() != null)
106 return esa
.getValue();
108 throw new SlcException("Key " + name
109 + " is not defined in the specifications of "
113 throw new SlcException("Key " + name
+ " is not set as parameter in "
117 public String
toString() {
118 return new StringBuffer("Flow ").append(name
).toString();
121 public boolean equals(Object obj
) {
122 return ((ExecutionFlow
) obj
).getName().equals(name
);