From b70568ea18193a9ab75cefcb6cb3484d6c984e12 Mon Sep 17 00:00:00 2001 From: trisberg Date: Thu, 12 Feb 2009 20:56:54 +0000 Subject: [PATCH] BATCH-1034: cleaned up registration of StepScope --- .../configuration/xml/CoreNamespaceUtils.java | 20 ++++++++++++++----- .../core/configuration/xml/JobParser.java | 2 +- .../configuration/xml/TopLevelStepParser.java | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java index eb65e4225..c654e7782 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java @@ -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); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java index 7dbeea718..488f232dd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java @@ -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); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TopLevelStepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TopLevelStepParser.java index e4f6f2fd4..7f59a67fa 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TopLevelStepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TopLevelStepParser.java @@ -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); + } }