]> git.argeo.org Git - gpl/argeo-slc.git/blob - execution/AbstractSpringExecutionModule.java
Prepare next development cycle
[gpl/argeo-slc.git] / execution / AbstractSpringExecutionModule.java
1 package org.argeo.slc.execution;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.argeo.slc.process.SlcExecution;
7 import org.springframework.beans.BeansException;
8 import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
9 import org.springframework.context.ApplicationContext;
10 import org.springframework.context.ApplicationContextAware;
11 import org.springframework.util.Assert;
12
13 public abstract class AbstractSpringExecutionModule implements ExecutionModule,
14 ApplicationContextAware {
15 private ApplicationContext applicationContext;
16
17 public ExecutionModuleDescriptor getDescriptor() {
18 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
19 md.setName(getName());
20 md.setVersion(getVersion());
21
22 GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
23 applicationContext);
24 Map<String, ExecutionFlow> executionFlows = accessor
25 .getBeansOfType(ExecutionFlow.class);
26
27 for (String name : executionFlows.keySet()) {
28 ExecutionFlow executionFlow = executionFlows.get(name);
29
30 Assert.notNull(executionFlow.getName());
31 Assert.state(name.equals(executionFlow.getName()));
32
33 ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
34 Assert.notNull(executionSpec);
35 Assert.notNull(executionSpec.getName());
36
37 Map<String, Object> values = new HashMap<String, Object>();
38 for (String key : executionSpec.getAttributes().keySet()) {
39 ExecutionSpecAttribute attribute = executionSpec
40 .getAttributes().get(key);
41 if (attribute instanceof SimpleExecutionSpec
42 && attribute.getIsParameter()) {
43 values.put(key, executionFlow.getParameter(key));
44 }
45 }
46
47 ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
48 values, executionSpec);
49
50 if (!md.getExecutionSpecs().contains(executionSpec))
51 md.getExecutionSpecs().add(executionSpec);
52 md.getExecutionFlows().add(efd);
53 }
54
55 return md;
56 }
57
58 public void execute(SlcExecution slcExecution) {
59 applicationContext.publishEvent(new NewExecutionEvent(this,
60 slcExecution));
61 }
62
63 public void setApplicationContext(ApplicationContext applicationContext)
64 throws BeansException {
65 this.applicationContext = applicationContext;
66 }
67
68 }