X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FExecutionScope.java;h=36d951093a964c18b68fea9f0348a089e1f553ac;hb=c7f0b5fc6a3c66e2d7de7b37f0ed4983b4a16006;hp=05a60b73bd5e9db39073fed4cbc2fd54e05e3fdd;hpb=7a3b9a150bbd8f6e7110b61fd85594e1a3fb9c53;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionScope.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionScope.java index 05a60b73b..36d951093 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionScope.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionScope.java @@ -13,50 +13,51 @@ import org.springframework.beans.factory.config.Scope; public class ExecutionScope implements Scope { private final static Log log = LogFactory.getLog(ExecutionScope.class); - private final ThreadLocal executionContext - = new ThreadLocal(); - + private final ThreadLocal executionContext = new ThreadLocal(); + public final ThreadLocal executionContextBeanName = new ThreadLocal(); - + public Object get(String name, ObjectFactory objectFactory) { if (log.isTraceEnabled()) log.trace("Getting scoped bean " + name); - + // check if an execution context is defined for this thread - if(executionContext.get() == null) { + if (executionContext.get() == null) { // if not, we expect objectFactory to produce an ExecutionContext Object obj = objectFactory.getObject(); - if(obj instanceof ExecutionContext) { + if (obj instanceof ExecutionContext) { // store the ExecutionContext in the ThreadLocal - executionContext.set((ExecutionContext)obj); + executionContext.set((ExecutionContext) obj); executionContextBeanName.set(name); return obj; + } else { + throw new SlcException( + "Expected an ExecutionContext, got an object of class " + + obj.getClass() + + " for bean " + + name + + ": make sure that you have porperly set scope=\"execution\" where required"); } - else { - throw new SlcException("Expected an ExecutionContext, got an object of class " - + obj.getClass() + " for bean " + name); - } } - - if(name.equals(executionContextBeanName.get())) { + + if (name.equals(executionContextBeanName.get())) { return executionContext.get(); - } - else { - // see if the executionContext already knows the object + } else { + // see if the executionContext already knows the object Object obj = executionContext.get().findScopedObject(name); - if(obj == null) { + if (obj == null) { obj = objectFactory.getObject(); - if(!(obj instanceof ExecutionContext)) { + if (!(obj instanceof ExecutionContext)) { executionContext.get().addScopedObject(name, obj); - } - else { - throw new SlcException("Only one ExecutionContext can be defined per Thread"); + } else { + throw new SlcException( + "Only one ExecutionContext can be defined per Thread"); } } return obj; } - + // if (ExecutionContext.getScopedObjects().containsKey(name)) { // // returns cached instance // Object obj = ExecutionContext.getScopedObjects().get(name); @@ -74,18 +75,17 @@ public class ExecutionScope implements Scope { } public String getConversationId() { - + return executionContext.get().getUuid(); } - + public Boolean hasExecutionContext() { return executionContext.get() != null; } - public void registerDestructionCallback(String name, Runnable callback) { // TODO: implement it - //throw new UnsupportedOperationException(); + // throw new UnsupportedOperationException(); } public Object remove(String name) {