]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java
Document and improve execution model
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / AbstractSpringExecutionModule.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution;
18
19 import org.argeo.slc.execution.ExecutionModule;
20
21 @Deprecated
22 public abstract class AbstractSpringExecutionModule implements ExecutionModule
23 {
24 /*
25 protected ApplicationContext applicationContext;
26
27 protected ExecutionContext executionContext;
28
29 protected ExecutionFlowDescriptorConverter descriptorConverter = new DefaultDescriptorConverter();
30
31 public ExecutionModuleDescriptor getDescriptor() {
32 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
33 md.setName(getName());
34 md.setVersion(getVersion());
35
36 Map<String, ExecutionFlow> executionFlows = listFlows();
37 for (String name : executionFlows.keySet()) {
38 ExecutionFlow executionFlow = executionFlows.get(name);
39
40 Assert.notNull(executionFlow.getName());
41 Assert.state(name.equals(executionFlow.getName()));
42
43 ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
44 Assert.notNull(executionSpec);
45 Assert.notNull(executionSpec.getName());
46
47 Map<String, Object> values = new TreeMap<String, Object>();
48 for (String key : executionSpec.getAttributes().keySet()) {
49 ExecutionSpecAttribute attribute = executionSpec
50 .getAttributes().get(key);
51
52 if (executionFlow.isSetAsParameter(key)) {
53 Object value = executionFlow.getParameter(key);
54 if (attribute instanceof PrimitiveSpecAttribute) {
55 PrimitiveValue primitiveValue = new PrimitiveValue();
56 primitiveValue
57 .setType(((PrimitiveSpecAttribute) attribute)
58 .getType());
59 primitiveValue.setValue(value);
60 values.put(key, primitiveValue);
61 } else if (attribute instanceof RefSpecAttribute) {
62 RefValue refValue = new RefValue();
63 if (value instanceof ScopedObject) {
64 refValue.setLabel("RUNTIME "
65 + value.getClass().getName());
66 } else {
67 refValue.setLabel("STATIC "
68 + value.getClass().getName());
69 }
70 values.put(key, refValue);
71 } else if (attribute instanceof ResourceSpecAttribute) {
72 PrimitiveValue primitiveValue = new PrimitiveValue();
73 primitiveValue
74 .setType(((ResourceSpecAttribute) attribute)
75 .getType());
76 primitiveValue.setValue(value);
77 values.put(key, primitiveValue);
78 } else {
79 throw new SlcException("Unkown spec attribute type "
80 + attribute.getClass());
81 }
82 }
83
84 }
85
86 ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
87 values, executionSpec);
88 if (executionFlow.getPath() != null)
89 efd.setPath(executionFlow.getPath());
90
91 // Add execution spec if necessary
92 if (!md.getExecutionSpecs().contains(executionSpec))
93 md.getExecutionSpecs().add(executionSpec);
94
95 // Add execution flow
96 md.getExecutionFlows().add(efd);
97 }
98
99 return md;
100 }
101
102 protected Map<String, ExecutionFlow> listFlows() {
103 GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
104 applicationContext);
105 Map<String, ExecutionFlow> executionFlows = accessor
106 .getBeansOfType(ExecutionFlow.class);
107 return executionFlows;
108 }
109
110 public void execute(ExecutionFlowDescriptor executionFlowDescriptor) {
111 if (descriptorConverter != null)
112 executionContext.addVariables(descriptorConverter
113 .convertValues(executionFlowDescriptor));
114 ExecutionFlow flow = (ExecutionFlow) applicationContext.getBean(
115 executionFlowDescriptor.getName(), ExecutionFlow.class);
116 flow.run();
117 }
118
119 public void setApplicationContext(ApplicationContext applicationContext)
120 throws BeansException {
121 this.applicationContext = applicationContext;
122 }
123
124 public void setExecutionContext(ExecutionContext executionContext) {
125 this.executionContext = executionContext;
126 }
127
128 public void setDescriptorConverter(
129 ExecutionFlowDescriptorConverter descriptorConverter) {
130 this.descriptorConverter = descriptorConverter;
131 }*/
132
133 }