OPEN - issue BATCH-116: Create XML input/output source which will work directly with StAX parser
http://opensource.atlassian.com/projects/spring/browse/BATCH-116
This commit is contained in:
1
samples/20070918.testStream.xmlFileStep.output.xml
Normal file
1
samples/20070918.testStream.xmlFileStep.output.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?><trades><trade><isin>XYZ0001</isin><quantity>5</quantity><price>11.39</price><customer>Customer1</customer></trade><trade><isin>XYZ0002</isin><quantity>2</quantity><price>72.99</price><customer>Customer2c</customer></trade><trade><isin>XYZ0003</isin><quantity>9</quantity><price>99.99</price><customer>Customer3</customer></trade><trade><isin>XYZ0001</isin><quantity>5</quantity><price>11.39</price><customer>Customer1</customer></trade><trade><isin>XYZ0002</isin><quantity>2</quantity><price>72.99</price><customer>Customer2c</customer></trade><trade><isin>XYZ0003</isin><quantity>9</quantity><price>99.99</price><customer>Customer3</customer></trade><trade><isin>XYZ0001</isin><quantity>5</quantity><price>11.39</price><customer>Customer1</customer></trade><trade><isin>XYZ0002</isin><quantity>2</quantity><price>72.99</price><customer>Customer2c</customer></trade><trade><isin>XYZ0003</isin><quantity>9</quantity><price>99.99</price><customer>Customer3</customer></trade></trades>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<records>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
</records>
|
||||
17
samples/src/main/resources/data/staxJob/input/trade.xsd
Normal file
17
samples/src/main/resources/data/staxJob/input/trade.xsd
Normal file
@@ -0,0 +1,17 @@
|
||||
<xs:schema
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:bk="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
targetNamespace="http://springframework.org/batch/sample/io/oxm/domain"
|
||||
elementFormDefault="qualified">
|
||||
<xs:element name="trade">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="isin" type="xs:string"/>
|
||||
<xs:element name="quantity" type="xs:long"/>
|
||||
<xs:element name="price" type="xs:decimal"/>
|
||||
<xs:element name="customer" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
||||
80
samples/src/main/resources/jobs/xmlStaxJob.xml
Normal file
80
samples/src/main/resources/jobs/xmlStaxJob.xml
Normal file
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="xmlStaxJob" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource">
|
||||
<bean class="org.springframework.batch.io.stax.StaxEventReaderInputSource" scope="step">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="fragmentRootElementName" value="trade" />
|
||||
<property name="resource" value="data/staxJob/input/20070918.testStream.xmlFileStep.xml" />
|
||||
<property name="fragmentDeserializer">
|
||||
<bean class="org.springframework.batch.io.oxm.UnmarshallingFragmentDeserializer">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases" ref="aliases" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.item.processor.OutputSourceItemProcessor"
|
||||
p:outputSource-ref="tradeStaxWriter" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.io.stax.StaxEventWriterOutputSource" id="tradeStaxWriter">
|
||||
<property name="resource" value="file:20070918.testStream.xmlFileStep.output.xml" />
|
||||
<property name="serializer" ref="tradeMarshallingSerializer" />
|
||||
<property name="rootTagName" value="trades" />
|
||||
<property name="overwriteOutput" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.io.oxm.MarshallingObjectToXmlSerializer" id="tradeMarshallingSerializer">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases" ref="aliases" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<util:map id="aliases">
|
||||
<entry key="trade" value="org.springframework.batch.sample.domain.Trade" />
|
||||
<entry key="isin" value="java.lang.String" />
|
||||
<entry key="quantity" value="long" />
|
||||
<entry key="price" value="java.math.BigDecimal" />
|
||||
<entry key="customer" value="java.lang.String" />
|
||||
</util:map>
|
||||
|
||||
<!-- register the step scope with the application context -->
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2006-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.sample;
|
||||
|
||||
import org.springframework.batch.sample.AbstractLifecycleSpringContextTests;
|
||||
|
||||
public class XmlStaxJobFunctionalTests extends AbstractLifecycleSpringContextTests {
|
||||
|
||||
// @Override
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[]{"jobs/xmlStaxJob.xml"};
|
||||
}
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
applicationContext.close(); //make sure the output file is closed
|
||||
|
||||
/* TODO compare DOM to the expected output -> does not work as expected yet, fails on correct output
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document expectedOutput = builder.parse(
|
||||
new File("src/main/resources/data/staxJob/input/20070918.testStream.xmlFileStep.output.xml"));
|
||||
|
||||
Document actualOutput = builder.parse(
|
||||
new File("20070918.testStream.xmlFileStep.output.xml"));
|
||||
|
||||
expectedOutput.normalize();
|
||||
actualOutput.normalize();
|
||||
|
||||
assertTrue(expectedOutput.isEqualNode(actualOutput));
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user