Cleanup of remaining direct BeanWrapper usage
Issue: SPR-14121
(cherry picked from commit 157dcab)
This commit is contained in:
parent
7659101843
commit
0864834077
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -87,10 +87,10 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private int autoGrowCollectionLimit = Integer.MAX_VALUE;
|
||||
|
||||
/** The wrapped object */
|
||||
private Object object;
|
||||
private Object wrappedObject;
|
||||
|
||||
private String nestedPath = "";
|
||||
|
||||
|
|
@ -204,23 +204,23 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
|
||||
Assert.notNull(object, "Target object must not be null");
|
||||
if (object.getClass() == javaUtilOptionalClass) {
|
||||
this.object = OptionalUnwrapper.unwrap(object);
|
||||
this.wrappedObject = OptionalUnwrapper.unwrap(object);
|
||||
}
|
||||
else {
|
||||
this.object = object;
|
||||
this.wrappedObject = object;
|
||||
}
|
||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||
this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.object);
|
||||
this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.wrappedObject);
|
||||
this.nestedPropertyAccessors = null;
|
||||
this.typeConverterDelegate = new TypeConverterDelegate(this, this.object);
|
||||
this.typeConverterDelegate = new TypeConverterDelegate(this, this.wrappedObject);
|
||||
}
|
||||
|
||||
public final Object getWrappedInstance() {
|
||||
return this.object;
|
||||
return this.wrappedObject;
|
||||
}
|
||||
|
||||
public final Class<?> getWrappedClass() {
|
||||
return (this.object != null ? this.object.getClass() : null);
|
||||
return (this.wrappedObject != null ? this.wrappedObject.getClass() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -303,7 +303,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
catch (NotReadablePropertyException ex) {
|
||||
throw new NotWritablePropertyException(getRootClass(), this.nestedPath + propertyName,
|
||||
"Cannot access indexed value in property referenced " +
|
||||
"in indexed property path '" + propertyName + "'", ex);
|
||||
"in indexed property path '" + propertyName + "'", ex);
|
||||
}
|
||||
// Set value for last key.
|
||||
String key = tokens.keys[tokens.keys.length - 1];
|
||||
|
|
@ -318,7 +318,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
else {
|
||||
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
|
||||
"Cannot access indexed value in property referenced " +
|
||||
"in indexed property path '" + propertyName + "': returned null");
|
||||
"in indexed property path '" + propertyName + "': returned null");
|
||||
}
|
||||
}
|
||||
if (propValue.getClass().isArray()) {
|
||||
|
|
@ -367,8 +367,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
catch (NullPointerException ex) {
|
||||
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
|
||||
"Cannot set element with index " + index + " in List of size " +
|
||||
size + ", accessed using property path '" + propertyName +
|
||||
"': List does not support filling up gaps with null elements");
|
||||
size + ", accessed using property path '" + propertyName +
|
||||
"': List does not support filling up gaps with null elements");
|
||||
}
|
||||
}
|
||||
list.add(convertedValue);
|
||||
|
|
@ -405,7 +405,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
else {
|
||||
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
|
||||
"Property referenced in indexed property path '" + propertyName +
|
||||
"' is neither an array nor a List nor a Map; returned value was [" + propValue + "]");
|
||||
"' is neither an array nor a List nor a Map; returned value was [" + propValue + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -451,7 +451,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
|
||||
}
|
||||
ph.setValue(object, valueToApply);
|
||||
ph.setValue(this.wrappedObject, valueToApply);
|
||||
}
|
||||
catch (TypeMismatchException ex) {
|
||||
throw ex;
|
||||
|
|
@ -953,10 +953,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
tokens.actualName = (actualName != null ? actualName : propertyName);
|
||||
tokens.canonicalName = tokens.actualName;
|
||||
if (!keys.isEmpty()) {
|
||||
tokens.canonicalName +=
|
||||
PROPERTY_KEY_PREFIX +
|
||||
StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX) +
|
||||
PROPERTY_KEY_SUFFIX;
|
||||
tokens.canonicalName += PROPERTY_KEY_PREFIX +
|
||||
StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX) +
|
||||
PROPERTY_KEY_SUFFIX;
|
||||
tokens.keys = StringUtils.toStringArray(keys);
|
||||
}
|
||||
return tokens;
|
||||
|
|
@ -965,8 +964,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
if (this.object != null) {
|
||||
sb.append(": wrapping object [").append(ObjectUtils.identityToString(this.object)).append("]");
|
||||
if (this.wrappedObject != null) {
|
||||
sb.append(": wrapping object [").append(ObjectUtils.identityToString(this.wrappedObject)).append("]");
|
||||
}
|
||||
else {
|
||||
sb.append(": no wrapped object set");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -48,6 +48,19 @@ import java.beans.PropertyDescriptor;
|
|||
*/
|
||||
public interface BeanWrapper extends ConfigurablePropertyAccessor {
|
||||
|
||||
/**
|
||||
* Specify a limit for array and collection auto-growing.
|
||||
* <p>Default is unlimited on a plain BeanWrapper.
|
||||
* @since 4.1
|
||||
*/
|
||||
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
|
||||
|
||||
/**
|
||||
* Return the limit for array and collection auto-growing.
|
||||
* @since 4.1
|
||||
*/
|
||||
int getAutoGrowCollectionLimit();
|
||||
|
||||
/**
|
||||
* Return the bean instance wrapped by this object, if any.
|
||||
* @return the bean instance, or {@code null} if none set
|
||||
|
|
@ -78,15 +91,4 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
|
|||
*/
|
||||
PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException;
|
||||
|
||||
/**
|
||||
* Specify a limit for array and collection auto-growing.
|
||||
* <p>Default is unlimited on a plain BeanWrapper.
|
||||
*/
|
||||
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
|
||||
|
||||
/**
|
||||
* Return the limit for array and collection auto-growing.
|
||||
*/
|
||||
int getAutoGrowCollectionLimit();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -136,7 +136,30 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
@Override
|
||||
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
|
||||
super.setWrappedInstance(object, nestedPath, rootObject);
|
||||
setIntrospectionClass(getWrappedInstance().getClass());
|
||||
setIntrospectionClass(getWrappedClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class to introspect.
|
||||
* Needs to be called when the target object changes.
|
||||
* @param clazz the class to introspect
|
||||
*/
|
||||
protected void setIntrospectionClass(Class<?> clazz) {
|
||||
if (this.cachedIntrospectionResults != null && this.cachedIntrospectionResults.getBeanClass() != clazz) {
|
||||
this.cachedIntrospectionResults = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a lazily initializted CachedIntrospectionResults instance
|
||||
* for the wrapped object.
|
||||
*/
|
||||
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
||||
Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
|
||||
if (this.cachedIntrospectionResults == null) {
|
||||
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
||||
}
|
||||
return this.cachedIntrospectionResults;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,30 +178,6 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
return this.acc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class to introspect.
|
||||
* Needs to be called when the target object changes.
|
||||
* @param clazz the class to introspect
|
||||
*/
|
||||
protected void setIntrospectionClass(Class<?> clazz) {
|
||||
if (this.cachedIntrospectionResults != null &&
|
||||
!clazz.equals(this.cachedIntrospectionResults.getBeanClass())) {
|
||||
this.cachedIntrospectionResults = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a lazily initializted CachedIntrospectionResults instance
|
||||
* for the wrapped object.
|
||||
*/
|
||||
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
||||
Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
|
||||
if (this.cachedIntrospectionResults == null) {
|
||||
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
||||
}
|
||||
return this.cachedIntrospectionResults;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the given value for the specified property to the latter's type.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -72,8 +72,8 @@ public class SpringBeanJobFactory extends AdaptableJobFactory implements Schedul
|
|||
@Override
|
||||
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||
Object job = super.createJobInstance(bundle);
|
||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
|
||||
if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
|
||||
if (isEligibleForPropertyPopulation(job)) {
|
||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
if (this.schedulerContext != null) {
|
||||
pvs.addPropertyValues(this.schedulerContext);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -61,9 +61,6 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
|
|||
return;
|
||||
}
|
||||
String prefix = "java.util.concurrent.ThreadPoolExecutor.";
|
||||
if (builder.getRawBeanDefinition().getBeanClassName().contains("backport")) {
|
||||
prefix = "edu.emory.mathcs.backport." + prefix;
|
||||
}
|
||||
String policyClassName;
|
||||
if (rejectionPolicy.equals("ABORT")) {
|
||||
policyClassName = prefix + "AbortPolicy";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.scheduling.config;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
|
@ -27,8 +27,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating ThreadPoolTaskExecutor instances, choosing
|
||||
* between the standard concurrent and the backport-concurrent variant.
|
||||
* {@link FactoryBean} for creating {@link ThreadPoolTaskExecutor} instances,
|
||||
* primarily used behind the XML task namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -41,13 +41,13 @@ public class TaskExecutorFactoryBean implements
|
|||
|
||||
private Integer queueCapacity;
|
||||
|
||||
private Object rejectedExecutionHandler;
|
||||
private RejectedExecutionHandler rejectedExecutionHandler;
|
||||
|
||||
private Integer keepAliveSeconds;
|
||||
|
||||
private String beanName;
|
||||
|
||||
private TaskExecutor target;
|
||||
private ThreadPoolTaskExecutor target;
|
||||
|
||||
|
||||
public void setPoolSize(String poolSize) {
|
||||
|
|
@ -58,7 +58,7 @@ public class TaskExecutorFactoryBean implements
|
|||
this.queueCapacity = queueCapacity;
|
||||
}
|
||||
|
||||
public void setRejectedExecutionHandler(Object rejectedExecutionHandler) {
|
||||
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
|
||||
this.rejectedExecutionHandler = rejectedExecutionHandler;
|
||||
}
|
||||
|
||||
|
|
@ -73,28 +73,25 @@ public class TaskExecutorFactoryBean implements
|
|||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
BeanWrapper bw = new BeanWrapperImpl(ThreadPoolTaskExecutor.class);
|
||||
determinePoolSizeRange(bw);
|
||||
public void afterPropertiesSet() {
|
||||
this.target = new ThreadPoolTaskExecutor();
|
||||
determinePoolSizeRange();
|
||||
if (this.queueCapacity != null) {
|
||||
bw.setPropertyValue("queueCapacity", this.queueCapacity);
|
||||
this.target.setQueueCapacity(this.queueCapacity);
|
||||
}
|
||||
if (this.keepAliveSeconds != null) {
|
||||
bw.setPropertyValue("keepAliveSeconds", this.keepAliveSeconds);
|
||||
this.target.setKeepAliveSeconds(this.keepAliveSeconds);
|
||||
}
|
||||
if (this.rejectedExecutionHandler != null) {
|
||||
bw.setPropertyValue("rejectedExecutionHandler", this.rejectedExecutionHandler);
|
||||
this.target.setRejectedExecutionHandler(this.rejectedExecutionHandler);
|
||||
}
|
||||
if (this.beanName != null) {
|
||||
bw.setPropertyValue("threadNamePrefix", this.beanName + "-");
|
||||
}
|
||||
this.target = (TaskExecutor) bw.getWrappedInstance();
|
||||
if (this.target instanceof InitializingBean) {
|
||||
((InitializingBean) this.target).afterPropertiesSet();
|
||||
this.target.setThreadNamePrefix(this.beanName + "-");
|
||||
}
|
||||
this.target.afterPropertiesSet();
|
||||
}
|
||||
|
||||
private void determinePoolSizeRange(BeanWrapper bw) {
|
||||
private void determinePoolSizeRange() {
|
||||
if (StringUtils.hasText(this.poolSize)) {
|
||||
try {
|
||||
int corePoolSize;
|
||||
|
|
@ -108,15 +105,15 @@ public class TaskExecutorFactoryBean implements
|
|||
"Lower bound of pool-size range must not exceed the upper bound");
|
||||
}
|
||||
if (this.queueCapacity == null) {
|
||||
// no queue-capacity provided, so unbounded
|
||||
// No queue-capacity provided, so unbounded
|
||||
if (corePoolSize == 0) {
|
||||
// actually set 'corePoolSize' to the upper bound of the range
|
||||
// but allow core threads to timeout
|
||||
bw.setPropertyValue("allowCoreThreadTimeOut", true);
|
||||
// Actually set 'corePoolSize' to the upper bound of the range
|
||||
// but allow core threads to timeout...
|
||||
this.target.setAllowCoreThreadTimeOut(true);
|
||||
corePoolSize = maxPoolSize;
|
||||
}
|
||||
else {
|
||||
// non-zero lower bound implies a core-max size range
|
||||
// Non-zero lower bound implies a core-max size range...
|
||||
throw new IllegalArgumentException(
|
||||
"A non-zero lower bound for the size range requires a queue-capacity value");
|
||||
}
|
||||
|
|
@ -127,8 +124,8 @@ public class TaskExecutorFactoryBean implements
|
|||
corePoolSize = value;
|
||||
maxPoolSize = value;
|
||||
}
|
||||
bw.setPropertyValue("corePoolSize", corePoolSize);
|
||||
bw.setPropertyValue("maxPoolSize", maxPoolSize);
|
||||
this.target.setCorePoolSize(corePoolSize);
|
||||
this.target.setMaxPoolSize(maxPoolSize);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
throw new IllegalArgumentException("Invalid pool-size value [" + this.poolSize + "]: only single " +
|
||||
|
|
@ -155,10 +152,8 @@ public class TaskExecutorFactoryBean implements
|
|||
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (this.target instanceof DisposableBean) {
|
||||
((DisposableBean) this.target).destroy();
|
||||
}
|
||||
public void destroy() {
|
||||
this.target.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue