X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FAbstractSpringExecutionModule.java;h=1bbf16821539b2a8ec06bcfc234274ebded757e1;hb=53146ebdda3a7c0c217c44d395d270a7e9d045be;hp=fa42917fdb3e5ca43e43efdb79d1b6aa04939fdb;hpb=1b19cac6a92c31d9119fc2986e7aaf3df98b2393;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java index fa42917fd..1bbf16821 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java @@ -1,15 +1,18 @@ package org.argeo.slc.core.execution; -import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; +import org.argeo.slc.SlcException; +import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionFlowDescriptorConverter; import org.argeo.slc.execution.ExecutionModule; import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; -import org.argeo.slc.process.SlcExecution; +import org.springframework.aop.scope.ScopedObject; import org.springframework.beans.BeansException; import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor; import org.springframework.context.ApplicationContext; @@ -18,8 +21,13 @@ import org.springframework.util.Assert; public abstract class AbstractSpringExecutionModule implements ExecutionModule, ApplicationContextAware { + private ApplicationContext applicationContext; + private ExecutionContext executionContext; + + private ExecutionFlowDescriptorConverter descriptorConverter = new DefaultDescriptorConverter(); + public ExecutionModuleDescriptor getDescriptor() { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); md.setName(getName()); @@ -40,30 +48,68 @@ public abstract class AbstractSpringExecutionModule implements ExecutionModule, Assert.notNull(executionSpec); Assert.notNull(executionSpec.getName()); - Map values = new HashMap(); + Map values = new TreeMap(); for (String key : executionSpec.getAttributes().keySet()) { ExecutionSpecAttribute attribute = executionSpec .getAttributes().get(key); - if (attribute instanceof SimpleExecutionSpec - && attribute.getIsParameter()) { - values.put(key, executionFlow.getParameter(key)); + + if (executionFlow.isSetAsParameter(key)) { + Object value = executionFlow.getParameter(key); + if (attribute instanceof PrimitiveSpecAttribute) { + PrimitiveValue primitiveValue = new PrimitiveValue(); + primitiveValue + .setType(((PrimitiveSpecAttribute) attribute) + .getType()); + primitiveValue.setValue(value); + values.put(key, primitiveValue); + } else if (attribute instanceof RefSpecAttribute) { + RefValue refValue = new RefValue(); + if (value instanceof ScopedObject) { + refValue.setLabel("RUNTIME " + + value.getClass().getName()); + } else { + refValue.setLabel("STATIC " + + value.getClass().getName()); + } + values.put(key, refValue); + } else if (attribute instanceof ResourceSpecAttribute) { + PrimitiveValue primitiveValue = new PrimitiveValue(); + primitiveValue + .setType(((ResourceSpecAttribute) attribute) + .getType()); + primitiveValue.setValue(value); + values.put(key, primitiveValue); + } else { + throw new SlcException("Unkown spec attribute type " + + attribute.getClass()); + } } + } ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, values, executionSpec); + if (executionFlow.getPath() != null) + efd.setPath(executionFlow.getPath()); + // Add execution spec if necessary if (!md.getExecutionSpecs().contains(executionSpec)) md.getExecutionSpecs().add(executionSpec); + + // Add execution flow md.getExecutionFlows().add(efd); } return md; } - public void execute(SlcExecution slcExecution) { - applicationContext.publishEvent(new NewExecutionEvent(this, - slcExecution)); + public void execute(ExecutionFlowDescriptor executionFlowDescriptor) { + if (descriptorConverter != null) + executionContext.addVariables(descriptorConverter + .convertValues(executionFlowDescriptor)); + ExecutionFlow flow = (ExecutionFlow) applicationContext.getBean( + executionFlowDescriptor.getName(), ExecutionFlow.class); + flow.run(); } public void setApplicationContext(ApplicationContext applicationContext) @@ -71,4 +117,13 @@ public abstract class AbstractSpringExecutionModule implements ExecutionModule, this.applicationContext = applicationContext; } + public void setExecutionContext(ExecutionContext executionContext) { + this.executionContext = executionContext; + } + + public void setDescriptorConverter( + ExecutionFlowDescriptorConverter descriptorConverter) { + this.descriptorConverter = descriptorConverter; + } + }