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