Merge pull request #96 from mminella/BATCH-1938

BATCH-1938: Updated 2.2 branch to support Spring 3.2.0.RELEASE
This commit is contained in:
Michael Minella
2012-12-20 14:00:56 -08:00
4 changed files with 50 additions and 19 deletions

View File

@@ -13,7 +13,7 @@
the project jar on the classpath and run the the project jar on the classpath and run the
CommandLineJobRunner directly or with "java -jar launch-context.xml job1".</description> CommandLineJobRunner directly or with "java -jar launch-context.xml job1".</description>
<properties> <properties>
<spring.framework.version>3.1.2.RELEASE</spring.framework.version> <spring.framework.version>3.2.0.RELEASE</spring.framework.version>
<spring.batch.version>2.2.0.BUILD-SNAPSHOT</spring.batch.version> <spring.batch.version>2.2.0.BUILD-SNAPSHOT</spring.batch.version>
<dependency.locations.enabled>false</dependency.locations.enabled> <dependency.locations.enabled>false</dependency.locations.enabled>
<junit.version>4.10</junit.version> <junit.version>4.10</junit.version>
@@ -154,7 +154,7 @@
</descriptorRefs> </descriptorRefs>
</configuration> </configuration>
</plugin> </plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings <!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. --> only. It has no influence on the Maven build itself. -->
<plugin> <plugin>
<groupId>org.eclipse.m2e</groupId> <groupId>org.eclipse.m2e</groupId>

View File

@@ -41,7 +41,9 @@
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId><artifactId>h2</artifactId><version>1.2.132</version> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.2.132</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>

View File

@@ -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;
@@ -56,9 +57,9 @@ import org.springframework.util.StringValueResolver;
* non-primitive values directly by making the whole bean property value into a * non-primitive values directly by making the whole bean property value into a
* placeholder (e.g. <code>value="%{foo}"</code> where <code>foo</code> is a * placeholder (e.g. <code>value="%{foo}"</code> where <code>foo</code> is a
* property in the context). * property in the context).
* *
* @author Dave Syer * @author Dave Syer
* *
*/ */
public class PlaceholderTargetSource extends SimpleBeanTargetSource implements InitializingBean { public class PlaceholderTargetSource extends SimpleBeanTargetSource implements InitializingBean {
@@ -76,7 +77,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
/** /**
* Public setter for the context factory. Used to construct the context root * Public setter for the context factory. Used to construct the context root
* whenever placeholders are replaced in a bean definition. * whenever placeholders are replaced in a bean definition.
* *
* @param contextFactory the {@link ContextFactory} * @param contextFactory the {@link ContextFactory}
*/ */
public void setContextFactory(ContextFactory contextFactory) { public void setContextFactory(ContextFactory contextFactory) {
@@ -85,10 +86,11 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @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();
@@ -96,7 +98,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.springframework.aop.target.LazyInitTargetSource#getTarget() * @see org.springframework.aop.target.LazyInitTargetSource#getTarget()
*/ */
@Override @Override
@@ -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
@@ -287,7 +314,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
* Determine whether the input is a whole key in the form * Determine whether the input is a whole key in the form
* <code>%{...}</code>, i.e. starting with the correct prefix, ending with * <code>%{...}</code>, i.e. starting with the correct prefix, ending with
* the correct suffix and containing only one of each. * the correct suffix and containing only one of each.
* *
* @param value a String with placeholder patterns * @param value a String with placeholder patterns
* @return true if the value is a key * @return true if the value is a key
*/ */
@@ -299,9 +326,9 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
/** /**
* A {@link BeanDefinitionVisitor} that will replace embedded placeholders * A {@link BeanDefinitionVisitor} that will replace embedded placeholders
* with values from the provided context. * with values from the provided context.
* *
* @author Dave Syer * @author Dave Syer
* *
*/ */
private final class PlaceholderBeanDefinitionVisitor extends BeanDefinitionVisitor { private final class PlaceholderBeanDefinitionVisitor extends BeanDefinitionVisitor {
@@ -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;
@@ -407,7 +436,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
/** /**
* Convenience method to replace all the placeholders in the input. * Convenience method to replace all the placeholders in the input.
* *
* @param typeConverter a {@link TypeConverter} that can be used to * @param typeConverter a {@link TypeConverter} that can be used to
* convert placeholder keys to context values * convert placeholder keys to context values
* @param value the value to replace placeholders in * @param value the value to replace placeholders in
@@ -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;

View File

@@ -29,7 +29,7 @@
</developer> </developer>
</developers> </developers>
<properties> <properties>
<spring.framework.version>3.1.2.RELEASE</spring.framework.version> <spring.framework.version>3.2.0.RELEASE</spring.framework.version>
<spring.amqp.version>1.1.2.RELEASE</spring.amqp.version> <spring.amqp.version>1.1.2.RELEASE</spring.amqp.version>
<junit.version>4.10</junit.version> <junit.version>4.10</junit.version>
<bundlor.version>1.0.0.RELEASE</bundlor.version> <bundlor.version>1.0.0.RELEASE</bundlor.version>