X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=sandbox%2Fargeo.slc.executionflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fexecutionflow%2FSimpleExecutionSpec.java;h=ce14efd592fb40e218b836bf67dbd92ab2020e2f;hb=f3797d5a7f833ecb183ce8d4a31a7897fbca4035;hp=f8eb969b8ead89fd8996596ed25674d1ca4cd9d6;hpb=fd419cbd85435070ee575b4cf71f74be011d4282;p=gpl%2Fargeo-slc.git diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java index f8eb969b8..ce14efd59 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java @@ -3,11 +3,17 @@ package org.argeo.slc.executionflow; import java.util.HashMap; import java.util.Map; +import org.argeo.slc.SlcException; import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.factory.BeanNameAware; + +public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware { + private final static ThreadLocal initializingFlow = new ThreadLocal(); -public class SimpleExecutionSpec implements ExecutionSpec { private Map attributes = new HashMap(); + private String name = null; + public Map getAttributes() { return attributes; } @@ -17,17 +23,42 @@ public class SimpleExecutionSpec implements ExecutionSpec { } public Object createRef(String name) { - RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes + ExecutionFlow flow = initializingFlow.get(); + if (flow == null) + throw new SlcException("No flow is currently initializing." + + " Declare flow refs as inner beans or prototypes."); + + RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes .get(name); - Class targetClass = refSpecAttribute.getTargetClass(); - ExecutionTargetSource targetSource = new ExecutionTargetSource(); - targetSource.setName(name); - targetSource.setTargetClass(targetClass); + Class targetClass = refSpecAttribute.getTargetClass(); + ExecutionTargetSource targetSource = new ExecutionTargetSource(flow, + targetClass, name); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetClass(targetClass); proxyFactory.setProxyTargetClass(true); proxyFactory.setTargetSource(targetSource); - + return proxyFactory.getProxy(); } + + public void setBeanName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static void flowInitializationStarted(ExecutionFlow flow) { + initializingFlow.set(flow); + } + + public static void flowInitializationFinished(ExecutionFlow flow) { + ExecutionFlow registeredFlow = initializingFlow.get(); + if (registeredFlow == null) + throw new SlcException("No flow registered"); + if (!flow.getUuid().equals(registeredFlow.getUuid())) + throw new SlcException("Current flow is " + flow); + initializingFlow.set(null); + } }