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; } }