1 package org
.argeo
.slc
.executionflow
;
3 import java
.beans
.PropertyDescriptor
;
4 import java
.util
.HashSet
;
6 import java
.util
.Properties
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.springframework
.beans
.BeansException
;
12 import org
.springframework
.beans
.PropertyValue
;
13 import org
.springframework
.beans
.PropertyValues
;
14 import org
.springframework
.beans
.factory
.config
.InstantiationAwareBeanPostProcessorAdapter
;
15 import org
.springframework
.beans
.factory
.config
.PropertyPlaceholderConfigurer
;
16 import org
.springframework
.beans
.factory
.config
.TypedStringValue
;
18 public class ExecutionParameterPostProcessor
extends
19 InstantiationAwareBeanPostProcessorAdapter
{
20 private final static Log log
= LogFactory
21 .getLog(ExecutionParameterPostProcessor
.class);
23 private String placeholderPrefix
= "@{";
24 private String placeholderSuffix
= "}";
25 private String nullValue
;
28 public PropertyValues
postProcessPropertyValues(PropertyValues pvs
,
29 PropertyDescriptor
[] pds
, Object bean
, String beanName
)
30 throws BeansException
{
31 if (!ExecutionContext
.isExecuting())
34 ExecutionFlow currentFlow
= ExecutionContext
.getCurrentFlow();
36 Properties props
= new Properties();
37 Map
<String
, Object
> attributes
= currentFlow
.getAttributes();
38 Map
<String
, ExecutionSpecAttribute
> specAttributes
= currentFlow
39 .getExecutionSpec().getAttributes();
41 for (String key
: specAttributes
.keySet()) {
42 ExecutionSpecAttribute obj
= specAttributes
.get(key
);
43 if (!(obj
instanceof RefSpecAttribute
)) {
44 if (!attributes
.containsKey(key
))
45 throw new SlcException("Specified attribute " + key
46 + " is not set in " + currentFlow
);
48 props
.setProperty(key
, attributes
.get(key
).toString());
49 // if (log.isTraceEnabled())
50 // log.trace("Use attribute " + key);
53 CustomPpc ppc
= new CustomPpc(props
);
55 for (PropertyValue pv
: pvs
.getPropertyValues()) {
56 if (pv
.getValue() instanceof TypedStringValue
) {
57 TypedStringValue tsv
= (TypedStringValue
) pv
.getValue();
58 String originalValue
= tsv
.getValue();
59 String convertedValue
= ppc
.process(originalValue
);
60 tsv
.setValue(convertedValue
);
61 if (log
.isTraceEnabled()) {
62 if (!originalValue
.equals(convertedValue
))
63 log
.trace("Converted field '" + pv
.getName() + "': '"
64 + originalValue
+ "' to '" + convertedValue
65 + "' in bean " + beanName
);
68 // if (log.isTraceEnabled())
69 // log.trace(beanName + "[" + pv.getName() + "]: "
70 // + pv.getValue().getClass());
77 public void setPlaceholderPrefix(String placeholderPrefix
) {
78 this.placeholderPrefix
= placeholderPrefix
;
81 public void setPlaceholderSuffix(String placeholderSuffix
) {
82 this.placeholderSuffix
= placeholderSuffix
;
85 public void setNullValue(String nullValue
) {
86 this.nullValue
= nullValue
;
89 private class CustomPpc
extends PropertyPlaceholderConfigurer
{
90 private final Properties props
;
92 public CustomPpc(Properties props
) {
95 setPlaceholderPrefix(placeholderPrefix
);
96 setPlaceholderSuffix(placeholderSuffix
);
97 setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER
);
100 public String
process(String strVal
) {
101 String value
= parseStringValue(strVal
, this.props
,
102 new HashSet
<String
>());
103 return (value
.equals(nullValue
) ?
null : value
);