1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.HashMap
;
5 import java
.util
.TreeMap
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.execution
.ExecutionContext
;
9 import org
.argeo
.slc
.execution
.ExecutionFlow
;
10 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
11 import org
.argeo
.slc
.execution
.ExecutionModule
;
12 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
13 import org
.argeo
.slc
.execution
.ExecutionSpec
;
14 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
15 import org
.argeo
.slc
.process
.SlcExecution
;
16 import org
.springframework
.aop
.scope
.ScopedObject
;
17 import org
.springframework
.beans
.BeansException
;
18 import org
.springframework
.beans
.factory
.generic
.GenericBeanFactoryAccessor
;
19 import org
.springframework
.context
.ApplicationContext
;
20 import org
.springframework
.context
.ApplicationContextAware
;
21 import org
.springframework
.util
.Assert
;
23 public abstract class AbstractSpringExecutionModule
implements ExecutionModule
,
24 ApplicationContextAware
{
26 private ApplicationContext applicationContext
;
28 private ExecutionContext executionContext
;
30 public ExecutionContext
getExecutionContext() {
31 return executionContext
;
34 public void setExecutionContext(ExecutionContext executionContext
) {
35 this.executionContext
= executionContext
;
38 public ExecutionModuleDescriptor
getDescriptor() {
39 ExecutionModuleDescriptor md
= new ExecutionModuleDescriptor();
40 md
.setName(getName());
41 md
.setVersion(getVersion());
43 GenericBeanFactoryAccessor accessor
= new GenericBeanFactoryAccessor(
45 Map
<String
, ExecutionFlow
> executionFlows
= accessor
46 .getBeansOfType(ExecutionFlow
.class);
48 for (String name
: executionFlows
.keySet()) {
49 ExecutionFlow executionFlow
= executionFlows
.get(name
);
51 Assert
.notNull(executionFlow
.getName());
52 Assert
.state(name
.equals(executionFlow
.getName()));
54 ExecutionSpec executionSpec
= executionFlow
.getExecutionSpec();
55 Assert
.notNull(executionSpec
);
56 Assert
.notNull(executionSpec
.getName());
58 Map
<String
, Object
> values
= new TreeMap
<String
, Object
>();
59 for (String key
: executionSpec
.getAttributes().keySet()) {
60 ExecutionSpecAttribute attribute
= executionSpec
61 .getAttributes().get(key
);
63 if (executionFlow
.isSetAsParameter(key
)) {
64 Object value
= executionFlow
.getParameter(key
);
65 if (attribute
instanceof PrimitiveSpecAttribute
) {
66 PrimitiveValue primitiveValue
= new PrimitiveValue();
68 .setType(((PrimitiveSpecAttribute
) attribute
)
70 primitiveValue
.setValue(value
);
71 values
.put(key
, primitiveValue
);
72 } else if (attribute
instanceof RefSpecAttribute
) {
73 RefValue refValue
= new RefValue();
74 if (value
instanceof ScopedObject
) {
75 refValue
.setLabel("RUNTIME "
76 + value
.getClass().getName());
78 refValue
.setLabel("STATIC "
79 + value
.getClass().getName());
81 values
.put(key
, refValue
);
83 throw new SlcException("Unkown spec attribute type "
84 + attribute
.getClass());
90 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(name
,
91 values
, executionSpec
);
93 // Add execution spec if necessary
94 if (!md
.getExecutionSpecs().contains(executionSpec
))
95 md
.getExecutionSpecs().add(executionSpec
);
98 md
.getExecutionFlows().add(efd
);
104 public void execute(SlcExecution slcExecution
) {
105 applicationContext
.publishEvent(new NewExecutionEvent(this,
109 public void execute(ExecutionFlowDescriptor descriptor
) {
110 ExecutionFlow flow
= (ExecutionFlow
) applicationContext
.getBean(descriptor
.getName(),
111 ExecutionFlow
.class);
116 public void setApplicationContext(ApplicationContext applicationContext
)
117 throws BeansException
{
118 this.applicationContext
= applicationContext
;