1 package org
.argeo
.slc
.core
.execution
;
3 import org
.argeo
.slc
.execution
.ExecutionModule
;
6 public abstract class AbstractSpringExecutionModule
implements ExecutionModule
9 protected ApplicationContext applicationContext;
11 protected ExecutionContext executionContext;
13 protected ExecutionFlowDescriptorConverter descriptorConverter = new DefaultDescriptorConverter();
15 public ExecutionModuleDescriptor getDescriptor() {
16 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
17 md.setName(getName());
18 md.setVersion(getVersion());
20 Map<String, ExecutionFlow> executionFlows = listFlows();
21 for (String name : executionFlows.keySet()) {
22 ExecutionFlow executionFlow = executionFlows.get(name);
24 Assert.notNull(executionFlow.getName());
25 Assert.state(name.equals(executionFlow.getName()));
27 ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
28 Assert.notNull(executionSpec);
29 Assert.notNull(executionSpec.getName());
31 Map<String, Object> values = new TreeMap<String, Object>();
32 for (String key : executionSpec.getAttributes().keySet()) {
33 ExecutionSpecAttribute attribute = executionSpec
34 .getAttributes().get(key);
36 if (executionFlow.isSetAsParameter(key)) {
37 Object value = executionFlow.getParameter(key);
38 if (attribute instanceof PrimitiveSpecAttribute) {
39 PrimitiveValue primitiveValue = new PrimitiveValue();
41 .setType(((PrimitiveSpecAttribute) attribute)
43 primitiveValue.setValue(value);
44 values.put(key, primitiveValue);
45 } else if (attribute instanceof RefSpecAttribute) {
46 RefValue refValue = new RefValue();
47 if (value instanceof ScopedObject) {
48 refValue.setLabel("RUNTIME "
49 + value.getClass().getName());
51 refValue.setLabel("STATIC "
52 + value.getClass().getName());
54 values.put(key, refValue);
55 } else if (attribute instanceof ResourceSpecAttribute) {
56 PrimitiveValue primitiveValue = new PrimitiveValue();
58 .setType(((ResourceSpecAttribute) attribute)
60 primitiveValue.setValue(value);
61 values.put(key, primitiveValue);
63 throw new SlcException("Unkown spec attribute type "
64 + attribute.getClass());
70 ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
71 values, executionSpec);
72 if (executionFlow.getPath() != null)
73 efd.setPath(executionFlow.getPath());
75 // Add execution spec if necessary
76 if (!md.getExecutionSpecs().contains(executionSpec))
77 md.getExecutionSpecs().add(executionSpec);
80 md.getExecutionFlows().add(efd);
86 protected Map<String, ExecutionFlow> listFlows() {
87 GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
89 Map<String, ExecutionFlow> executionFlows = accessor
90 .getBeansOfType(ExecutionFlow.class);
91 return executionFlows;
94 public void execute(ExecutionFlowDescriptor executionFlowDescriptor) {
95 if (descriptorConverter != null)
96 executionContext.addVariables(descriptorConverter
97 .convertValues(executionFlowDescriptor));
98 ExecutionFlow flow = (ExecutionFlow) applicationContext.getBean(
99 executionFlowDescriptor.getName(), ExecutionFlow.class);
103 public void setApplicationContext(ApplicationContext applicationContext)
104 throws BeansException {
105 this.applicationContext = applicationContext;
108 public void setExecutionContext(ExecutionContext executionContext) {
109 this.executionContext = executionContext;
112 public void setDescriptorConverter(
113 ExecutionFlowDescriptorConverter descriptorConverter) {
114 this.descriptorConverter = descriptorConverter;