]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionSpec.java
Data model for batch entry, spec editor basis.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / SimpleExecutionSpec.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.argeo.slc.SlcException;
9 import org.argeo.slc.execution.ExecutionFlow;
10 import org.argeo.slc.execution.ExecutionSpec;
11 import org.argeo.slc.execution.ExecutionSpecAttribute;
12 import org.springframework.beans.factory.BeanNameAware;
13
14 public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
15 private final static Log log = LogFactory.getLog(SimpleExecutionSpec.class);
16
17 private final static ThreadLocal<ExecutionFlow> initializingFlow = new ThreadLocal<ExecutionFlow>();
18
19 private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
20
21 private String name = null;
22
23 public Map<String, ExecutionSpecAttribute> getAttributes() {
24 return attributes;
25 }
26
27 public void setAttributes(Map<String, ExecutionSpecAttribute> attributes) {
28 this.attributes = attributes;
29 }
30
31 public Object createRef(String name) {
32 ExecutionFlow flow = initializingFlow.get();
33 if (flow == null)
34 throw new SlcException("No flow is currently initializing."
35 + " Declare flow refs as inner beans or prototypes.");
36 /*
37 * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
38 * .get(name); Class<?> targetClass = refSpecAttribute.getTargetClass();
39 * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow,
40 * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory();
41 * proxyFactory.setTargetClass(targetClass);
42 * proxyFactory.setProxyTargetClass(true);
43 * proxyFactory.setTargetSource(targetSource);
44 *
45 * return proxyFactory.getProxy();
46 */
47 return flow.getParameter(name);
48 }
49
50 public void setBeanName(String name) {
51 this.name = name;
52 }
53
54 public String getName() {
55 return name;
56 }
57
58 // FLOWS INITIALIZATION SUPPORT
59
60 public static void flowInitializationStarted(ExecutionFlow flow) {
61 if (log.isTraceEnabled())
62 log.trace("Start initialization of " + flow.hashCode() + " ("
63 + flow + " - " + flow.getClass() + ")");
64 initializingFlow.set(flow);
65 }
66
67 public static void flowInitializationFinished(ExecutionFlow flow) {
68 if (log.isTraceEnabled())
69 log.trace("Finish initialization of " + flow.hashCode() + " ("
70 + flow + " - " + flow.getClass() + ")");
71 ExecutionFlow registeredFlow = initializingFlow.get();
72 if (registeredFlow != null) {
73 if (!flow.getName().equals(registeredFlow.getName()))
74 throw new SlcException("Current flow is " + flow);
75 initializingFlow.set(null);
76 }
77 }
78
79 public static Object getInitializingFlowParameter(String key) {
80 if (initializingFlow.get() == null)
81 throw new SlcException("No initializing flow available.");
82 return initializingFlow.get().getParameter(key);
83 }
84
85 public static Boolean isInFlowInitialization() {
86 return initializingFlow.get() != null;
87 }
88
89 public boolean equals(Object obj) {
90 return ((ExecutionSpec) obj).getName().equals(name);
91 }
92
93 }