Skip to content

Commit 157dcab

Browse files
committed
Cleanup of remaining direct BeanWrapper usage
Issue: SPR-14121
1 parent 5c1d3fc commit 157dcab

File tree

4 files changed

+44
-50
lines changed

4 files changed

+44
-50
lines changed

spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,19 @@
4848
*/
4949
public interface BeanWrapper extends ConfigurablePropertyAccessor {
5050

51+
/**
52+
* Specify a limit for array and collection auto-growing.
53+
* <p>Default is unlimited on a plain BeanWrapper.
54+
* @since 4.1
55+
*/
56+
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
57+
58+
/**
59+
* Return the limit for array and collection auto-growing.
60+
* @since 4.1
61+
*/
62+
int getAutoGrowCollectionLimit();
63+
5164
/**
5265
* Return the bean instance wrapped by this object, if any.
5366
* @return the bean instance, or {@code null} if none set
@@ -78,15 +91,4 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
7891
*/
7992
PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException;
8093

81-
/**
82-
* Specify a limit for array and collection auto-growing.
83-
* <p>Default is unlimited on a plain BeanWrapper.
84-
*/
85-
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
86-
87-
/**
88-
* Return the limit for array and collection auto-growing.
89-
*/
90-
int getAutoGrowCollectionLimit();
91-
9294
}

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,8 +72,8 @@ public void setSchedulerContext(SchedulerContext schedulerContext) {
7272
@Override
7373
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
7474
Object job = super.createJobInstance(bundle);
75-
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
76-
if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
75+
if (isEligibleForPropertyPopulation(job)) {
76+
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
7777
MutablePropertyValues pvs = new MutablePropertyValues();
7878
if (this.schedulerContext != null) {
7979
pvs.addPropertyValues(this.schedulerContext);

spring-context/src/main/java/org/springframework/scheduling/config/ExecutorBeanDefinitionParser.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,9 +61,6 @@ private void configureRejectionPolicy(Element element, BeanDefinitionBuilder bui
6161
return;
6262
}
6363
String prefix = "java.util.concurrent.ThreadPoolExecutor.";
64-
if (builder.getRawBeanDefinition().getBeanClassName().contains("backport")) {
65-
prefix = "edu.emory.mathcs.backport." + prefix;
66-
}
6764
String policyClassName;
6865
if (rejectionPolicy.equals("ABORT")) {
6966
policyClassName = prefix + "AbortPolicy";

spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.scheduling.config;
1818

19-
import org.springframework.beans.BeanWrapper;
20-
import org.springframework.beans.BeanWrapperImpl;
19+
import java.util.concurrent.RejectedExecutionHandler;
20+
2121
import org.springframework.beans.factory.BeanNameAware;
2222
import org.springframework.beans.factory.DisposableBean;
2323
import org.springframework.beans.factory.FactoryBean;
@@ -27,8 +27,8 @@
2727
import org.springframework.util.StringUtils;
2828

2929
/**
30-
* FactoryBean for creating ThreadPoolTaskExecutor instances, choosing
31-
* between the standard concurrent and the backport-concurrent variant.
30+
* {@link FactoryBean} for creating {@link ThreadPoolTaskExecutor} instances,
31+
* primarily used behind the XML task namespace.
3232
*
3333
* @author Mark Fisher
3434
* @author Juergen Hoeller
@@ -41,13 +41,13 @@ public class TaskExecutorFactoryBean implements
4141

4242
private Integer queueCapacity;
4343

44-
private Object rejectedExecutionHandler;
44+
private RejectedExecutionHandler rejectedExecutionHandler;
4545

4646
private Integer keepAliveSeconds;
4747

4848
private String beanName;
4949

50-
private TaskExecutor target;
50+
private ThreadPoolTaskExecutor target;
5151

5252

5353
public void setPoolSize(String poolSize) {
@@ -58,7 +58,7 @@ public void setQueueCapacity(int queueCapacity) {
5858
this.queueCapacity = queueCapacity;
5959
}
6060

61-
public void setRejectedExecutionHandler(Object rejectedExecutionHandler) {
61+
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
6262
this.rejectedExecutionHandler = rejectedExecutionHandler;
6363
}
6464

@@ -73,28 +73,25 @@ public void setBeanName(String beanName) {
7373

7474

7575
@Override
76-
public void afterPropertiesSet() throws Exception {
77-
BeanWrapper bw = new BeanWrapperImpl(ThreadPoolTaskExecutor.class);
78-
determinePoolSizeRange(bw);
76+
public void afterPropertiesSet() {
77+
this.target = new ThreadPoolTaskExecutor();
78+
determinePoolSizeRange();
7979
if (this.queueCapacity != null) {
80-
bw.setPropertyValue("queueCapacity", this.queueCapacity);
80+
this.target.setQueueCapacity(this.queueCapacity);
8181
}
8282
if (this.keepAliveSeconds != null) {
83-
bw.setPropertyValue("keepAliveSeconds", this.keepAliveSeconds);
83+
this.target.setKeepAliveSeconds(this.keepAliveSeconds);
8484
}
8585
if (this.rejectedExecutionHandler != null) {
86-
bw.setPropertyValue("rejectedExecutionHandler", this.rejectedExecutionHandler);
86+
this.target.setRejectedExecutionHandler(this.rejectedExecutionHandler);
8787
}
8888
if (this.beanName != null) {
89-
bw.setPropertyValue("threadNamePrefix", this.beanName + "-");
90-
}
91-
this.target = (TaskExecutor) bw.getWrappedInstance();
92-
if (this.target instanceof InitializingBean) {
93-
((InitializingBean) this.target).afterPropertiesSet();
89+
this.target.setThreadNamePrefix(this.beanName + "-");
9490
}
91+
this.target.afterPropertiesSet();
9592
}
9693

97-
private void determinePoolSizeRange(BeanWrapper bw) {
94+
private void determinePoolSizeRange() {
9895
if (StringUtils.hasText(this.poolSize)) {
9996
try {
10097
int corePoolSize;
@@ -108,15 +105,15 @@ private void determinePoolSizeRange(BeanWrapper bw) {
108105
"Lower bound of pool-size range must not exceed the upper bound");
109106
}
110107
if (this.queueCapacity == null) {
111-
// no queue-capacity provided, so unbounded
108+
// No queue-capacity provided, so unbounded
112109
if (corePoolSize == 0) {
113-
// actually set 'corePoolSize' to the upper bound of the range
114-
// but allow core threads to timeout
115-
bw.setPropertyValue("allowCoreThreadTimeOut", true);
110+
// Actually set 'corePoolSize' to the upper bound of the range
111+
// but allow core threads to timeout...
112+
this.target.setAllowCoreThreadTimeOut(true);
116113
corePoolSize = maxPoolSize;
117114
}
118115
else {
119-
// non-zero lower bound implies a core-max size range
116+
// Non-zero lower bound implies a core-max size range...
120117
throw new IllegalArgumentException(
121118
"A non-zero lower bound for the size range requires a queue-capacity value");
122119
}
@@ -127,8 +124,8 @@ private void determinePoolSizeRange(BeanWrapper bw) {
127124
corePoolSize = value;
128125
maxPoolSize = value;
129126
}
130-
bw.setPropertyValue("corePoolSize", corePoolSize);
131-
bw.setPropertyValue("maxPoolSize", maxPoolSize);
127+
this.target.setCorePoolSize(corePoolSize);
128+
this.target.setMaxPoolSize(maxPoolSize);
132129
}
133130
catch (NumberFormatException ex) {
134131
throw new IllegalArgumentException("Invalid pool-size value [" + this.poolSize + "]: only single " +
@@ -155,10 +152,8 @@ public boolean isSingleton() {
155152

156153

157154
@Override
158-
public void destroy() throws Exception {
159-
if (this.target instanceof DisposableBean) {
160-
((DisposableBean) this.target).destroy();
161-
}
155+
public void destroy() {
156+
this.target.destroy();
162157
}
163158

164159
}

0 commit comments

Comments
 (0)