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