]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java
Fix issue with parameters
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / ExecutionParameterPostProcessor.java
index e39e9fab78aec4798477daf7e707400111f6dc74..5a00ed5aca89e01666546c3e907b04a5fa605910 100644 (file)
@@ -18,21 +18,22 @@ import org.springframework.beans.factory.config.TypedStringValue;
 
 public class ExecutionParameterPostProcessor extends
                InstantiationAwareBeanPostProcessorAdapter {
-       
+
        private final static Log log = LogFactory
                        .getLog(ExecutionParameterPostProcessor.class);
 
        private ExecutionContext executionContext;
-       
+
        private ExecutionScope executionScope;
-       
+
        private InstantiationManager instantiationManager;
-       
+
        public InstantiationManager getInstantiationManager() {
                return instantiationManager;
        }
 
-       public void setInstantiationManager(InstantiationManager instantiationManager) {
+       public void setInstantiationManager(
+                       InstantiationManager instantiationManager) {
                this.instantiationManager = instantiationManager;
        }
 
@@ -56,24 +57,24 @@ public class ExecutionParameterPostProcessor extends
        public PropertyValues postProcessPropertyValues(PropertyValues pvs,
                        PropertyDescriptor[] pds, Object bean, String beanName)
                        throws BeansException {
-               
-               
-//             boolean inFlowInitialization = DefaultExecutionSpec.isInFlowInitialization();
-                               
+
+//             boolean inFlowInitialization = instantiationManager
+//                             .isInFlowInitialization();
+//
 //             if (((executionScope == null) || (!executionScope.hasExecutionContext()))
 //                             && !inFlowInitialization) {
-//                     //log.info("Skip parameter conversion for bean " + beanName);
+//                     // log.info("Skip parameter conversion for bean " + beanName);
 //                     return pvs;
 //             } else {
-//                     //log.info("Execute parameter conversion for bean " + beanName);
+//                     // log.info("Execute parameter conversion for bean " + beanName);
 //             }
 
                Properties props = new Properties();
                CustomPpc ppc = new CustomPpc(props);
 
                for (PropertyValue pv : pvs.getPropertyValues()) {
-//                     log.info("   PropertyValue pv " + pv.getValue() + " - "
-//                                     + pv.getValue().getClass());
+                       // log.info("   PropertyValue pv " + pv.getValue() + " - "
+                       // + pv.getValue().getClass());
                        String originalValue = null;
                        String convertedValue = null;
                        if (pv.getValue() instanceof TypedStringValue) {
@@ -84,7 +85,8 @@ public class ExecutionParameterPostProcessor extends
                        } else if (pv.getValue() instanceof String) {
                                originalValue = pv.getValue().toString();
                                convertedValue = ppc.process(originalValue);
-                               pv.setConvertedValue(convertedValue);
+                               if (!convertedValue.equals(originalValue))
+                                       pv.setConvertedValue(convertedValue);
                        }
                        if (convertedValue != null && log.isTraceEnabled()) {
                                if (!originalValue.equals(convertedValue))
@@ -120,6 +122,7 @@ public class ExecutionParameterPostProcessor extends
                        setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER);
                }
 
+               /** Public access to the internals of PropertyPlaceholderConfigurer*/
                public String process(String strVal) {
                        String value = parseStringValue(strVal, this.props,
                                        new HashSet<String>());
@@ -128,27 +131,15 @@ public class ExecutionParameterPostProcessor extends
 
                @Override
                protected String resolvePlaceholder(String placeholder, Properties props) {
-                       if ((executionScope != null) && (executionScope.hasExecutionContext())) {
-                               // if we have an execution context, look there for the placeholder
+                       // log.info("Try convert placeholder " + placeholder);
+                       if ((executionScope != null)
+                                       && (executionScope.hasExecutionContext()))
                                return executionContext.getVariable(placeholder).toString();
-                       }
-                       else {
-                               // TODO: check scope of the bean
-                               // throw exception if trying to resolve placeholder on bean of scope singleton 
-                               
-                               if (instantiationManager.isInFlowInitialization()) {
-                                       String resolved = instantiationManager.getInitializingFlowParameter(
-                                                       placeholder).toString();
-//                                     log.info("Initialization placeholder resolution " + placeholder 
-//                                                     + ">>" + resolved);
-                                       return resolved;
-                               }
-                               else {
-       //                              return super.resolvePlaceholder(placeholder, props);
-                                       throw new SlcException("Placeholder '" + placeholder 
-                                                       + "' can not be resolved outside of Flow Initialization or Flow Execution.");
-                               }
-                       }
+                       else if (instantiationManager.isInFlowInitialization())
+                               return instantiationManager.getInitializingFlowParameter(
+                                               placeholder).toString();
+                       else
+                               return super.resolvePlaceholder(placeholder, props);
                }
        }
 }