1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.ArrayList
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
9 import org
.argeo
.slc
.execution
.RefSpecAttribute
;
10 import org
.argeo
.slc
.execution
.RefValueChoice
;
11 import org
.springframework
.beans
.factory
.BeanNameAware
;
12 import org
.springframework
.beans
.factory
.InitializingBean
;
13 import org
.springframework
.beans
.factory
.NoSuchBeanDefinitionException
;
14 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
15 import org
.springframework
.beans
.factory
.config
.ConfigurableListableBeanFactory
;
16 import org
.springframework
.context
.ApplicationContext
;
17 import org
.springframework
.context
.ApplicationContextAware
;
18 import org
.springframework
.context
.ConfigurableApplicationContext
;
20 /** Spring based implementation of execution specifications. */
22 public class DefaultExecutionSpec
extends org
.argeo
.slc
.runtime
.DefaultExecutionSpec
23 implements BeanNameAware
, ApplicationContextAware
, InitializingBean
{
24 private static final long serialVersionUID
= 5159882223926926539L;
25 private final static Log log
= LogFactory
.getLog(DefaultExecutionSpec
.class);
26 private transient ApplicationContext applicationContext
;
28 public DefaultExecutionSpec() {
32 public void setBeanName(String name
) {
36 private ConfigurableListableBeanFactory
getBeanFactory() {
37 return ((ConfigurableApplicationContext
) applicationContext
).getBeanFactory();
40 public void setApplicationContext(ApplicationContext applicationContext
) {
41 this.applicationContext
= applicationContext
;
44 public void afterPropertiesSet() throws Exception
{
45 if (getDescription() == null) {
47 setDescription(getBeanFactory().getBeanDefinition(getName()).getDescription());
48 } catch (NoSuchBeanDefinitionException e
) {
53 for (String key
: getAttributes().keySet()) {
54 ExecutionSpecAttribute attr
= getAttributes().get(key
);
55 if (attr
instanceof RefSpecAttribute
) {
56 RefSpecAttribute rsa
= (RefSpecAttribute
) attr
;
57 if (rsa
.getChoices() == null) {
58 List
<RefValueChoice
> choices
= buildRefValueChoices(rsa
);
59 rsa
.setChoices(choices
);
61 if (log
.isTraceEnabled())
62 log
.debug("Spec attr " + key
+ " has " + rsa
.getChoices().size() + " choices");
68 * Generates a list of ref value choices based on the bean available in the
69 * application context.
71 protected List
<RefValueChoice
> buildRefValueChoices(RefSpecAttribute rsa
) {
72 List
<RefValueChoice
> choices
= new ArrayList
<RefValueChoice
>();
73 if (applicationContext
== null) {
74 log
.warn("No application context declared," + " cannot scan ref value choices.");
78 beanNames
: for (String beanName
: getBeanFactory().getBeanNamesForType(rsa
.getTargetClass(), true, false)) {
80 // Since Spring 3, systemProperties is implicitly defined but has no
82 if (beanName
.equals("systemProperties"))
85 BeanDefinition bd
= getBeanFactory().getBeanDefinition(beanName
);
86 RefValueChoice choice
= new RefValueChoice();
87 choice
.setName(beanName
);
88 choice
.setDescription(bd
.getDescription());
89 if (log
.isTraceEnabled())
90 log
.debug("Found choice " + beanName
+ " for " + rsa
);