]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java
Modular distributions
[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 org.argeo.slc.execution.ExecutionModule;
4
5 @Deprecated
6 public abstract class AbstractSpringExecutionModule implements ExecutionModule
7 {
8 /*
9 protected ApplicationContext applicationContext;
10
11 protected ExecutionContext executionContext;
12
13 protected ExecutionFlowDescriptorConverter descriptorConverter = new DefaultDescriptorConverter();
14
15 public ExecutionModuleDescriptor getDescriptor() {
16 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
17 md.setName(getName());
18 md.setVersion(getVersion());
19
20 Map<String, ExecutionFlow> executionFlows = listFlows();
21 for (String name : executionFlows.keySet()) {
22 ExecutionFlow executionFlow = executionFlows.get(name);
23
24 Assert.notNull(executionFlow.getName());
25 Assert.state(name.equals(executionFlow.getName()));
26
27 ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
28 Assert.notNull(executionSpec);
29 Assert.notNull(executionSpec.getName());
30
31 Map<String, Object> values = new TreeMap<String, Object>();
32 for (String key : executionSpec.getAttributes().keySet()) {
33 ExecutionSpecAttribute attribute = executionSpec
34 .getAttributes().get(key);
35
36 if (executionFlow.isSetAsParameter(key)) {
37 Object value = executionFlow.getParameter(key);
38 if (attribute instanceof PrimitiveSpecAttribute) {
39 PrimitiveValue primitiveValue = new PrimitiveValue();
40 primitiveValue
41 .setType(((PrimitiveSpecAttribute) attribute)
42 .getType());
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());
50 } else {
51 refValue.setLabel("STATIC "
52 + value.getClass().getName());
53 }
54 values.put(key, refValue);
55 } else if (attribute instanceof ResourceSpecAttribute) {
56 PrimitiveValue primitiveValue = new PrimitiveValue();
57 primitiveValue
58 .setType(((ResourceSpecAttribute) attribute)
59 .getType());
60 primitiveValue.setValue(value);
61 values.put(key, primitiveValue);
62 } else {
63 throw new SlcException("Unkown spec attribute type "
64 + attribute.getClass());
65 }
66 }
67
68 }
69
70 ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
71 values, executionSpec);
72 if (executionFlow.getPath() != null)
73 efd.setPath(executionFlow.getPath());
74
75 // Add execution spec if necessary
76 if (!md.getExecutionSpecs().contains(executionSpec))
77 md.getExecutionSpecs().add(executionSpec);
78
79 // Add execution flow
80 md.getExecutionFlows().add(efd);
81 }
82
83 return md;
84 }
85
86 protected Map<String, ExecutionFlow> listFlows() {
87 GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
88 applicationContext);
89 Map<String, ExecutionFlow> executionFlows = accessor
90 .getBeansOfType(ExecutionFlow.class);
91 return executionFlows;
92 }
93
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);
100 flow.run();
101 }
102
103 public void setApplicationContext(ApplicationContext applicationContext)
104 throws BeansException {
105 this.applicationContext = applicationContext;
106 }
107
108 public void setExecutionContext(ExecutionContext executionContext) {
109 this.executionContext = executionContext;
110 }
111
112 public void setDescriptorConverter(
113 ExecutionFlowDescriptorConverter descriptorConverter) {
114 this.descriptorConverter = descriptorConverter;
115 }*/
116
117 }