Permalink
Browse files

BATCH-1949: Removed Spring 3 checks and updated documentation accordi…

…ngly
  • Loading branch information...
1 parent 5a427ca commit 2e0cba57f75a90024fbf57a194f3e7ada00d97e8 @mminella mminella committed Jan 11, 2013
View
@@ -95,3 +95,5 @@ unflushed
memento
michael
minella
+accessors
+subclassing
@@ -20,7 +20,6 @@
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.batch.core.scope.context.StepContext;
import org.springframework.batch.core.scope.context.StepSynchronizationManager;
-import org.springframework.batch.core.scope.util.PlaceholderProxyFactoryBean;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException;
@@ -35,7 +34,6 @@
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.Ordered;
import org.springframework.util.Assert;
-import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringValueResolver;
/**
@@ -73,6 +71,7 @@
* accessors provided as a convenience for step and job attributes.
*
* @author Dave Syer
+ * @author Michael Minella
* @since 2.0
*/
public class StepScope implements Scope, BeanFactoryPostProcessor, Ordered {
@@ -105,10 +104,6 @@ public int getOrder() {
private boolean proxyTargetClass = false;
- private static boolean springThreeDetected;
-
- private static boolean cachedSpringThreeResult;
-
/**
* Flag to indicate that proxies should use dynamic subclassing. This allows
* classes with no interface to be proxied. Defaults to false.
@@ -121,9 +116,7 @@ public void setProxyTargetClass(boolean proxyTargetClass) {
}
/**
- * If Spring 3.0 is available, this will be used to resolve expressions in
- * step-scoped beans. This method is part of the Scope SPI in Spring 3.0,
- * but should just be ignored by earlier versions of Spring.
+ * This will be used to resolve expressions in step-scoped beans.
*/
@Override
public Object resolveContextualObject(String key) {
@@ -231,24 +224,12 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
scopifier.visitBeanDefinition(definition);
if (scoped) {
- if (!isSpringThree()) {
- new ExpressionHider(name, scoped).visitBeanDefinition(definition);
- }
createScopedProxy(beanName, definition, registry, proxyTargetClass);
}
}
}
- private static boolean isSpringThree() {
- if (!cachedSpringThreeResult) {
- springThreeDetected = ReflectionUtils.findMethod(Scope.class, "resolveContextualObject",
- new Class<?>[] { String.class }) != null;
- cachedSpringThreeResult = true;
- }
- return springThreeDetected;
- }
-
/**
* Public setter for the name property. This can then be used as a bean
* definition attribute, e.g. scope="step". Defaults to "step".
@@ -262,9 +243,7 @@ public void setName(String name) {
/**
* Wrap a target bean definition in a proxy that defers initialization until
* after the {@link StepContext} is available. Amounts to adding
- * &lt;aop-auto-proxy/&gt; to a step scoped bean. Also if Spring EL is not
- * available will enable a weak version of late binding as described in the
- * class-level docs.
+ * &lt;aop-auto-proxy/&gt; to a step scoped bean.
*
* @param beanName the bean name to replace
* @param definition the bean definition to replace
@@ -280,16 +259,9 @@ private static BeanDefinitionHolder createScopedProxy(String beanName, BeanDefin
BeanDefinitionHolder proxyHolder;
- if (isSpringThree()) {
- proxyHolder = ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(definition, beanName), registry,
- proxyTargetClass);
- }
- else {
- // Create the scoped proxy...
- proxyHolder = PlaceholderProxyFactoryBean.createScopedProxy(new BeanDefinitionHolder(definition, beanName),
- registry, proxyTargetClass);
- // ...and register it under the original target name
- }
+ proxyHolder = ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(definition, beanName), registry,
+ proxyTargetClass);
+
registry.registerBeanDefinition(beanName, proxyHolder.getBeanDefinition());
return proxyHolder;
@@ -344,9 +316,6 @@ else if (value instanceof BeanDefinitionHolder) {
if (definition != null) {
boolean nestedScoped = scope.equals(definition.getScope());
boolean scopeChangeRequiresProxy = !scoped && nestedScoped;
- if (!isSpringThree()) {
- new ExpressionHider(scope, nestedScoped).visitBeanDefinition(definition);
- }
if (scopeChangeRequiresProxy) {
// Exit here so that nested inner bean definitions are not
// analysed
@@ -361,66 +330,4 @@ else if (value instanceof BeanDefinitionHolder) {
}
}
-
- /**
- * Helper class to scan a bean definition hierarchy and hide placeholders
- * from Spring EL.
- *
- * @author Dave Syer
- *
- */
- private static class ExpressionHider extends BeanDefinitionVisitor {
-
- private static final String PLACEHOLDER_PREFIX = "#{";
-
- private static final String PLACEHOLDER_SUFFIX = "}";
-
- private static final String REPLACEMENT_PREFIX = "%{";
-
- private final String scope;
-
- private final boolean scoped;
-
- private ExpressionHider(String scope, final boolean scoped) {
- super(new StringValueResolver() {
- @Override
- public String resolveStringValue(String value) {
- if (scoped && value.contains(PLACEHOLDER_PREFIX) && value.contains(PLACEHOLDER_SUFFIX)) {
- value = value.replace(PLACEHOLDER_PREFIX, REPLACEMENT_PREFIX);
- }
- return value;
- }
- });
- this.scope = scope;
- this.scoped = scoped;
- }
-
- @Override
- protected Object resolveValue(Object value) {
- BeanDefinition definition = null;
- if (value instanceof BeanDefinition) {
- definition = (BeanDefinition) value;
- }
- else if (value instanceof BeanDefinitionHolder) {
- BeanDefinitionHolder holder = (BeanDefinitionHolder) value;
- definition = holder.getBeanDefinition();
- }
- if (definition != null) {
- String otherScope = definition.getScope();
- boolean scopeChange = !scope.equals(otherScope);
- if (scopeChange) {
- new ExpressionHider(otherScope == null ? scope : otherScope, !scoped)
- .visitBeanDefinition(definition);
- // Exit here so that nested inner bean definitions are not
- // analysed by both visitors
- return value;
- }
- }
- // Nested inner bean definitions are recursively analysed here
- value = super.resolveValue(value);
- return value;
- }
-
- }
-
}

0 comments on commit 2e0cba5

Please sign in to comment.