X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.spring%2Fsrc%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Fgenerator%2FCompositeRunnableFactory.java;fp=org.argeo.slc.spring%2Fsrc%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Fgenerator%2FCompositeRunnableFactory.java;h=f1e80d390d053cb6ea1b5d39064938bad5435e3d;hb=e14154d2baba78852915304d51cbb56bed1d3d3e;hp=0000000000000000000000000000000000000000;hpb=aba0f1135009d9014c42368ecea338088e6d2be1;p=gpl%2Fargeo-slc.git
diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/generator/CompositeRunnableFactory.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/generator/CompositeRunnableFactory.java
new file mode 100644
index 000000000..f1e80d390
--- /dev/null
+++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/generator/CompositeRunnableFactory.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.core.execution.generator;
+
+import java.util.Map;
+
+import org.argeo.slc.SlcException;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+
+/**
+ * Composite RunnableFactory
, redirecting the Runnable
+ * creation to on of the configured RunnableFactory
depending
+ * on an entry of the data of the RunnableDataNode
.
+ */
+public class CompositeRunnableFactory implements RunnableFactory {
+
+ /**
+ * Key used to access factory ID in the data of the RunnableDataNode
+ */
+ private String factoryKey;
+
+ /**
+ * Maps a factory ID to an ExecutionFlowFactory
+ */
+ private Map factories;
+
+ public void createAndRegisterRunnable(RunnableDataNode node,
+ BeanDefinitionRegistry beanDefinitionRegistry) {
+ findFactory(node).createAndRegisterRunnable(node, beanDefinitionRegistry);
+ }
+
+ /**
+ * Finds the RunnableFactory
to use for a RunnableDataNode
+ * @param node
+ * @return the RunnableFactory
to use for the RunnableDataNode
+ */
+ private RunnableFactory findFactory(RunnableDataNode node) {
+ // get the factory ID from the data of the RunnableDescriptor
+ Map data = node.getData();
+ if (!data.containsKey(factoryKey)) {
+ throw new SlcException("No data value for key '" + factoryKey + "'");
+ }
+ String factoryId = data.get(factoryKey).toString();
+
+ // see if we have a factory for the factory ID
+ if ((factories != null) && factories.containsKey(factoryId)) {
+ return factories.get(factoryId);
+ }
+ // if not, look for a bean of name equals to the factory ID
+ else {
+ throw new SlcException("Not implemented");
+ }
+ }
+
+ public void setFactoryKey(String factoryKey) {
+ this.factoryKey = factoryKey;
+ }
+
+ public void setFactories(Map factories) {
+ this.factories = factories;
+ }
+
+
+}