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