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 ExecutionFlow currentFlow
= ExecutionContext
.getCurrentFlow();
32 if (currentFlow
== null)
35 Properties props
= new Properties();
36 Map
<String
, Object
> attributes
= currentFlow
.getAttributes();
37 Map
<String
, ExecutionSpecAttribute
> specAttributes
= currentFlow
38 .getExecutionSpec().getAttributes();
40 for (String key
: specAttributes
.keySet()) {
41 ExecutionSpecAttribute obj
= specAttributes
.get(key
);
42 if (!(obj
instanceof RefSpecAttribute
)) {
43 if (!attributes
.containsKey(key
))
44 throw new SlcException("Specified attribute " + key
45 + " is not set in " + currentFlow
);
47 props
.setProperty(key
, attributes
.get(key
).toString());
48 // if (log.isTraceEnabled())
49 // log.trace("Use attribute " + key);
52 CustomPpc ppc
= new CustomPpc(props
);
54 for (PropertyValue pv
: pvs
.getPropertyValues()) {
55 if (pv
.getValue() instanceof TypedStringValue
) {
56 TypedStringValue tsv
= (TypedStringValue
) pv
.getValue();
57 String originalValue
= tsv
.getValue();
58 String convertedValue
= ppc
.process(originalValue
);
59 tsv
.setValue(convertedValue
);
60 if (log
.isTraceEnabled()) {
61 if (!originalValue
.equals(convertedValue
))
62 log
.trace("Converted " + beanName
+ "[" + pv
.getName()
63 + "]: " + originalValue
+ " to "
67 // if (log.isTraceEnabled())
68 // log.trace(beanName + "[" + pv.getName() + "]: "
69 // + pv.getValue().getClass());
76 public void setPlaceholderPrefix(String placeholderPrefix
) {
77 this.placeholderPrefix
= placeholderPrefix
;
80 public void setPlaceholderSuffix(String placeholderSuffix
) {
81 this.placeholderSuffix
= placeholderSuffix
;
84 public void setNullValue(String nullValue
) {
85 this.nullValue
= nullValue
;
88 private class CustomPpc
extends PropertyPlaceholderConfigurer
{
89 private final Properties props
;
91 public CustomPpc(Properties props
) {
94 setPlaceholderPrefix(placeholderPrefix
);
95 setPlaceholderSuffix(placeholderSuffix
);
96 setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER
);
99 public String
process(String strVal
) {
100 String value
= parseStringValue(strVal
, this.props
, new HashSet
<String
>());
101 return (value
.equals(nullValue
) ?
null : value
);