From 3aa3bb941074268f09de6c61c1a400d702fabd2e Mon Sep 17 00:00:00 2001 From: Olivier Capillon Date: Sat, 21 Mar 2009 19:55:09 +0000 Subject: [PATCH] Placeholder resolution in Map, List and Set supported git-svn-id: https://svn.argeo.org/slc/trunk@2296 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../ExecutionParameterPostProcessor.java | 86 ++++-- .../slc/core/execution/ExecutionFlowTest.java | 31 +- .../argeo/slc/core/execution/listSetMap.xml | 292 ++++++++++++++++++ 3 files changed, 365 insertions(+), 44 deletions(-) create mode 100644 runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMap.xml diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java index 9cb694829..a76820465 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java @@ -4,8 +4,11 @@ import java.beans.PropertyDescriptor; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,7 +21,10 @@ import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.support.ManagedSet; +import org.springframework.util.ObjectUtils; public class ExecutionParameterPostProcessor extends InstantiationAwareBeanPostProcessorAdapter { @@ -67,6 +73,57 @@ public class ExecutionParameterPostProcessor extends else if (value instanceof String) { return ppc.process(value.toString()); } + else if (value instanceof Map) { + Map mapVal = (Map) value; + + Map newContent = new LinkedHashMap(); + boolean entriesModified = false; + for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = (Map.Entry) it.next(); + Object key = entry.getKey(); + int keyHash = (key != null ? key.hashCode() : 0); + Object newKey = resolveValue(key,ppc); + int newKeyHash = (newKey != null ? newKey.hashCode() : 0); + Object val = entry.getValue(); + Object newVal = resolveValue(val,ppc); + newContent.put(newKey, newVal); + entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash); + } + if (entriesModified) { + mapVal.clear(); + mapVal.putAll(newContent); + } + return mapVal; + } + else if (value instanceof List) { + List listVal = (List) value; + for (int i = 0; i < listVal.size(); i++) { + Object elem = listVal.get(i); + Object newVal = resolveValue(elem,ppc); + if (!ObjectUtils.nullSafeEquals(newVal, elem)) { + listVal.set(i, newVal); + } + } + return value; + } + else if (value instanceof Set) { + Set setVal = (Set) value; + Set newContent = new LinkedHashSet(); + boolean entriesModified = false; + for (Iterator it = setVal.iterator(); it.hasNext();) { + Object elem = it.next(); + int elemHash = (elem != null ? elem.hashCode() : 0); + Object newVal = resolveValue(elem,ppc); + int newValHash = (newVal != null ? newVal.hashCode() : 0); + newContent.add(newVal); + entriesModified = entriesModified || (newVal != elem || newValHash != elemHash); + } + if (entriesModified) { + setVal.clear(); + setVal.addAll(newContent); + } + return value; + } else { return value; } @@ -118,31 +175,10 @@ public class ExecutionParameterPostProcessor extends pv.setConvertedValue(convertedValue); } - else if (pv.getValue() instanceof ManagedMap) { - //debug - Object obj = pv.getValue(); - String name = pv.getName(); - -// log.info("##" + name + ":" + obj.getClass()); - ManagedMap mapVal = (ManagedMap) pv.getValue(); - - Map newContent = new LinkedHashMap(); - boolean entriesModified = false; - for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - Object key = entry.getKey(); - int keyHash = (key != null ? key.hashCode() : 0); - Object newKey = resolveValue(key,ppc); - int newKeyHash = (newKey != null ? newKey.hashCode() : 0); - Object val = entry.getValue(); - Object newVal = resolveValue(val,ppc); - newContent.put(newKey, newVal); - entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash); - } - if (entriesModified) { - mapVal.clear(); - mapVal.putAll(newContent); - } + else if ((pv.getValue() instanceof ManagedMap) + ||(pv.getValue() instanceof ManagedList) + ||(pv.getValue() instanceof ManagedSet)){ + resolveValue(pv.getValue(),ppc); } if (convertedValue != null && log.isTraceEnabled()) { diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java index 2692ef99f..d3030e95f 100644 --- a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java +++ b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java @@ -21,21 +21,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class ExecutionFlowTest extends TestCase { protected final Log log = LogFactory.getLog(getClass()); - - - public void testRecursive() throws Exception { - ConfigurableApplicationContext applicationContext = createApplicationContext("test.xml"); - ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("second"); - executionFlow.execute(); - - BasicTestData res = (BasicTestData) applicationContext.getBean("basic.testData"); - - log.info("res=" + res.getReached().toString()); - applicationContext.close(); - } - - /** * Test placeholder resolution in a context without scope execution or proxy * and with cascading flows (the flow A contains the flow B) @@ -92,10 +78,6 @@ public class ExecutionFlowTest extends TestCase { applicationContext.close(); } - public void testSimpleExecution() throws Exception { -// configureAndExecuteSlcFlow("applicationContext.xml", "main"); - } - public void testCanonicFlowParameters() throws Exception { configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001"); } @@ -123,7 +105,18 @@ public class ExecutionFlowTest extends TestCase { } } - + public void testListSetMap() throws Exception { + ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml"); + ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("myFlow"); + executionFlow.execute(); + + validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult")); + + BasicTestData res = (BasicTestData) applicationContext.getBean("cascadingComplex.testData"); + log.info("res=" + res.getReached().toString()); + + applicationContext.close(); + } protected void logException(Throwable ex) { diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMap.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMap.xml new file mode 100644 index 000000000..4f22d2763 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMap.xml @@ -0,0 +1,292 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + myValue + _myValue_ + + + + + @{testKey} + _@{testKey}_ + + + + + + + + + myValue + _myValue_ + + myValue + + + + + + @{testKey} + _@{testKey}_ + + @{testKey} + + + + + + + + myValue + _myValue_ + + + + + @{testKey} + _@{testKey}_ + + + + + + + + + myValue + _myValue_ + + myValue + + + + + + @{testKey} + _@{testKey}_ + + @{testKey} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + myValue + _myValue_ + + + myValue + _myValue_ + + myValue + + + myValue + + + + + + + + + + + + + + + + + + + + + @{testKey} + _@{testKey}_ + + + @{testKey} + _@{testKey}_ + + @{testKey} + + + @{testKey} + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.39.2