1 package org
.argeo
.slc
.core
.execution
;
4 import java
.util
.TreeMap
;
6 import org
.argeo
.slc
.SlcException
;
7 import org
.argeo
.slc
.execution
.ExecutionContext
;
8 import org
.argeo
.slc
.execution
.ExecutionFlow
;
9 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
10 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptorConverter
;
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
.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
{
25 private ApplicationContext applicationContext
;
27 private ExecutionContext executionContext
;
29 private ExecutionFlowDescriptorConverter descriptorConverter
= new DefaultDescriptorConverter();
31 public ExecutionModuleDescriptor
getDescriptor() {
32 ExecutionModuleDescriptor md
= new ExecutionModuleDescriptor();
33 md
.setName(getName());
34 md
.setVersion(getVersion());
36 GenericBeanFactoryAccessor accessor
= new GenericBeanFactoryAccessor(
38 Map
<String
, ExecutionFlow
> executionFlows
= accessor
39 .getBeansOfType(ExecutionFlow
.class);
41 for (String name
: executionFlows
.keySet()) {
42 ExecutionFlow executionFlow
= executionFlows
.get(name
);
44 Assert
.notNull(executionFlow
.getName());
45 Assert
.state(name
.equals(executionFlow
.getName()));
47 ExecutionSpec executionSpec
= executionFlow
.getExecutionSpec();
48 Assert
.notNull(executionSpec
);
49 Assert
.notNull(executionSpec
.getName());
51 Map
<String
, Object
> values
= new TreeMap
<String
, Object
>();
52 for (String key
: executionSpec
.getAttributes().keySet()) {
53 ExecutionSpecAttribute attribute
= executionSpec
54 .getAttributes().get(key
);
56 if (executionFlow
.isSetAsParameter(key
)) {
57 Object value
= executionFlow
.getParameter(key
);
58 if (attribute
instanceof PrimitiveSpecAttribute
) {
59 PrimitiveValue primitiveValue
= new PrimitiveValue();
61 .setType(((PrimitiveSpecAttribute
) attribute
)
63 primitiveValue
.setValue(value
);
64 values
.put(key
, primitiveValue
);
65 } else if (attribute
instanceof RefSpecAttribute
) {
66 RefValue refValue
= new RefValue();
67 if (value
instanceof ScopedObject
) {
68 refValue
.setLabel("RUNTIME "
69 + value
.getClass().getName());
71 refValue
.setLabel("STATIC "
72 + value
.getClass().getName());
74 values
.put(key
, refValue
);
75 } else if (attribute
instanceof ResourceSpecAttribute
) {
76 PrimitiveValue primitiveValue
= new PrimitiveValue();
78 .setType(((ResourceSpecAttribute
) attribute
)
80 primitiveValue
.setValue(value
);
81 values
.put(key
, primitiveValue
);
83 throw new SlcException("Unkown spec attribute type "
84 + attribute
.getClass());
90 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(name
,
91 values
, executionSpec
);
92 if (executionFlow
.getPath() != null)
93 efd
.setPath(executionFlow
.getPath());
95 // Add execution spec if necessary
96 if (!md
.getExecutionSpecs().contains(executionSpec
))
97 md
.getExecutionSpecs().add(executionSpec
);
100 md
.getExecutionFlows().add(efd
);
106 public void execute(ExecutionFlowDescriptor executionFlowDescriptor
) {
107 if (descriptorConverter
!= null)
108 executionContext
.addVariables(descriptorConverter
109 .convertValues(executionFlowDescriptor
));
110 ExecutionFlow flow
= (ExecutionFlow
) applicationContext
.getBean(
111 executionFlowDescriptor
.getName(), ExecutionFlow
.class);
115 public void setApplicationContext(ApplicationContext applicationContext
)
116 throws BeansException
{
117 this.applicationContext
= applicationContext
;
120 public void setExecutionContext(ExecutionContext executionContext
) {
121 this.executionContext
= executionContext
;
124 public void setDescriptorConverter(
125 ExecutionFlowDescriptorConverter descriptorConverter
) {
126 this.descriptorConverter
= descriptorConverter
;