]> 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
Add license headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / generator / CompositeRunnableFactory.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.generator;
18
19 import java.util.Map;
20
21 import org.argeo.slc.SlcException;
22 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
23
24 /**
25 * Composite <code>RunnableFactory</code>, redirecting the Runnable
26 * creation to on of the configured <code>RunnableFactory</code> depending
27 * on an entry of the data of the <code>RunnableDataNode</code>.
28 */
29 public class CompositeRunnableFactory implements RunnableFactory {
30
31 /**
32 * Key used to access factory ID in the data of the <code>RunnableDataNode</code>
33 */
34 private String factoryKey;
35
36 /**
37 * Maps a factory ID to an ExecutionFlowFactory
38 */
39 private Map<String, RunnableFactory> factories;
40
41 public void createAndRegisterRunnable(RunnableDataNode node,
42 BeanDefinitionRegistry beanDefinitionRegistry) {
43 findFactory(node).createAndRegisterRunnable(node, beanDefinitionRegistry);
44 }
45
46 /**
47 * Finds the <code>RunnableFactory</code> to use for a <code>RunnableDataNode</code>
48 * @param node
49 * @return the <code>RunnableFactory</code> to use for the <code>RunnableDataNode</code>
50 */
51 private RunnableFactory findFactory(RunnableDataNode node) {
52 // get the factory ID from the data of the RunnableDescriptor
53 Map<String, Object> data = node.getData();
54 if (!data.containsKey(factoryKey)) {
55 throw new SlcException("No data value for key '" + factoryKey + "'");
56 }
57 String factoryId = data.get(factoryKey).toString();
58
59 // see if we have a factory for the factory ID
60 if ((factories != null) && factories.containsKey(factoryId)) {
61 return factories.get(factoryId);
62 }
63 // if not, look for a bean of name equals to the factory ID
64 else {
65 throw new SlcException("Not implemented");
66 }
67 }
68
69 public void setFactoryKey(String factoryKey) {
70 this.factoryKey = factoryKey;
71 }
72
73 public void setFactories(Map<String, RunnableFactory> factories) {
74 this.factories = factories;
75 }
76
77
78 }