1 package org
.argeo
.slc
.execution
;
3 import java
.util
.HashMap
;
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
;
11 public class SimpleExecutionSpec
implements ExecutionSpec
, BeanNameAware
{
12 private final static Log log
= LogFactory
.getLog(SimpleExecutionSpec
.class);
14 private final static ThreadLocal
<ExecutionFlow
> initializingFlow
= new ThreadLocal
<ExecutionFlow
>();
16 private Map
<String
, ExecutionSpecAttribute
> attributes
= new HashMap
<String
, ExecutionSpecAttribute
>();
18 private String name
= null;
20 public Map
<String
, ExecutionSpecAttribute
> getAttributes() {
24 public void setAttributes(Map
<String
, ExecutionSpecAttribute
> attributes
) {
25 this.attributes
= attributes
;
28 public Object
createRef(String name
) {
29 ExecutionFlow flow
= initializingFlow
.get();
31 throw new SlcException("No flow is currently initializing."
32 + " Declare flow refs as inner beans or prototypes.");
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);
42 * return proxyFactory.getProxy();
44 return flow
.getParameter(name
);
47 public void setBeanName(String name
) {
51 public String
getName() {
55 // FLOWS INITIALIZATION SUPPORT
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
);
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);
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
);
82 public static Boolean
isInFlowInitialization() {
83 return initializingFlow
.get() != null;
86 public boolean equals(Object obj
) {
87 return ((ExecutionSpec
) obj
).getName().equals(name
);