]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/CompositeRunnableFactory.java
Improve SystemCall
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / generator / CompositeRunnableFactory.java
1 package org.argeo.slc.core.execution.generator;
2
3 import java.util.Map;
4
5 import org.argeo.slc.SlcException;
6 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
7
8 /**
9 * Composite <code>RunnableFactory</code>, redirecting the Runnable
10 * creation to on of the configured <code>RunnableFactory</code> depending
11 * on an entry of the data of the <code>RunnableDataNode</code>.
12 */
13 public class CompositeRunnableFactory implements RunnableFactory {
14
15 /**
16 * Key used to access factory ID in the data of the <code>RunnableDataNode</code>
17 */
18 private String factoryKey;
19
20 /**
21 * Maps a factory ID to an ExecutionFlowFactory
22 */
23 private Map<String, RunnableFactory> factories;
24
25 public void createAndRegisterRunnable(RunnableDataNode node,
26 BeanDefinitionRegistry beanDefinitionRegistry) {
27 findFactory(node).createAndRegisterRunnable(node, beanDefinitionRegistry);
28 }
29
30 /**
31 * Finds the <code>RunnableFactory</code> to use for a <code>RunnableDataNode</code>
32 * @param node
33 * @return the <code>RunnableFactory</code> to use for the <code>RunnableDataNode</code>
34 */
35 private RunnableFactory findFactory(RunnableDataNode node) {
36 // get the factory ID from the data of the RunnableDescriptor
37 Map<String, Object> data = node.getData();
38 if (!data.containsKey(factoryKey)) {
39 throw new SlcException("No data value for key '" + factoryKey + "'");
40 }
41 String factoryId = data.get(factoryKey).toString();
42
43 // see if we have a factory for the factory ID
44 if ((factories != null) && factories.containsKey(factoryId)) {
45 return factories.get(factoryId);
46 }
47 // if not, look for a bean of name equals to the factory ID
48 else {
49 throw new SlcException("Not implemented");
50 }
51 }
52
53 public void setFactoryKey(String factoryKey) {
54 this.factoryKey = factoryKey;
55 }
56
57 public void setFactories(Map<String, RunnableFactory> factories) {
58 this.factories = factories;
59 }
60
61
62 }