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