]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionTargetSource.java
Introduce executor and event notifications
[gpl/argeo-slc.git] / sandbox / argeo.slc.executionflow / src / main / java / org / argeo / slc / executionflow / ExecutionTargetSource.java
index 51bdf250f484631da340b29a88a4c7f1a7a62559..b2e0f971b03b9605ee2dae485d155af13bd1e7bf 100644 (file)
@@ -1,22 +1,35 @@
 package org.argeo.slc.executionflow;
 
+import java.util.Map;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
 import org.springframework.aop.TargetSource;
 
 public class ExecutionTargetSource implements TargetSource {
        private final static Log log = LogFactory
                        .getLog(ExecutionTargetSource.class);
 
-       private String name;
-       private Class targetClass;
+       private final String name;
+       private final Class<?> targetClass;
+       private final ExecutionFlow executionFlow;
+
+       public ExecutionTargetSource(ExecutionFlow executionFlow,
+                       Class<?> targetClass, String name) {
+               this.executionFlow = executionFlow;
+               this.targetClass = targetClass;
+               this.name = name;
+       }
 
        public Object getTarget() throws Exception {
                if (log.isTraceEnabled())
                        log.trace("Getting object " + name);
-               ExecutionFlow executionFlow = SimpleExecutionFlow
-                               .getCurrentExecutionFlow();
-               Object obj = executionFlow.getAttributes().get(name);
+               Map<String, Object> attributes = executionFlow.getAttributes();
+               if (!attributes.containsKey(name))
+                       throw new SlcException("Key " + name + " is not registered in "
+                                       + executionFlow);
+               Object obj = attributes.get(name);
                if (log.isTraceEnabled())
                        log.trace("Target object " + obj);
                return obj;
@@ -35,12 +48,4 @@ public class ExecutionTargetSource implements TargetSource {
 
        }
 
-       public void setName(String name) {
-               this.name = name;
-       }
-
-       public void setTargetClass(Class targetClass) {
-               this.targetClass = targetClass;
-       }
-
 }