diff --git a/spring-batch-execution/.springBeans b/spring-batch-execution/.springBeans index 9d32ce747..e94082c10 100644 --- a/spring-batch-execution/.springBeans +++ b/spring-batch-execution/.springBeans @@ -1,56 +1,58 @@ - - - 1 - - - - - - src/test/resources/simple-container-definition.xml - src/test/resources/job-configuration.xml - src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml - src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml - src/test/resources/org/springframework/batch/execution/configuration/test-context.xml - src/test/resources/org/springframework/batch/execution/scope/scope-tests.xml - src/test/resources/beanRefContext.xml - src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml - src/test/resources/org/springframework/batch/execution/bootstrap/support/test-environment.xml - - - - - true - false - - src/test/resources/job-configuration.xml - src/test/resources/simple-container-definition.xml - - - - - true - false - - src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml - src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml - - - - - true - false - - src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml - - - - - true - false - - src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml - src/test/resources/org/springframework/batch/execution/bootstrap/support/test-environment.xml - - - - + + + 1 + + + + + + + src/test/resources/simple-container-definition.xml + src/test/resources/job-configuration.xml + src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml + src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml + src/test/resources/org/springframework/batch/execution/configuration/test-context.xml + src/test/resources/org/springframework/batch/execution/scope/scope-tests.xml + src/test/resources/beanRefContext.xml + src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml + src/test/resources/org/springframework/batch/execution/bootstrap/support/test-environment.xml + src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepOk.xml + + + + + true + false + + src/test/resources/job-configuration.xml + src/test/resources/simple-container-definition.xml + + + + + true + false + + src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml + src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml + + + + + true + false + + src/test/resources/org/springframework/batch/execution/repository/dao/data-source-context.xml + + + + + true + false + + src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml + src/test/resources/org/springframework/batch/execution/bootstrap/support/test-environment.xml + + + + diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/AbstractStepEntry.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/AbstractStepEntry.java new file mode 100644 index 000000000..906e5c50b --- /dev/null +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/AbstractStepEntry.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import org.springframework.beans.factory.parsing.ParseState; + +/** + * {@link ParseState} entry representing a step. This is an abstract class intended to be overriden with given step + * types. + * + * @author Ben Hale + */ +abstract class AbstractStepEntry implements ParseState.Entry { + + private final String name; + + /** + * Creates a new instance of the {@link AbstractStepEntry} class. + * + * @param name the bean name of the job + */ + AbstractStepEntry(String name) { + this.name = name; + } + + abstract String getType(); + + public String toString() { + return "Step '" + name + "', Type'" + getType() + "'"; + } +} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/BatchNamespaceHandler.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/BatchNamespaceHandler.java new file mode 100644 index 000000000..b4dd43208 --- /dev/null +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/BatchNamespaceHandler.java @@ -0,0 +1,24 @@ +package org.springframework.batch.execution.configuration; + +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.NamespaceHandlerSupport; + +/** + * NamespaceHandler for the batch-execution namespace. + * + *

Provides a {@link BeanDefinitionParser} for the <batch:job> tag. A job + * tag can include nested chunked-step and tasklet-step tags. + * + * @author Ben Hale + */ +public class BatchNamespaceHandler extends NamespaceHandlerSupport { + + /** + * Register the {@link BeanDefinitionParser BeanDefinitionParser} for the + * 'job', tag. + */ + public void init() { + registerBeanDefinitionParser("job", new JobBeanDefinitionParser()); + } + +} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/ChunkStepEntry.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/ChunkStepEntry.java new file mode 100644 index 000000000..048f9c5eb --- /dev/null +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/ChunkStepEntry.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import org.springframework.beans.factory.parsing.ParseState; + +/** + * {@link ParseState} entry representing a {@link ChunkStep}. + * + * @author Ben Hale + */ +public class ChunkStepEntry extends AbstractStepEntry { + + /** + * Creates a new instance of the {@link ChunkStepEntry} class. + * + * @param name the bean name of the job + */ + ChunkStepEntry(String name) { + super(name); + } + + String getType() { + return "chunk"; + } + +} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java index c3bd73622..7380711dc 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java @@ -1,21 +1,79 @@ package org.springframework.batch.execution.configuration; +import org.springframework.batch.execution.step.tasklet.TaskletStep; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.RuntimeBeanNameReference; +import org.springframework.beans.factory.parsing.CompositeComponentDefinition; +import org.springframework.beans.factory.parsing.ParseState; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.StringUtils; import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; class JobBeanDefinitionParser implements BeanDefinitionParser { - - public static final String JOB = "job"; - - public static final String CHUNKING_STEP = "chunking-step"; - - public static final String TASKLET_STEP ="tasklet-step"; + + private static final String TAG_JOB = "job"; + + private static final String TAG_CHUNKING_STEP = "chunking-step"; + + private static final String TAG_TASKLET_STEP = "tasklet-step"; + + private static final String ATT_ID = "id"; + + private static final String ATT_TASKLET = "tasklet"; + + private static final String ATT_RERUN = "rerun"; + + private static final String PROP_TASKLET = "tasklet"; + + private final ParseState parseState = new ParseState(); public BeanDefinition parse(Element element, ParserContext parserContext) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException(); + CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), + parserContext.extractSource(element)); + parserContext.pushContainingComponent(compositeDef); + + NodeList childNodes = element.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + String localName = node.getLocalName(); + if (TAG_CHUNKING_STEP.equals(localName)) { +// parseChunkingStep((Element) node, parserContext); + } else if (TAG_TASKLET_STEP.equals(localName)) { + parseTaskletStep((Element) node, parserContext); + } + } + } + + parserContext.popAndRegisterContainingComponent(); + return null; } + private void parseTaskletStep(Element taskletElement, ParserContext parserContext) { + AbstractBeanDefinition taskletStepDef = createTaskletStepBeanDefinition(taskletElement, parserContext); + } + + private AbstractBeanDefinition createTaskletStepBeanDefinition(Element taskletElement, ParserContext parserContext) { + RootBeanDefinition taskletStepDefinition = new RootBeanDefinition(TaskletStep.class); + taskletStepDefinition.setSource(parserContext.extractSource(taskletElement)); + + String tasklet = taskletElement.getAttribute(ATT_TASKLET); + if (!StringUtils.hasText(tasklet)) { + parserContext.getReaderContext().error("'tasklet' attribute contains empty value", taskletElement, + parseState.snapshot()); + } else { + taskletStepDefinition.getPropertyValues().addPropertyValue(PROP_TASKLET, + new RuntimeBeanNameReference(tasklet)); + } + + System.out.println(taskletElement.hasAttribute("rerun")); + System.out.println(taskletElement.getAttribute("rerun")); + + return taskletStepDefinition; + } } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobEntry.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobEntry.java new file mode 100644 index 000000000..4aa503471 --- /dev/null +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobEntry.java @@ -0,0 +1,42 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import org.springframework.beans.factory.parsing.ParseState; + +/** + * {@link ParseState} entry representing a job. + * + * @author Ben Hale + */ +class JobEntry implements ParseState.Entry { + + private final String name; + + /** + * Creates a new instance of the {@link JobEntry} class. + * + * @param name the bean name of the job + */ + JobEntry(String name) { + this.name = name; + } + + public String toString() { + return "Job '" + name + "'"; + } +} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/TaskletStepEntry.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/TaskletStepEntry.java new file mode 100644 index 000000000..245f3b203 --- /dev/null +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/TaskletStepEntry.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import org.springframework.beans.factory.parsing.ParseState; + +/** + * {@link ParseState} entry representing a {@link TaskletStep}. + * + * @author Ben Hale + */ +public class TaskletStepEntry extends AbstractStepEntry { + + /** + * Creates a new instance of the {@link TaskletStepEntry} class. + * + * @param name the bean name of the job + */ + TaskletStepEntry(String name) { + super(name); + } + + String getType() { + return "tasklet"; + } + +} diff --git a/spring-batch-execution/src/main/resources/META-INF/spring.handlers b/spring-batch-execution/src/main/resources/META-INF/spring.handlers index c3d371f98..cb8e0c842 100644 --- a/spring-batch-execution/src/main/resources/META-INF/spring.handlers +++ b/spring-batch-execution/src/main/resources/META-INF/spring.handlers @@ -1 +1 @@ -http\://www.springframework.org/schema/batch-execution=org.springframework.batch.execution.config.BatchCoreNamespaceHandler +http\://www.springframework.org/schema/batch=org.springframework.batch.execution.configuration.BatchNamespaceHandler diff --git a/spring-batch-execution/src/main/resources/META-INF/spring.schemas b/spring-batch-execution/src/main/resources/META-INF/spring.schemas index b9b173a13..100a80e5a 100644 --- a/spring-batch-execution/src/main/resources/META-INF/spring.schemas +++ b/spring-batch-execution/src/main/resources/META-INF/spring.schemas @@ -1 +1 @@ -http\://www.springframework.org/schema/batch/spring-batch-execution-1.0.xsd=org/springframework/batch/core/config/spring-batch-execution-1.0.xsd +http\://www.springframework.org/schema/batch/spring-batch-1.0.xsd=org/springframework/batch/execution/configuration/spring-batch-1.0.xsd \ No newline at end of file diff --git a/spring-batch-execution/src/main/resources/org/springframework/batch/execution/configuration/spring-batch-1.0.xsd b/spring-batch-execution/src/main/resources/org/springframework/batch/execution/configuration/spring-batch-1.0.xsd new file mode 100644 index 000000000..41a228a0a --- /dev/null +++ b/spring-batch-execution/src/main/resources/org/springframework/batch/execution/configuration/spring-batch-1.0.xsd @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepMissingTasklet.xml b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepMissingTasklet.xml new file mode 100644 index 000000000..ad1b65994 --- /dev/null +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepMissingTasklet.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepOk.xml b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepOk.xml new file mode 100644 index 000000000..25e1ac598 --- /dev/null +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepOk.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java new file mode 100644 index 000000000..8102fcf89 --- /dev/null +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import junit.framework.TestCase; + +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class BatchNamespaceHandlerTaskletStepTests extends TestCase { + + private static final String PACKAGE = "org/springframework/batch/execution/configuration/"; + + public void testNamespaceOk() { + new ClassPathXmlApplicationContext(PACKAGE + "BatchNamespaceHandlerTaskletStepOk.xml"); + } + + public void testNamespaceMissingTasklet() { + try { + new ClassPathXmlApplicationContext(PACKAGE + "BatchNamespaceHandlerTaskletStepMissingTasklet.xml"); + fail("Expected BeanDefinitionParsingException"); + } catch (BeanDefinitionParsingException e) { + + } + } + +} diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/TaskletTestBean.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/TaskletTestBean.java new file mode 100644 index 000000000..1d1bf7f4d --- /dev/null +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/TaskletTestBean.java @@ -0,0 +1,29 @@ +/* + * Copyright 2002-2007 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.execution.configuration; + +import org.springframework.batch.core.tasklet.Tasklet; +import org.springframework.batch.repeat.ExitStatus; + +public class TaskletTestBean implements Tasklet { + + public ExitStatus execute() throws Exception { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + } + +}