--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.core.execution.generator;\r
+\r
+import java.util.Map;\r
+\r
+import org.argeo.slc.SlcException;\r
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;\r
+\r
+/**\r
+ * Composite <code>RunnableFactory</code>, redirecting the Runnable \r
+ * creation to on of the configured <code>RunnableFactory</code> depending\r
+ * on an entry of the data of the <code>RunnableDataNode</code>.\r
+ */\r
+public class CompositeRunnableFactory implements RunnableFactory {\r
+\r
+ /**\r
+ * Key used to access factory ID in the data of the <code>RunnableDataNode</code>\r
+ */\r
+ private String factoryKey;\r
+\r
+ /**\r
+ * Maps a factory ID to an ExecutionFlowFactory\r
+ */\r
+ private Map<String, RunnableFactory> factories;\r
+\r
+ public void createAndRegisterRunnable(RunnableDataNode node,\r
+ BeanDefinitionRegistry beanDefinitionRegistry) {\r
+ findFactory(node).createAndRegisterRunnable(node, beanDefinitionRegistry);\r
+ } \r
+ \r
+ /**\r
+ * Finds the <code>RunnableFactory</code> to use for a <code>RunnableDataNode</code>\r
+ * @param node\r
+ * @return the <code>RunnableFactory</code> to use for the <code>RunnableDataNode</code>\r
+ */\r
+ private RunnableFactory findFactory(RunnableDataNode node) {\r
+ // get the factory ID from the data of the RunnableDescriptor\r
+ Map<String, Object> data = node.getData();\r
+ if (!data.containsKey(factoryKey)) {\r
+ throw new SlcException("No data value for key '" + factoryKey + "'");\r
+ }\r
+ String factoryId = data.get(factoryKey).toString();\r
+ \r
+ // see if we have a factory for the factory ID\r
+ if ((factories != null) && factories.containsKey(factoryId)) {\r
+ return factories.get(factoryId);\r
+ }\r
+ // if not, look for a bean of name equals to the factory ID\r
+ else {\r
+ throw new SlcException("Not implemented");\r
+ } \r
+ }\r
+ \r
+ public void setFactoryKey(String factoryKey) {\r
+ this.factoryKey = factoryKey;\r
+ }\r
+\r
+ public void setFactories(Map<String, RunnableFactory> factories) {\r
+ this.factories = factories;\r
+ }\r
+\r
+\r
+}\r