[BATCH 63] Incremental commit

This commit is contained in:
nebhale
2008-02-20 13:14:01 +00:00
parent 34bd1fc446
commit 612b9c1036
14 changed files with 520 additions and 66 deletions

View File

@@ -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() + "'";
}
}

View File

@@ -0,0 +1,24 @@
package org.springframework.batch.execution.configuration;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
* <code>NamespaceHandler</code> for the <code>batch-execution</code> namespace.
*
* <p>Provides a {@link BeanDefinitionParser} for the <code>&lt;batch:job&gt;</code> tag. A <code>job</code>
* tag can include nested <code>chunked-step</code> and <code>tasklet-step</code> tags.
*
* @author Ben Hale
*/
public class BatchNamespaceHandler extends NamespaceHandlerSupport {
/**
* Register the {@link BeanDefinitionParser BeanDefinitionParser} for the
* '<code>job</code>', tag.
*/
public void init() {
registerBeanDefinitionParser("job", new JobBeanDefinitionParser());
}
}

View File

@@ -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";
}
}

View File

@@ -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;
}
}

View File

@@ -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 + "'";
}
}

View File

@@ -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";
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.springframework.org/schema/batch"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/schema/batch"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xs:element name="job">
<xs:annotation>
<xs:documentation><![CDATA[Defines a uniquely identified job that is referenced at runtime.]]></xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="chunk-step" type="chunkStepType">
<xs:annotation>
<xs:documentation><![CDATA[Defines a step that supports chunking]]></xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="tasklet-step" type="taskletStepType">
<xs:annotation>
<xs:documentation><![CDATA[Defines a step that executes a tasklet]]></xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
<xs:attribute name="id" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The unique identifier to use in this step. The id must be unique within the context of this job.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<!-- Types -->
<xs:complexType name="chunkStepType">
<xs:attribute name="id" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The unique identifier to use in this step. The id must be unique within the context of this job.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="size" type="xs:positiveInteger" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The number of elements to be processed per chunk. This must be a number greater than 0.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="item-reader" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The id of the ItemReader implementation to read from in this step]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="item-writer" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The id of the ItemWriter implementation to write to in this step]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="transaction-manager" type="xs:string" use="optional"
default="transaction-manager">
<xs:annotation>
<xs:documentation><![CDATA[The id of the transaction manager to use in this step. This should be an implementation of Spring's PlatformTransactionManager.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="rerun.enum"/>
<xs:attribute name="input-skip-limit" type="xs:nonNegativeInteger" use="optional">
<xs:annotation>
<xs:documentation><![CDATA[The maximum number of items the ItemReader can skip before this step is marked as a failure. The default is no limit.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="output-skip-limit" type="xs:nonNegativeInteger" use="optional">
<xs:annotation>
<xs:documentation><![CDATA[The maximum number of items the ItemWriter can skip before this step is marked as a failure. The default is no limit.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="taskletStepType">
<xs:attribute name="id" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The unique identifier to use in this step. The id must be unique within the context of this job.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="tasklet" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[The id of the Tasklet implementation to execute in this step.]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="rerun.enum"/>
</xs:complexType>
<!-- Enumerations -->
<xs:attributeGroup name="rerun.enum">
<xs:attribute name="rerun" use="optional" default="incomplete">
<xs:annotation>
<xs:documentation><![CDATA[When to re-run this step. The default is 'incomplete.
* always: Always re-run this step
* never: Never re-run this step
* incomplete: Re-run this step whenever a previous execution was incomplete]]></xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="always"/>
<xs:enumeration value="never"/>
<xs:enumeration value="incomplete"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
</xs:schema>

View File

@@ -0,0 +1,12 @@
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-1.0.xsd">
<job id="processJob">
<tasklet-step id="process" tasklet=""/>
</job>
</beans:beans>

View File

@@ -0,0 +1,14 @@
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-1.0.xsd">
<job id="processJob">
<tasklet-step id="process" tasklet="processorTasklet"/>
</job>
<beans:bean id="processorTasklet" class="org.springframework.batch.execution.configuration.TaskletTestBean"/>
</beans:beans>

View File

@@ -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) {
}
}
}

View File

@@ -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();
}
}