+
+ // check if an execution context is defined for this thread
+ if (executionContext.get() == null) {
+ // if not, we expect objectFactory to produce an ExecutionContext
+ Object obj = objectFactory.getObject();
+ if (obj instanceof ExecutionContext) {
+ // store the ExecutionContext in the ThreadLocal
+ 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");
+ }
+ }
+
+ if (name.equals(executionContextBeanName.get())) {
+ return executionContext.get();
+ } else {
+ // see if the executionContext already knows the object
+ Object obj = executionContext.get().findScopedObject(name);
+ if (obj == null) {
+ obj = objectFactory.getObject();
+ if (!(obj instanceof ExecutionContext)) {
+ executionContext.get().addScopedObject(name, obj);
+ } else {
+ throw new SlcException(
+ "Only one ExecutionContext can be defined per Thread");
+ }
+ }
+ return obj;
+ }