]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java
Ignore files
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / ExecutionParameterPostProcessor.java
index e56bfd388fd2cb76f7a05f4db53572e4acda01da..1365e6bc67a9cab9ce1b4c388ce520011b738544 100644 (file)
@@ -1,3 +1,18 @@
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
 package org.argeo.slc.core.execution;\r
 \r
 import java.beans.PropertyDescriptor;\r
@@ -25,6 +40,12 @@ import org.springframework.beans.factory.support.ManagedSet;
 import org.springframework.util.ObjectUtils;\r
 import org.springframework.util.StringUtils;\r
 \r
+/**\r
+ * Spring post processor which ensures that execution parameters are properly\r
+ * set. It is used at two levels: first during instantiation for instantiation\r
+ * parameters which allow to implement templates, then at runtime in order to\r
+ * interpret @{} placeholders when object of scope execution are instantiated.\r
+ */\r
 public class ExecutionParameterPostProcessor extends\r
                InstantiationAwareBeanPostProcessorAdapter {\r
 \r
@@ -86,7 +107,7 @@ public class ExecutionParameterPostProcessor extends
                                        placeholder).toString();\r
 \r
                else {// execution\r
-                       // next call fail if no execution context available\r
+                               // next call fail if no execution context available\r
                        Object obj = executionContext.getVariable(placeholder);\r
                        if (obj != null) {\r
                                return obj.toString();\r
@@ -103,20 +124,24 @@ public class ExecutionParameterPostProcessor extends
                        String originalValue = tsv.getValue();\r
 \r
                        String convertedValue = resolveString(beanName, bean, originalValue);\r
+                       if (convertedValue == null)\r
+                               return null;\r
                        return convertedValue.equals(originalValue) ? value\r
                                        : new TypedStringValue(convertedValue);\r
                } else if (value instanceof String) {\r
                        String originalValue = value.toString();\r
                        String convertedValue = resolveString(beanName, bean, originalValue);\r
+                       if (convertedValue == null)\r
+                               return null;\r
                        return convertedValue.equals(originalValue) ? value\r
                                        : convertedValue;\r
                } else if (value instanceof ManagedMap) {\r
-                       Map mapVal = (Map) value;\r
+                       Map<?, ?> mapVal = (Map<?, ?>) value;\r
 \r
-                       Map newContent = new ManagedMap();\r
+                       Map<Object, Object> newContent = new ManagedMap();\r
                        boolean entriesModified = false;\r
-                       for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) {\r
-                               Map.Entry entry = (Map.Entry) it.next();\r
+                       for (Iterator<?> it = mapVal.entrySet().iterator(); it.hasNext();) {\r
+                               Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();\r
                                Object key = entry.getKey();\r
                                int keyHash = (key != null ? key.hashCode() : 0);\r
                                Object newKey = resolveValue(beanName, bean, key);\r
@@ -130,8 +155,8 @@ public class ExecutionParameterPostProcessor extends
 \r
                        return entriesModified ? newContent : value;\r
                } else if (value instanceof ManagedList) {\r
-                       List listVal = (List) value;\r
-                       List newContent = new ManagedList();\r
+                       List<?> listVal = (List<?>) value;\r
+                       List<Object> newContent = new ManagedList();\r
                        boolean valueModified = false;\r
 \r
                        for (int i = 0; i < listVal.size(); i++) {\r
@@ -144,10 +169,10 @@ public class ExecutionParameterPostProcessor extends
                        }\r
                        return valueModified ? newContent : value;\r
                } else if (value instanceof ManagedSet) {\r
-                       Set setVal = (Set) value;\r
-                       Set newContent = new ManagedSet();\r
+                       Set<?> setVal = (Set<?>) value;\r
+                       Set<Object> newContent = new ManagedSet();\r
                        boolean entriesModified = false;\r
-                       for (Iterator it = setVal.iterator(); it.hasNext();) {\r
+                       for (Iterator<?> it = setVal.iterator(); it.hasNext();) {\r
                                Object elem = it.next();\r
                                int elemHash = (elem != null ? elem.hashCode() : 0);\r
                                Object newVal = resolveValue(beanName, bean, elem);\r
@@ -165,6 +190,10 @@ public class ExecutionParameterPostProcessor extends
        }\r
 \r
        private String resolveString(String beanName, Object bean, String strVal) {\r
+               // in case <null/> is passed\r
+               if (strVal == null)\r
+                       return null;\r
+\r
                String value = parseStringValue(bean, strVal, new HashSet<String>());\r
 \r
                if (value == null)\r
@@ -204,6 +233,10 @@ public class ExecutionParameterPostProcessor extends
                        Set<String> visitedPlaceholders)\r
                        throws BeanDefinitionStoreException {\r
 \r
+               // in case <null/> is passed\r
+               if (strVal == null)\r
+                       return null;\r
+\r
                StringBuffer buf = new StringBuffer(strVal);\r
 \r
                int startIndex = strVal.indexOf(placeholderPrefix);\r
@@ -229,8 +262,8 @@ public class ExecutionParameterPostProcessor extends
                                        // previously resolved placeholder value.\r
                                        propVal = parseStringValue(bean, propVal,\r
                                                        visitedPlaceholders);\r
-                                       buf.replace(startIndex, endIndex\r
-                                                       + placeholderSuffix.length(), propVal);\r
+                                       buf.replace(startIndex,\r
+                                                       endIndex + placeholderSuffix.length(), propVal);\r
                                        if (log.isTraceEnabled()) {\r
                                                log.trace("Resolved placeholder '" + placeholder + "'");\r
                                        }\r