diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java index 63ab91d30..47e2c8b3a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java @@ -15,7 +15,6 @@ */ package org.springframework.batch.core.configuration.xml; -import org.springframework.batch.core.jsr.configuration.xml.JobFactoryBean; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.AbstractStep; import org.springframework.beans.BeansException; @@ -127,14 +126,7 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor if (jobRepository == null) { fb.setJobRepository((JobRepository) applicationContext.getBean(DEFAULT_JOB_REPOSITORY_NAME)); } - } else if(bean instanceof JobFactoryBean) { - JobFactoryBean fb = (JobFactoryBean) bean; - JobRepository jobRepository = fb.getJobRepository(); - if (jobRepository == null) { - fb.setJobRepository((JobRepository) applicationContext.getBean(DEFAULT_JOB_REPOSITORY_NAME)); - } - } - else if (bean instanceof StepParserStepFactoryBean) { + } else if (bean instanceof StepParserStepFactoryBean) { StepParserStepFactoryBean fb = (StepParserStepFactoryBean) bean; JobRepository jobRepository = fb.getJobRepository(); if (jobRepository == null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespacePostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespacePostProcessor.java new file mode 100644 index 000000000..b8ae980d2 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespacePostProcessor.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.jsr.configuration.xml; + +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * @author Michael Minella + */ +public class JsrNamespacePostProcessor implements BeanPostProcessor, ApplicationContextAware { + + private static final String DEFAULT_JOB_REPOSITORY_NAME = "jobRepository"; + + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if(bean instanceof JobFactoryBean) { + JobFactoryBean fb = (JobFactoryBean) bean; + JobRepository jobRepository = fb.getJobRepository(); + if (jobRepository == null) { + fb.setJobRepository((JobRepository) applicationContext.getBean(DEFAULT_JOB_REPOSITORY_NAME)); + } + } + + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } +} + + + diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespaceUtils.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespaceUtils.java index 85734cd7c..978a737f3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespaceUtils.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrNamespaceUtils.java @@ -15,11 +15,9 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import java.util.HashMap; - -import org.springframework.batch.core.jsr.configuration.support.BatchPropertyBeanPostProcessor; +import org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor; import org.springframework.batch.core.jsr.configuration.support.JsrAutowiredAnnotationBeanPostProcessor; -import org.springframework.batch.core.jsr.configuration.support.JsrBeanScopeBeanFactoryPostProcessor; +import org.springframework.batch.core.jsr.partition.support.JsrBeanScopeBeanFactoryPostProcessor; import org.springframework.batch.core.jsr.configuration.support.ThreadLocalClassloaderBeanPostProcessor; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -27,6 +25,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.context.annotation.AnnotationConfigUtils; +import java.util.HashMap; + /** * Utility methods used in parsing of the JSR-352 batch namespace and related helpers. * @@ -41,6 +41,7 @@ class JsrNamespaceUtils { private static final String BEAN_SCOPE_POST_PROCESSOR_BEAN_NAME = "beanScopeBeanPostProcessor"; private static final String BATCH_PROPERTY_CONTEXT_BEAN_CLASS_NAME = "org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext"; private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext"; + private static final String JSR_NAMESPACE_POST_PROCESSOR = "jsrNamespacePostProcessor"; static void autoregisterJsrBeansForNamespace(ParserContext parserContext) { autoRegisterJobProperties(parserContext); @@ -49,6 +50,11 @@ class JsrNamespaceUtils { autoRegisterThreadLocalClassloaderBeanPostProcessor(parserContext); autoRegisterBeanScopeBeanFactoryPostProcessor(parserContext); autoRegisterBatchPropertyContext(parserContext); + autoRegisterNamespacePostProcessor(parserContext); + } + + private static void autoRegisterNamespacePostProcessor(ParserContext parserContext) { + registerPostProcessor(parserContext, JsrNamespacePostProcessor.class, BeanDefinition.ROLE_INFRASTRUCTURE, JSR_NAMESPACE_POST_PROCESSOR); } private static void autoRegisterBeanScopeBeanFactoryPostProcessor( diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrStepListenerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrStepListenerFactoryBean.java new file mode 100644 index 000000000..8f051d562 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrStepListenerFactoryBean.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.jsr.configuration.xml; + +import org.springframework.batch.core.jsr.JsrStepListenerMetaData; +import org.springframework.batch.core.listener.ListenerMetaData; +import org.springframework.batch.core.listener.StepListenerFactoryBean; +import org.springframework.batch.core.listener.StepListenerMetaData; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Michael Minella + */ +public class JsrStepListenerFactoryBean extends StepListenerFactoryBean { + + @Override + protected ListenerMetaData getMetaDataFromPropertyName(String propertyName) { + ListenerMetaData metaData = StepListenerMetaData.fromPropertyName(propertyName); + + if(metaData == null) { + metaData = JsrStepListenerMetaData.fromPropertyName(propertyName); + } + + return metaData; + } + + @Override + protected ListenerMetaData[] getMetaDataValues() { + List values = new ArrayList(); + Collections.addAll(values, StepListenerMetaData.values()); + Collections.addAll(values, JsrStepListenerMetaData.values()); + + return values.toArray(new ListenerMetaData[values.size()]); + } +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/StepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/StepParser.java index af472c9f8..3b9cc4235 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/StepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/StepParser.java @@ -15,11 +15,8 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import java.util.Collection; - import org.springframework.batch.core.jsr.configuration.support.BatchArtifactType; import org.springframework.batch.core.jsr.job.flow.support.state.JsrStepState; -import org.springframework.batch.core.listener.StepListenerFactoryBean; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.parsing.BeanComponentDefinition; @@ -32,6 +29,8 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.util.Collection; + /** * Parser for the <step /> element defined by JSR-352. * @@ -75,7 +74,7 @@ public class StepParser extends AbstractSingleBeanDefinitionParser { allowStartIfCompletValue = Boolean.valueOf(allowStartIfComplete); } - new ListenerParser(StepListenerFactoryBean.class, "listeners").parseListeners(element, parserContext, bd, stepName); + new ListenerParser(JsrStepListenerFactoryBean.class, "listeners").parseListeners(element, parserContext, bd, stepName); new PropertyParser(stepName, parserContext, BatchArtifactType.STEP, stepName).parseProperties(element); // look at all nested elements diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/support/BatchPropertyBeanPostProcessor.java similarity index 96% rename from spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyBeanPostProcessor.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/support/BatchPropertyBeanPostProcessor.java index 673f7758f..7ba1896a4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/support/BatchPropertyBeanPostProcessor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.jsr.configuration.support; +package org.springframework.batch.core.jsr.launch.support; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -26,6 +26,8 @@ import javax.batch.api.BatchProperty; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext; +import org.springframework.batch.core.jsr.configuration.support.JsrExpressionParser; import org.springframework.batch.core.scope.StepScope; import org.springframework.batch.core.scope.context.StepContext; import org.springframework.batch.core.scope.context.StepSynchronizationManager; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/JsrBeanScopeBeanFactoryPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/partition/support/JsrBeanScopeBeanFactoryPostProcessor.java similarity index 98% rename from spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/JsrBeanScopeBeanFactoryPostProcessor.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/jsr/partition/support/JsrBeanScopeBeanFactoryPostProcessor.java index 0a0c4d090..3f3f9ce19 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/JsrBeanScopeBeanFactoryPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/partition/support/JsrBeanScopeBeanFactoryPostProcessor.java @@ -13,11 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.jsr.configuration.support; - -import javax.batch.api.partition.PartitionAnalyzer; -import javax.batch.api.partition.PartitionMapper; -import javax.batch.api.partition.PartitionReducer; +package org.springframework.batch.core.jsr.partition.support; import org.springframework.batch.core.jsr.configuration.xml.StepFactoryBean; import org.springframework.batch.core.jsr.partition.JsrPartitionHandler; @@ -29,6 +25,10 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.AbstractBeanDefinition; +import javax.batch.api.partition.PartitionAnalyzer; +import javax.batch.api.partition.PartitionMapper; +import javax.batch.api.partition.PartitionReducer; + /** * In order for property resolution to occur correctly within the scope of a JSR-352 * batch job, initialization of job level artifacts must occur on the same thread that diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerFactoryBean.java index 6aa56e4ff..f859fd668 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerFactoryBean.java @@ -15,12 +15,7 @@ */ package org.springframework.batch.core.listener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.springframework.batch.core.StepListener; -import org.springframework.batch.core.jsr.JsrStepListenerMetaData; /** * This {@link AbstractListenerFactoryBean} implementation is used to create a @@ -36,22 +31,12 @@ public class StepListenerFactoryBean extends AbstractListenerFactoryBean values = new ArrayList(); - Collections.addAll(values, StepListenerMetaData.values()); - Collections.addAll(values, JsrStepListenerMetaData.values()); - - return values.toArray(new ListenerMetaData[0]); + return StepListenerMetaData.values(); } @Override