1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.execution
.ExecutionSpec
;
12 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
13 import org
.springframework
.beans
.factory
.BeanNameAware
;
14 import org
.springframework
.beans
.factory
.InitializingBean
;
15 import org
.springframework
.beans
.factory
.NoSuchBeanDefinitionException
;
16 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
17 import org
.springframework
.beans
.factory
.config
.ConfigurableListableBeanFactory
;
18 import org
.springframework
.context
.ApplicationContext
;
19 import org
.springframework
.context
.ApplicationContextAware
;
20 import org
.springframework
.context
.ConfigurableApplicationContext
;
22 public class DefaultExecutionSpec
implements ExecutionSpec
, BeanNameAware
,
23 ApplicationContextAware
, InitializingBean
{
24 private final static Log log
= LogFactory
25 .getLog(DefaultExecutionSpec
.class);
26 private ApplicationContext applicationContext
;
28 private String description
;
29 private Map
<String
, ExecutionSpecAttribute
> attributes
= new HashMap
<String
, ExecutionSpecAttribute
>();
31 private String name
= getClass().getName() + "#" + UUID
.randomUUID();
33 public Map
<String
, ExecutionSpecAttribute
> getAttributes() {
37 public void setAttributes(Map
<String
, ExecutionSpecAttribute
> attributes
) {
38 this.attributes
= attributes
;
41 public void setBeanName(String name
) {
45 public String
getName() {
49 public boolean equals(Object obj
) {
50 return ((ExecutionSpec
) obj
).getName().equals(name
);
53 public String
getDescription() {
57 private ConfigurableListableBeanFactory
getBeanFactory() {
58 return ((ConfigurableApplicationContext
) applicationContext
)
62 public void setApplicationContext(ApplicationContext applicationContext
) {
63 this.applicationContext
= applicationContext
;
66 public void afterPropertiesSet() throws Exception
{
67 if (description
== null) {
69 description
= getBeanFactory().getBeanDefinition(name
)
71 } catch (NoSuchBeanDefinitionException e
) {
76 for (String key
: attributes
.keySet()) {
77 ExecutionSpecAttribute attr
= attributes
.get(key
);
78 if (attr
instanceof RefSpecAttribute
) {
79 RefSpecAttribute rsa
= (RefSpecAttribute
) attr
;
80 if (rsa
.getChoices() == null) {
81 List
<RefValueChoice
> choices
= buildRefValueChoices(rsa
);
82 if (log
.isTraceEnabled())
83 log
.debug("Found " + choices
.size() + " choices for "
84 + rsa
+ " in spec " + name
);
86 rsa
.setChoices(choices
);
92 protected List
<RefValueChoice
> buildRefValueChoices(RefSpecAttribute rsa
) {
93 List
<RefValueChoice
> choices
= new ArrayList
<RefValueChoice
>();
94 if (applicationContext
== null) {
95 log
.warn("No application context declared,"
96 + " cannot scan ref value choices.");
100 for (String beanName
: getBeanFactory().getBeanNamesForType(
101 rsa
.getTargetClass(), true, false)) {
102 BeanDefinition bd
= getBeanFactory().getBeanDefinition(beanName
);
103 RefValueChoice choice
= new RefValueChoice();
104 choice
.setName(beanName
);
105 choice
.setDescription(bd
.getDescription());
106 if (log
.isTraceEnabled())
107 log
.debug("Found choice " + beanName
+ " for " + rsa
);