]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java
Local variables management
[gpl/argeo-slc.git] / sandbox / argeo.slc.executionflow / src / main / java / org / argeo / slc / executionflow / SimpleExecutionFlow.java
index cb27e68401327d34e1342a0cf3408b9d9f9a4d53..225400e1b9e8f31ec857edf9ca6d9b78d5dd867b 100644 (file)
@@ -18,7 +18,7 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                BeanNameAware {
        private ExecutionSpec executionSpec = new SimpleExecutionSpec();
        private String name = null;
-       private Map<String, Object> attributes = new HashMap<String, Object>();
+       private Map<String, Object> parameters = new HashMap<String, Object>();
        private List<Executable> executables = new ArrayList<Executable>();
 
        private final String uuid = UUID.randomUUID().toString();
@@ -34,19 +34,19 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                if (executionSpec == null)
                        return;
 
-               MapBindingResult errors = new MapBindingResult(attributes, "execution#"
+               MapBindingResult errors = new MapBindingResult(parameters, "execution#"
                                + getUuid());
                for (String key : executionSpec.getAttributes().keySet()) {
                        ExecutionSpecAttribute executionSpecAttr = executionSpec
                                        .getAttributes().get(key);
-                       if (!attributes.containsKey(key)) {
+                       if (!parameters.containsKey(key)) {
                                Object defaultValue = executionSpecAttr.getValue();
                                if (defaultValue == null)
                                        errors.rejectValue(key, "Not set and no default value");
                                else
-                                       attributes.put(key, defaultValue);
+                                       parameters.put(key, defaultValue);
                        } else {// contains key
-                               Object obj = attributes.get(key);
+                               Object obj = parameters.get(key);
                                if (executionSpecAttr instanceof RefSpecAttribute) {
                                        RefSpecAttribute rsa = (RefSpecAttribute) executionSpecAttr;
                                        Class targetClass = rsa.getTargetClass();
@@ -76,12 +76,8 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                this.executionSpec = executionSpec;
        }
 
-       public void setAttributes(Map<String, Object> attributes) {
-               this.attributes = attributes;
-       }
-
-       public Map<String, Object> getAttributes() {
-               return attributes;
+       public void setParameters(Map<String, Object> attributes) {
+               this.parameters = attributes;
        }
 
        public String getUuid() {
@@ -92,6 +88,25 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                return executionSpec;
        }
 
+       public Object getParameter(String name) {
+               if (parameters.containsKey(name)) {
+                       return parameters.get(name);
+               } else {
+                       if (executionSpec.getAttributes().containsKey(name)) {
+                               ExecutionSpecAttribute esa = executionSpec.getAttributes().get(
+                                               name);
+                               if (esa.getValue() != null)
+                                       return esa.getValue();
+                       } else {
+                               throw new SlcException("Key " + name
+                                               + " is not define in the specifications of "
+                                               + toString());
+                       }
+               }
+               throw new SlcException("Key " + name + " is not set as parameter in "
+                               + toString());
+       }
+
        public String toString() {
                return new StringBuffer("Flow ").append(name).toString();// .append(" [#")
                // .append(uuid).append(']').toString();