]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java
bca30d0ed2baa1c5715e641ce82c8bffae7aafd5
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / AbstractSpringExecutionModule.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.Map;
4 import java.util.TreeMap;
5
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;
21
22 @Deprecated
23 public abstract class AbstractSpringExecutionModule implements ExecutionModule
24 {
25 /*
26 protected ApplicationContext applicationContext;
27
28 protected ExecutionContext executionContext;
29
30 protected ExecutionFlowDescriptorConverter descriptorConverter = new DefaultDescriptorConverter();
31
32 public ExecutionModuleDescriptor getDescriptor() {
33 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
34 md.setName(getName());
35 md.setVersion(getVersion());
36
37 Map<String, ExecutionFlow> executionFlows = listFlows();
38 for (String name : executionFlows.keySet()) {
39 ExecutionFlow executionFlow = executionFlows.get(name);
40
41 Assert.notNull(executionFlow.getName());
42 Assert.state(name.equals(executionFlow.getName()));
43
44 ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
45 Assert.notNull(executionSpec);
46 Assert.notNull(executionSpec.getName());
47
48 Map<String, Object> values = new TreeMap<String, Object>();
49 for (String key : executionSpec.getAttributes().keySet()) {
50 ExecutionSpecAttribute attribute = executionSpec
51 .getAttributes().get(key);
52
53 if (executionFlow.isSetAsParameter(key)) {
54 Object value = executionFlow.getParameter(key);
55 if (attribute instanceof PrimitiveSpecAttribute) {
56 PrimitiveValue primitiveValue = new PrimitiveValue();
57 primitiveValue
58 .setType(((PrimitiveSpecAttribute) attribute)
59 .getType());
60 primitiveValue.setValue(value);
61 values.put(key, primitiveValue);
62 } else if (attribute instanceof RefSpecAttribute) {
63 RefValue refValue = new RefValue();
64 if (value instanceof ScopedObject) {
65 refValue.setLabel("RUNTIME "
66 + value.getClass().getName());
67 } else {
68 refValue.setLabel("STATIC "
69 + value.getClass().getName());
70 }
71 values.put(key, refValue);
72 } else if (attribute instanceof ResourceSpecAttribute) {
73 PrimitiveValue primitiveValue = new PrimitiveValue();
74 primitiveValue
75 .setType(((ResourceSpecAttribute) attribute)
76 .getType());
77 primitiveValue.setValue(value);
78 values.put(key, primitiveValue);
79 } else {
80 throw new SlcException("Unkown spec attribute type "
81 + attribute.getClass());
82 }
83 }
84
85 }
86
87 ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
88 values, executionSpec);
89 if (executionFlow.getPath() != null)
90 efd.setPath(executionFlow.getPath());
91
92 // Add execution spec if necessary
93 if (!md.getExecutionSpecs().contains(executionSpec))
94 md.getExecutionSpecs().add(executionSpec);
95
96 // Add execution flow
97 md.getExecutionFlows().add(efd);
98 }
99
100 return md;
101 }
102
103 protected Map<String, ExecutionFlow> listFlows() {
104 GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
105 applicationContext);
106 Map<String, ExecutionFlow> executionFlows = accessor
107 .getBeansOfType(ExecutionFlow.class);
108 return executionFlows;
109 }
110
111 public void execute(ExecutionFlowDescriptor executionFlowDescriptor) {
112 if (descriptorConverter != null)
113 executionContext.addVariables(descriptorConverter
114 .convertValues(executionFlowDescriptor));
115 ExecutionFlow flow = (ExecutionFlow) applicationContext.getBean(
116 executionFlowDescriptor.getName(), ExecutionFlow.class);
117 flow.run();
118 }
119
120 public void setApplicationContext(ApplicationContext applicationContext)
121 throws BeansException {
122 this.applicationContext = applicationContext;
123 }
124
125 public void setExecutionContext(ExecutionContext executionContext) {
126 this.executionContext = executionContext;
127 }
128
129 public void setDescriptorConverter(
130 ExecutionFlowDescriptorConverter descriptorConverter) {
131 this.descriptorConverter = descriptorConverter;
132 }*/
133
134 }