BATCH-1213:
*Removed isAbstractStep() from BeanDefinitionUtils. The formulation "beanFactory.isTypeMatch(beanName, AbstractStep.class)" should be used instead because it will automatically check the resultant type of a FactoryBean as well. *Changed *StepFactoryBean's getObjectType() to return TaskletStep.class, which is the most specific class name for the resulting object. This allows BeanFactory.isTypeMatch() to to recognize the factory bean's output properly. *Renamed CoreNamespaceBeanDefinitionUtils to BeanDefinitionUtils since it is no longer specific to the core namespace.
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -24,20 +23,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
* @author Dan Garrette
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public class CoreNamespaceBeanDefinitionUtils {
|
||||
|
||||
/**
|
||||
* @param beanName the name of a bean definition in the bean factory
|
||||
* @param beanFactory a {@link BeanFactory}
|
||||
* @return TRUE if the bean represents an {@link AbstractStep} (or
|
||||
* {@link StepParserStepFactoryBean}).
|
||||
*/
|
||||
public static boolean isAbstractStep(String beanName, ConfigurableListableBeanFactory beanFactory) {
|
||||
if (beanFactory.isFactoryBean(beanName)) {
|
||||
return beanFactory.isTypeMatch(BeanFactory.FACTORY_BEAN_PREFIX + beanName, StepParserStepFactoryBean.class);
|
||||
}
|
||||
return beanFactory.isTypeMatch(beanName, AbstractStep.class);
|
||||
}
|
||||
public class BeanDefinitionUtils {
|
||||
|
||||
/**
|
||||
* @param beanName a bean definition name
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
@@ -66,9 +67,9 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor
|
||||
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
|
||||
if (bd.hasAttribute(JOB_FACTORY_PROPERTY_NAME)) {
|
||||
MutablePropertyValues pvs = (MutablePropertyValues) bd.getPropertyValues();
|
||||
if (CoreNamespaceBeanDefinitionUtils.isAbstractStep(beanName, beanFactory)) {
|
||||
if (beanFactory.isTypeMatch(beanName, AbstractStep.class)) {
|
||||
String jobName = (String) bd.getAttribute(JOB_FACTORY_PROPERTY_NAME);
|
||||
PropertyValue jobRepository = CoreNamespaceBeanDefinitionUtils.getPropertyValue(jobName,
|
||||
PropertyValue jobRepository = BeanDefinitionUtils.getPropertyValue(jobName,
|
||||
JOB_REPOSITORY_PROPERTY_NAME, beanFactory);
|
||||
if (jobRepository != null) {
|
||||
// Set the job's JobRepository onto the step
|
||||
@@ -93,7 +94,7 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor
|
||||
*/
|
||||
private void overrideStepClass(String beanName, ConfigurableListableBeanFactory beanFactory) {
|
||||
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
|
||||
Object isNamespaceStep = CoreNamespaceBeanDefinitionUtils
|
||||
Object isNamespaceStep = BeanDefinitionUtils
|
||||
.getAttribute(beanName, "isNamespaceStep", beanFactory);
|
||||
if (isNamespaceStep != null && (Boolean) isNamespaceStep == true) {
|
||||
((AbstractBeanDefinition) bd).setBeanClass(StepParserStepFactoryBean.class);
|
||||
|
||||
@@ -352,8 +352,8 @@ class StepParserStepFactoryBean<I, O> implements FactoryBean, BeanNameAware {
|
||||
return n != null && n > 0;
|
||||
}
|
||||
|
||||
public Class<Step> getObjectType() {
|
||||
return Step.class;
|
||||
public Class<TaskletStep> getObjectType() {
|
||||
return TaskletStep.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
|
||||
@@ -335,8 +335,8 @@ public class SimpleStepFactoryBean<T, S> implements FactoryBean, BeanNameAware {
|
||||
return step;
|
||||
}
|
||||
|
||||
public Class<Step> getObjectType() {
|
||||
return Step.class;
|
||||
public Class<TaskletStep> getObjectType() {
|
||||
return TaskletStep.class;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,7 +124,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
|
||||
@Test
|
||||
public void testType() throws Exception {
|
||||
assertEquals(Step.class, factory.getObjectType());
|
||||
assertTrue(Step.class.isAssignableFrom(factory.getObjectType()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testType() throws Exception {
|
||||
assertEquals(Step.class, factory.getObjectType());
|
||||
assertTrue(Step.class.isAssignableFrom(factory.getObjectType()));
|
||||
}
|
||||
|
||||
public void testDefaultValue() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user