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