BATCH-1034: cleaned up registration of StepScope
This commit is contained in:
@@ -26,23 +26,33 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public class CoreNamespaceUtils {
|
||||
|
||||
public static final String STEP_SCOPE_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.batch.core.scope.internalStepScope";
|
||||
|
||||
protected static void checkForStepScope(ParserContext parserContext) {
|
||||
final String stepScopeClassName = "org.springframework.batch.core.scope.StepScope";
|
||||
public static final String STEP_SCOPE_PROCESSOR_CLASS_NAME =
|
||||
"org.springframework.batch.core.scope.StepScope";
|
||||
|
||||
|
||||
protected static void checkForStepScope(ParserContext parserContext, Object source) {
|
||||
|
||||
boolean foundStepScope = false;
|
||||
String[] beanNames = parserContext.getRegistry().getBeanDefinitionNames();
|
||||
for (String beanName : beanNames) {
|
||||
BeanDefinition bd = parserContext.getRegistry().getBeanDefinition(beanName);
|
||||
if (stepScopeClassName.equals(bd.getBeanClassName())) {
|
||||
if (STEP_SCOPE_PROCESSOR_CLASS_NAME.equals(bd.getBeanClassName())) {
|
||||
foundStepScope = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundStepScope) {
|
||||
BeanDefinitionBuilder stepScopeBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(stepScopeClassName);
|
||||
BeanDefinitionBuilder.genericBeanDefinition(STEP_SCOPE_PROCESSOR_CLASS_NAME);
|
||||
stepScopeBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
AbstractBeanDefinition abd = stepScopeBuilder.getBeanDefinition();
|
||||
parserContext.getRegistry().registerBeanDefinition(stepScopeClassName, abd);
|
||||
abd.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
abd.setSource(source);
|
||||
parserContext.getRegistry().registerBeanDefinition(STEP_SCOPE_PROCESSOR_BEAN_NAME, abd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
CoreNamespaceUtils.checkForStepScope(parserContext);
|
||||
CoreNamespaceUtils.checkForStepScope(parserContext, parserContext.extractSource(element));
|
||||
|
||||
String jobName = element.getAttribute("id");
|
||||
builder.addConstructorArgValue(jobName);
|
||||
|
||||
@@ -31,9 +31,11 @@ public class TopLevelStepParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
CoreNamespaceUtils.checkForStepScope(parserContext);
|
||||
|
||||
CoreNamespaceUtils.checkForStepScope(parserContext, parserContext.extractSource(element));
|
||||
StandaloneStepParser stepParser = new StandaloneStepParser();
|
||||
return stepParser.parse(element, parserContext);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user