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
.ExecutionFlow
;
9 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
10 import org
.argeo
.slc
.execution
.ExecutionModule
;
11 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
12 import org
.argeo
.slc
.execution
.ExecutionSpec
;
13 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
14 import org
.argeo
.slc
.process
.SlcExecution
;
15 import org
.springframework
.aop
.scope
.ScopedObject
;
16 import org
.springframework
.beans
.BeansException
;
17 import org
.springframework
.beans
.factory
.generic
.GenericBeanFactoryAccessor
;
18 import org
.springframework
.context
.ApplicationContext
;
19 import org
.springframework
.context
.ApplicationContextAware
;
20 import org
.springframework
.util
.Assert
;
22 public abstract class AbstractSpringExecutionModule
implements ExecutionModule
,
23 ApplicationContextAware
{
24 private ApplicationContext applicationContext
;
26 public ExecutionModuleDescriptor
getDescriptor() {
27 ExecutionModuleDescriptor md
= new ExecutionModuleDescriptor();
28 md
.setName(getName());
29 md
.setVersion(getVersion());
31 GenericBeanFactoryAccessor accessor
= new GenericBeanFactoryAccessor(
33 Map
<String
, ExecutionFlow
> executionFlows
= accessor
34 .getBeansOfType(ExecutionFlow
.class);
36 for (String name
: executionFlows
.keySet()) {
37 ExecutionFlow executionFlow
= executionFlows
.get(name
);
39 Assert
.notNull(executionFlow
.getName());
40 Assert
.state(name
.equals(executionFlow
.getName()));
42 ExecutionSpec executionSpec
= executionFlow
.getExecutionSpec();
43 Assert
.notNull(executionSpec
);
44 Assert
.notNull(executionSpec
.getName());
46 Map
<String
, Object
> values
= new TreeMap
<String
, Object
>();
47 for (String key
: executionSpec
.getAttributes().keySet()) {
48 ExecutionSpecAttribute attribute
= executionSpec
49 .getAttributes().get(key
);
51 if (executionFlow
.isSetAsParameter(key
)) {
52 Object value
= executionFlow
.getParameter(key
);
53 if (attribute
instanceof PrimitiveSpecAttribute
) {
54 PrimitiveValue primitiveValue
= new PrimitiveValue();
56 .setType(((PrimitiveSpecAttribute
) attribute
)
58 primitiveValue
.setValue(value
);
59 values
.put(key
, primitiveValue
);
60 } else if (attribute
instanceof RefSpecAttribute
) {
61 RefValue refValue
= new RefValue();
62 if (value
instanceof ScopedObject
) {
63 refValue
.setLabel("RUNTIME "
64 + value
.getClass().getName());
66 refValue
.setLabel("STATIC "
67 + value
.getClass().getName());
69 values
.put(key
, refValue
);
71 throw new SlcException("Unkown spec attribute type "
72 + attribute
.getClass());
78 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(name
,
79 values
, executionSpec
);
81 // Add execution spec if necessary
82 if (!md
.getExecutionSpecs().contains(executionSpec
))
83 md
.getExecutionSpecs().add(executionSpec
);
86 md
.getExecutionFlows().add(efd
);
92 public void execute(SlcExecution slcExecution
) {
93 applicationContext
.publishEvent(new NewExecutionEvent(this,
97 public void setApplicationContext(ApplicationContext applicationContext
)
98 throws BeansException
{
99 this.applicationContext
= applicationContext
;