|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
package org.springframework.batch.core.scope.util;
|
|
|
|
package org.springframework.batch.core.scope.util;
|
|
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyEditor;
|
|
|
|
import java.beans.PropertyEditor;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
@@ -89,6 +90,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
* @see
|
|
|
|
* @see
|
|
|
|
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
|
|
|
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterPropertiesSet() {
|
|
|
|
public void afterPropertiesSet() {
|
|
|
|
Assert.notNull(contextFactory, "The ContextFactory must be set.");
|
|
|
|
Assert.notNull(contextFactory, "The ContextFactory must be set.");
|
|
|
|
beanName = getTargetBeanName() + "#" + contextFactory.getContextId();
|
|
|
|
beanName = getTargetBeanName() + "#" + contextFactory.getContextId();
|
|
|
|
@@ -116,9 +118,16 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
beanFactory.copyConfigurationFrom(listableBeanFactory);
|
|
|
|
beanFactory.copyConfigurationFrom(listableBeanFactory);
|
|
|
|
|
|
|
|
|
|
|
|
final TypeConverter contextTypeConverter = new TypeConverter() {
|
|
|
|
final TypeConverter contextTypeConverter = new TypeConverter() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
public Object convertIfNecessary(Object value, Class requiredType, MethodParameter methodParam)
|
|
|
|
public Object convertIfNecessary(Object value, Class requiredType, MethodParameter methodParam)
|
|
|
|
throws TypeMismatchException {
|
|
|
|
throws TypeMismatchException {
|
|
|
|
|
|
|
|
return doConvertIfNecessary(value, requiredType,
|
|
|
|
|
|
|
|
methodParam);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Object doConvertIfNecessary(Object value,
|
|
|
|
|
|
|
|
Class requiredType, Object param) {
|
|
|
|
Object result = null;
|
|
|
|
Object result = null;
|
|
|
|
if (value instanceof String) {
|
|
|
|
if (value instanceof String) {
|
|
|
|
String key = (String) value;
|
|
|
|
String key = (String) value;
|
|
|
|
@@ -155,12 +164,30 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
result = value.toString();
|
|
|
|
result = value.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result != null ? result : typeConverter.convertIfNecessary(value, requiredType, methodParam);
|
|
|
|
|
|
|
|
|
|
|
|
if(result != null) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(param instanceof Field) {
|
|
|
|
|
|
|
|
return typeConverter.convertIfNecessary(value, requiredType, (Field) param);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return typeConverter.convertIfNecessary(value, requiredType, (MethodParameter) param);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
public Object convertIfNecessary(Object value, Class requiredType) throws TypeMismatchException {
|
|
|
|
public Object convertIfNecessary(Object value, Class requiredType) throws TypeMismatchException {
|
|
|
|
return convertIfNecessary(value, requiredType, null);
|
|
|
|
return doConvertIfNecessary(value, requiredType, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Object convertIfNecessary(Object value,
|
|
|
|
|
|
|
|
Class requiredType, Field field)
|
|
|
|
|
|
|
|
throws TypeMismatchException {
|
|
|
|
|
|
|
|
return doConvertIfNecessary(value, requiredType,
|
|
|
|
|
|
|
|
field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
beanFactory.setTypeConverter(contextTypeConverter);
|
|
|
|
beanFactory.setTypeConverter(contextTypeConverter);
|
|
|
|
@@ -220,7 +247,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Give it one chance to convert - this forces the default editors
|
|
|
|
// Give it one chance to convert - this forces the default editors
|
|
|
|
// to be registered
|
|
|
|
// to be registered
|
|
|
|
result = (String) typeConverter.convertIfNecessary(value, String.class);
|
|
|
|
result = typeConverter.convertIfNecessary(value, String.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (TypeMismatchException e) {
|
|
|
|
catch (TypeMismatchException e) {
|
|
|
|
// ignore
|
|
|
|
// ignore
|
|
|
|
@@ -309,6 +336,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
super(new PlaceholderStringValueResolver(typeConverter));
|
|
|
|
super(new PlaceholderStringValueResolver(typeConverter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
protected Object resolveValue(Object value) {
|
|
|
|
protected Object resolveValue(Object value) {
|
|
|
|
|
|
|
|
|
|
|
|
@@ -367,14 +395,14 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
else if (value instanceof BeanDefinition) {
|
|
|
|
else if (value instanceof BeanDefinition) {
|
|
|
|
|
|
|
|
|
|
|
|
BeanDefinition newValue = new GenericBeanDefinition((BeanDefinition) value);
|
|
|
|
BeanDefinition newValue = new GenericBeanDefinition((BeanDefinition) value);
|
|
|
|
visitBeanDefinition((BeanDefinition) newValue);
|
|
|
|
visitBeanDefinition(newValue);
|
|
|
|
value = newValue;
|
|
|
|
value = newValue;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (value instanceof BeanDefinitionHolder) {
|
|
|
|
else if (value instanceof BeanDefinitionHolder) {
|
|
|
|
|
|
|
|
|
|
|
|
BeanDefinition newValue = new GenericBeanDefinition(((BeanDefinitionHolder) value).getBeanDefinition());
|
|
|
|
BeanDefinition newValue = new GenericBeanDefinition(((BeanDefinitionHolder) value).getBeanDefinition());
|
|
|
|
visitBeanDefinition((BeanDefinition) newValue);
|
|
|
|
visitBeanDefinition(newValue);
|
|
|
|
value = newValue;
|
|
|
|
value = newValue;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -398,6 +426,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
this.typeConverter = typeConverter;
|
|
|
|
this.typeConverter = typeConverter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String resolveStringValue(String strVal) {
|
|
|
|
public String resolveStringValue(String strVal) {
|
|
|
|
if (!strVal.contains(PLACEHOLDER_PREFIX)) {
|
|
|
|
if (!strVal.contains(PLACEHOLDER_PREFIX)) {
|
|
|
|
return strVal;
|
|
|
|
return strVal;
|
|
|
|
@@ -454,7 +483,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
|
|
|
Class<?> requiredType, TypeConverter typeConverter) {
|
|
|
|
Class<?> requiredType, TypeConverter typeConverter) {
|
|
|
|
Object property = convertFromContext(key, requiredType);
|
|
|
|
Object property = convertFromContext(key, requiredType);
|
|
|
|
if (property != null) {
|
|
|
|
if (property != null) {
|
|
|
|
result.replace(first, next + 1, (String) typeConverter.convertIfNecessary(property, String.class));
|
|
|
|
result.replace(first, next + 1, typeConverter.convertIfNecessary(property, String.class));
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|