]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Add module descriptor
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 24 Feb 2009 08:15:52 +0000 (08:15 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 24 Feb 2009 08:15:52 +0000 (08:15 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2170 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionContext.java
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionFlow.java
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java [new file with mode: 0644]
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java [new file with mode: 0644]
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionRegister.java
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionSpec.java
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/SimpleExecutionFlow.java
runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/SimpleExecutionSpec.java

index db8af23d5d76657665cf19991335bde8a38da69c..cd2baa3da402610bc51bfa7a679432f3dda90b31 100644 (file)
@@ -110,8 +110,8 @@ public class ExecutionContext {
                                        + getCurrentStackUuid() + ", depth=" + stack.size());
 
                ExecutionFlowRuntime leftEf = stack.pop();
-               if (!leftEf.getExecutionFlow().getUuid()
-                               .equals(executionFlow.getUuid()))
+               if (!leftEf.getExecutionFlow().getName()
+                               .equals(executionFlow.getName()))
                        throw new SlcException("Asked to leave " + executionFlow
                                        + " but last is " + leftEf);
 
index b0075bf25027d19f77df2adb9da8d03ecc80e42e..0cbd741c7b6938b037f6ee2e1cee31a0e9d4fec6 100644 (file)
@@ -7,5 +7,5 @@ import org.argeo.slc.process.Executable;
 public interface ExecutionFlow extends Executable{
        public Object getParameter(String name);
        public ExecutionSpec getExecutionSpec();
-       public String getUuid();
+       public String getName();
 }
diff --git a/runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java b/runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java
new file mode 100644 (file)
index 0000000..5489542
--- /dev/null
@@ -0,0 +1,44 @@
+package org.argeo.slc.execution;
+
+import java.util.Map;
+
+public class ExecutionFlowDescriptor {
+       private String name;
+       private Map<String, Object> values;
+       private ExecutionSpec executionSpec;
+
+       public ExecutionFlowDescriptor() {
+       }
+
+       public ExecutionFlowDescriptor(String name, Map<String, Object> values,
+                       ExecutionSpec executionSpec) {
+               this.name = name;
+               this.values = values;
+               this.executionSpec = executionSpec;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public Map<String, Object> getValues() {
+               return values;
+       }
+
+       public ExecutionSpec getExecutionSpec() {
+               return executionSpec;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public void setValues(Map<String, Object> values) {
+               this.values = values;
+       }
+
+       public void setExecutionSpec(ExecutionSpec executionSpec) {
+               this.executionSpec = executionSpec;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java b/runtime/org.argeo.slc.execution/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java
new file mode 100644 (file)
index 0000000..548eb11
--- /dev/null
@@ -0,0 +1,26 @@
+package org.argeo.slc.execution;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExecutionModuleDescriptor {
+       private List<ExecutionSpec> executionSpecs = new ArrayList<ExecutionSpec>();
+       private List<ExecutionFlowDescriptor> executionFlows = new ArrayList<ExecutionFlowDescriptor>();
+
+       public List<ExecutionSpec> getExecutionSpecs() {
+               return executionSpecs;
+       }
+
+       public List<ExecutionFlowDescriptor> getExecutionFlows() {
+               return executionFlows;
+       }
+
+       public void setExecutionSpecs(List<ExecutionSpec> executionSpecs) {
+               this.executionSpecs = executionSpecs;
+       }
+
+       public void setExecutionFlows(List<ExecutionFlowDescriptor> executionFlows) {
+               this.executionFlows = executionFlows;
+       }
+
+}
index c4f958e9f845aa53b884652cf57ff88bc444b29e..957addee104245e164dc626cc00aa4ccd90c7752 100644 (file)
@@ -1,47 +1,69 @@
 package org.argeo.slc.execution;
 
+import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.util.Assert;
 
-public class ExecutionRegister implements InitializingBean {
+public class ExecutionRegister implements InitializingBean,
+               ApplicationContextAware {
        private final static Log log = LogFactory.getLog(ExecutionRegister.class);
 
-       @Autowired
-       private Set<ExecutionFlow> executionFlows;
+       private ApplicationContext applicationContext;
 
-       @Autowired
-       private Set<ExecutionSpec> executionSpecs;
+       public ExecutionModuleDescriptor getDescriptor() {
+               ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
 
-       public void afterPropertiesSet() throws Exception {
-               log.debug("Register: " + executionSpecs.size() + " specs");
-               for (ExecutionSpec spec : executionSpecs) {
-                       log.debug(spec);
-                       Map<String, ExecutionSpecAttribute> attributes = spec
-                                       .getAttributes();
-                       log.debug("Spec attributes: ");
-                       for (String key : attributes.keySet()) {
-                               log.debug(" " + key + "\t" + attributes.get(key));
+               GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
+                               applicationContext);
+               Map<String, ExecutionFlow> executionFlows = accessor
+                               .getBeansOfType(ExecutionFlow.class);
+
+               for (String name : executionFlows.keySet()) {
+                       ExecutionFlow executionFlow = executionFlows.get(name);
+
+                       Assert.notNull(executionFlow.getName());
+                       Assert.state(name.equals(executionFlow.getName()));
+
+                       ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
+                       Assert.notNull(executionSpec);
+                       Assert.notNull(executionSpec.getName());
+
+                       Map<String, Object> values = new HashMap<String, Object>();
+                       for (String key : executionSpec.getAttributes().keySet()) {
+                               ExecutionSpecAttribute attribute = executionSpec
+                                               .getAttributes().get(key);
+                               if (attribute instanceof SimpleExecutionSpec
+                                               && attribute.getIsParameter()) {
+                                       values.put(key, executionFlow.getParameter(key));
+                               }
                        }
-               }
 
-               log.debug("Register: " + executionFlows.size() + " flows");
-               for (ExecutionFlow flow : executionFlows) {
-                       log.debug(flow);
-//                     Map<String, Object> attributes = flow.getAttributes();
-//                     log.debug("Specified parameters: ");
-//                     for (String key : flow.getExecutionSpec().getAttributes().keySet()) {
-//                             log.debug(" "
-//                                             + key
-//                                             + "\t"
-//                                             + (attributes.containsKey(key) ? "SPECIFIED"
-//                                                             : "TO SPECIFY"));
-//                     }
+                       ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
+                                       values, executionSpec);
+
+                       if (!md.getExecutionSpecs().contains(executionSpec))
+                               md.getExecutionSpecs().add(executionSpec);
+                       md.getExecutionFlows().add(efd);
                }
 
+               return md;
        }
+
+       public void afterPropertiesSet() throws Exception {
+               log.debug("Execution Module Descriptor:\n" + getDescriptor());
+       }
+
+       public void setApplicationContext(ApplicationContext applicationContext)
+                       throws BeansException {
+               this.applicationContext = applicationContext;
+       }
+
 }
index 24a3c83a2507ebdad240c18d5f56442ff277588b..60924768bb851bf9863f5623580c0afde1af0a62 100644 (file)
@@ -4,4 +4,6 @@ import java.util.Map;
 
 public interface ExecutionSpec {
        public Map<String, ExecutionSpecAttribute> getAttributes();
+
+       public String getName();
 }
index 5c62cdfff5fbf2d8a7a9a33b6ceb9e548aa8b615..53114291f32e952ca82fc8be4b90e516c2f2488a 100644 (file)
@@ -21,13 +21,11 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
        private Map<String, Object> parameters = new HashMap<String, Object>();
        private List<Executable> executables = new ArrayList<Executable>();
 
-       private final String uuid = UUID.randomUUID().toString();
-       
-       public SimpleExecutionFlow(){
-               
+       public SimpleExecutionFlow() {
+
        }
 
-       public SimpleExecutionFlow(Map<String, Object> parameters){
+       public SimpleExecutionFlow(Map<String, Object> parameters) {
                this.parameters.putAll(parameters);
        }
 
@@ -43,7 +41,7 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                        return;
 
                MapBindingResult errors = new MapBindingResult(parameters, "execution#"
-                               + getUuid());
+                               + getName());
                for (String key : executionSpec.getAttributes().keySet()) {
                        ExecutionSpecAttribute executionSpecAttr = executionSpec
                                        .getAttributes().get(key);
@@ -88,8 +86,8 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                this.parameters = attributes;
        }
 
-       public String getUuid() {
-               return uuid;
+       public String getName() {
+               return name;
        }
 
        public ExecutionSpec getExecutionSpec() {
@@ -107,7 +105,7 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
                                        return esa.getValue();
                        } else {
                                throw new SlcException("Key " + name
-                                               + " is not define in the specifications of "
+                                               + " is not defined in the specifications of "
                                                + toString());
                        }
                }
@@ -116,7 +114,10 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
        }
 
        public String toString() {
-               return new StringBuffer("Flow ").append(name).toString();// .append(" [#")
-               // .append(uuid).append(']').toString();
+               return new StringBuffer("Flow ").append(name).toString();
+       }
+
+       public boolean equals(Object obj) {
+               return ((ExecutionFlow) obj).getName().equals(name);
        }
 }
index 3399a78e731bbb9bc89b0ff94fd42d98e657aa87..d6d0518802182221301f1ee52f845170849b3504 100644 (file)
@@ -3,11 +3,14 @@ package org.argeo.slc.execution;
 import java.util.HashMap;
 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.framework.ProxyFactory;
 import org.springframework.beans.factory.BeanNameAware;
 
 public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
+       private final static Log log = LogFactory.getLog(SimpleExecutionSpec.class);
+
        private final static ThreadLocal<ExecutionFlow> initializingFlow = new ThreadLocal<ExecutionFlow>();
 
        private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
@@ -27,18 +30,17 @@ public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
                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(flow,
-                               targetClass, name);
-               ProxyFactory proxyFactory = new ProxyFactory();
-               proxyFactory.setTargetClass(targetClass);
-               proxyFactory.setProxyTargetClass(true);
-               proxyFactory.setTargetSource(targetSource);
-
-               return proxyFactory.getProxy();*/
+               /*
+                * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
+                * .get(name); 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();
+                */
                return flow.getParameter(name);
        }
 
@@ -50,17 +52,25 @@ public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
                return name;
        }
 
+       // FLOWS INITIALIZATION SUPPORT
+
        public static void flowInitializationStarted(ExecutionFlow flow) {
+               if (log.isTraceEnabled())
+                       log.trace("Start initialization of " + flow.hashCode() + " ("
+                                       + flow + " - " + flow.getClass() + ")");
                initializingFlow.set(flow);
        }
 
        public static void flowInitializationFinished(ExecutionFlow flow) {
+               if (log.isTraceEnabled())
+                       log.trace("Finish initialization of " + flow.hashCode() + " ("
+                                       + flow + " - " + flow.getClass() + ")");
                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);
+               if (registeredFlow != null) {
+                       if (!flow.getName().equals(registeredFlow.getName()))
+                               throw new SlcException("Current flow is " + flow);
+                       initializingFlow.set(null);
+               }
        }
 
        public static Object getInitializingFlowParameter(String key) {
@@ -72,4 +82,9 @@ public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
        public static Boolean isInFlowInitialization() {
                return initializingFlow.get() != null;
        }
+
+       public boolean equals(Object obj) {
+               return ((ExecutionSpec) obj).getName().equals(name);
+       }
+
 }