diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInput.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInput.java
deleted file mode 100644
index b89c42446..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInput.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.io.xml;
-
-import java.io.IOException;
-
-import org.springframework.batch.io.xml.xstream.XStreamFactory;
-
-/**
- * The ObjectInput interface provides method for reading objects
- * from input stream and also provides methods for manipulating input stream.
- * @author peter.zozom
- * @see XStreamFactory.ObjectInputWrapper
- */
-public interface ObjectInput {
-
- /**
- * Enables input stream postprocess after reading from the stream has been
- * restarted.
- * @param data
- */
- public void afterRestart(Object data);
-
- /**
- * Read and return an object. The class that implements this interface
- * defines where the object is "read" from.
- *
- * @return the object read from the stream
- * @exception java.lang.ClassNotFoundException If the class of a serialized
- * object cannot be found.
- * @exception IOException If any of the usual Input/Output related
- * exceptions occur.
- */
- public Object readObject() throws ClassNotFoundException, IOException;
-
- /**
- * Closes the input stream. Must be called to release any resources
- * associated with the stream.
- */
- public void close();
-
- /**
- * Get actual position in the input stream.
- * @return actual position in the input stream
- */
- public long position();
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInputFactory.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInputFactory.java
deleted file mode 100644
index 2c1aceb66..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectInputFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.io.xml;
-
-import org.springframework.core.io.Resource;
-
-/**
- * ObjectInputFactory creates instance of ObjectInput.
- * Implementation should be thread-safe.
- * @author peter.zozom
- */
-public interface ObjectInputFactory {
-
- /**
- * Creates instance of {@link ObjectInput}
- * @return ObjectInput
- */
- public ObjectInput createObjectInput(Resource resource, String encoding);
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutput.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutput.java
deleted file mode 100644
index 3f6ecd67b..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutput.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.io.xml;
-
-import java.io.IOException;
-
-import org.springframework.batch.io.xml.xstream.XStreamFactory;
-
-/**
- * The ObjectOutput interface provides methods for writing
- * objects to output stream and also provides methods for manipulating output
- * stream (such as flush, position, truncate, etc.).
- * @author peter.zozom
- * @see XStreamFactory.ObjectOutputWrapper
- */
-public interface ObjectOutput {
-
- /**
- * Enables output stream postprocess after writing to the stream has been
- * restarted.
- * @param data
- */
- public void afterRestart(Object data);
-
- /**
- * Write an object to the stream. The class that implements this interface
- * defines how the object is written.
- *
- * @param obj the object to be written
- * @exception IOException Any of the usual Input/Output related exceptions.
- */
- public void writeObject(Object obj) throws IOException;
-
- /**
- * Closes the stream. This method must be called to release any resources
- * associated with the stream.
- */
- public void close();
-
- /**
- * Flushes the stream. This will write any buffered output bytes.
- */
- public void flush();
-
- /**
- * Get actual position in the output stream.
- * @return actual position in the output stream
- */
- public long position();
-
- /**
- * Set a new position in the output stream.
- * @param newPosition the new position, a non-negative integer counting the
- * number of bytes from the beginning of the file
- */
- public void position(long newPosition);
-
- /**
- * Truncates the otput file to the given size.
- * @param size the new size, a non-negative byte count
- */
- public void truncate(long size);
-
- /**
- * Returns the current size of the output file
- * @return The current size of the output file, measured in bytes
- */
- public long size();
-
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutputFactory.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutputFactory.java
deleted file mode 100644
index a8624c9d7..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/ObjectOutputFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.io.xml;
-
-import org.springframework.core.io.Resource;
-
-/**
- * ObjectOutputFactory creates instance of ObjectOutput.
- * Implementation should be thread-safe.
- * @author peter.zozom
- */
-public interface ObjectOutputFactory {
-
- /**
- * Creates instance of {@link ObjectOutput}
- * @return
- */
- public ObjectOutput createObjectOutput(Resource resource, String encoding);
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/UnmarshallerAdapter.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/UnmarshallerAdapter.java
deleted file mode 100644
index 6f5b9b46b..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/UnmarshallerAdapter.java
+++ /dev/null
@@ -1,198 +0,0 @@
-package org.springframework.batch.io.xml;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.charset.Charset;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.transform.Source;
-import javax.xml.transform.sax.SAXSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.dao.DataAccessResourceFailureException;
-import org.springframework.oxm.Unmarshaller;
-import org.springframework.oxm.XmlMappingException;
-import org.springframework.xml.transform.StaxSource;
-
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-/**
- * Unmarshaller adapter allows to use {@link org.springframework.oxm.Unmarshaller} for
- * iterative XML record processing.
- *
- * {@link org.springframework.oxm.Unmarshaller} always processes whole XML
- * input at once, but we need to process only one record per one module
- * iteration (or per one call of the read() method).
- *
- * Solution is to cut XML in smaller pieces (each piece contains single record) and call
- * the unmarshaller to process only this single piece (record).
- *
- */
-class UnmarshallerAdapter {
-
- private static final Log log = LogFactory.getLog(UnmarshallerAdapter.class);
-
- private FileChannel fc;
-
- private String encoding;
-
- //original unmarshaller - processes only pieces of XML passed from wrapper
- private Unmarshaller u;
-
- //regex matcher - used to cut XML piece holding one record
- private final Matcher matcher;
-
- private SourceFactory factory;
-
- /* ***** Constructor ***** */
-
- /**
- * @param originalUnmarshaller unmarshaller to be wrapped
- */
- public UnmarshallerAdapter(Unmarshaller originalUnmarshaller, String recordElementName, FileChannel fc,
- String encoding, boolean useSaxParser) {
- this.u = originalUnmarshaller;
- this.fc = fc;
- this.encoding = encoding;
- this.matcher = getMatcher(recordElementName);
- this.factory = getSourceFactory(useSaxParser);
- }
-
- /**
- * Unmarshal next record.
- * @see org.springframework.oxm.Unmarshaller#unmarshal(javax.xml.transform.Source)
- */
- public Object unmarshal() throws XmlMappingException, IOException {
-
- Object result = null;
-
- String record = readNextRecord();
- if (record != null) {
- result = u.unmarshal(factory.getSource(record));
- }
- return result;
- }
-
-
- /**
- * Read next piece of XML.
- * @return xml string holding one record
- */
- private String readNextRecord() {
-
- String result = null;
-
- if (matcher.find()) {
- result = matcher.group();
- }
- if (result != null) {
- try {
- fc.position(matcher.end());
- } catch (IOException e) {
- throw new IllegalStateException("Error while adjusting filechannel position");
- }
- }
-
- return result;
- }
-
-
- /* ***** Private helper methods ***** */
-
- /**
- * Get regex matcher, which cuts XML to pieces
- * @param elemName name of the element that represents one record
- * @return the matcher
- */
- private Matcher getMatcher(String elemName) {
-
- CharSequence cs = null;
-
- try {
- // Create a read-only CharBuffer on the file
- ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, fc.position(), fc.size() - fc.position());
- cs = Charset.forName(encoding).newDecoder().decode(bbuf);
- }
- catch (IOException ioe) {
- log.error(ioe);
- throw new DataAccessResourceFailureException("Unable to get input stream", ioe);
- }
-
- String prefix = (elemName.indexOf(':') < 0) ? "(?:[^:]*?:)?" : "";
- String re = "<" + prefix + elemName + "[^/>]*?/>|<" + prefix + elemName + "[\\s>][\\S\\s]*?" + prefix
- + elemName + ">";
-
- return Pattern.compile(re, Pattern.MULTILINE).matcher(cs);
- }
-
- /**
- * Get SourceFactory which will create SAX or StAX source (based on useSaxParser flag)
- * @param useSaxParser
- */
- private SourceFactory getSourceFactory(boolean useSaxParser) {
-
- SourceFactory sf;
-
- if (useSaxParser) {
- sf = new SourceFactory() {
- public Source getSource(String xml) {
-
- Source source = null;
-
- Reader r = new StringReader(xml);
- try {
- XMLReader reader;
- try {
- reader = XMLReaderFactory.createXMLReader();
- }
- catch (SAXException se) {
- reader = XMLReaderFactory.createXMLReader("org.apache.crimson.parser.XMLReaderImpl");
- }
- source = new SAXSource(reader, new org.xml.sax.InputSource(r));
- }
- catch (SAXException se) {
- log.error(se);
- throw new DataAccessResourceFailureException("Unable to get XML reader", se);
- }
-
- return source;
- }
- };
- }
- else {
- sf = new SourceFactory() {
- public Source getSource(String xml) {
- XMLInputFactory xsf = XMLInputFactory.newInstance();
-
- Source source = null;
-
- try {
- Reader r = new StringReader(xml);
- source = new StaxSource(xsf.createXMLStreamReader(r));
- }
- catch (XMLStreamException xse) {
- log.error(xse);
- throw new DataAccessResourceFailureException("Unable to get XML reader", xse);
- }
- return source;
- }
- };
- }
-
- return sf;
- }
-
- private interface SourceFactory {
- public Source getSource(String xml);
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlErrorHandler.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlErrorHandler.java
deleted file mode 100644
index 109216c17..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlErrorHandler.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.io.xml;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * SAX error handler implementation. This implementation only logs warnings and
- * errors and re-throws exceptions.
- *
- * @author peter.zozom
- */
-public class XmlErrorHandler extends DefaultHandler {
- private static final Log log = LogFactory.getLog(XmlErrorHandler.class);
-
- /**
- * @param e parsing exception
- * @throws SAXException re-thrown exception
- * @see org.xml.sax.helpers.DefaultHandler#warning(org.xml.sax.SAXParseException)
- */
- public void warning(SAXParseException e) throws SAXException {
- log.debug("Warning: \n" + printInfo(e));
- throw new SAXException(e);
- }
-
- /**
- * @param e parsing exception
- * @throws SAXException re-thrown exception
- * @see org.xml.sax.helpers.DefaultHandler#error(org.xml.sax.SAXParseException)
- */
- public void error(SAXParseException e) throws SAXException {
- log.debug("Warning: \n" + printInfo(e));
- throw new SAXException(e);
- }
-
- /**
- * @param e parsing exception
- * @throws SAXException re-thrown exception
- * @see org.xml.sax.helpers.DefaultHandler#fatalError(org.xml.sax.SAXParseException)
- */
- public void fatalError(SAXParseException e) throws SAXException {
- log.debug("Warning: \n" + printInfo(e));
- throw new SAXException(e);
- }
-
- private String printInfo(SAXParseException e) {
- StringBuffer sb = new StringBuffer();
- sb.append(" Public ID: \n");
- sb.append(e.getPublicId());
- sb.append(" System ID: \n");
- sb.append(e.getSystemId());
- sb.append(" Line number: \n");
- sb.append(e.getLineNumber());
- sb.append(" Column number: \n");
- sb.append(e.getColumnNumber());
- sb.append(" Message: \n");
- sb.append(e.getMessage());
-
- return sb.toString();
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource.java
deleted file mode 100644
index 3bf0184f4..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * 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.io.xml;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.io.InputSource;
-import org.springframework.batch.io.Skippable;
-import org.springframework.batch.io.exception.BatchCriticalException;
-import org.springframework.batch.io.exception.BatchEnvironmentException;
-import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
-import org.springframework.batch.restart.GenericRestartData;
-import org.springframework.batch.restart.RestartData;
-import org.springframework.batch.restart.Restartable;
-import org.springframework.batch.statistics.StatisticsProvider;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.io.Resource;
-import org.springframework.transaction.support.TransactionSynchronization;
-import org.springframework.util.Assert;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * XmlInputTemplate is implementation of {@link InputSource} which
- * processes XML input independently of technologies used for parsing XML files
- * and mapping XML to value objects. It has references only to interfaces, not
- * concrete implementations. It uses {@link ObjectInputFactory} interface for
- * getting {@link ObjectInput}, which is interface for retrieving value objects
- * from the input stream. So it's easy to plug-in any technology for parsing XML
- * and mapping it to value object by implementing these interfaces. See
- * implementation of {@link ObjectInputFactory} interface, which uses StAX
- * as XML parser and XStream as XML-to-ValueObjects mapper.
- *
- * Current implementation also allows validation of XML file against XSD schema.
- * This validation is realized by using SAXParser. Validation of the whole XML
- * file is performed in the {@link #open()} method, because SAXParser does not
- * allow to process only part of the XML, then stop and continue later with
- * processing. This type of processing can be realized by using any pull-parser
- * (e.g. StAX), but StAX API does not provide methods for validation. So be
- * careful when using this validation, because it means to parse XML twice: once
- * to validate and once to read and map. Validation can be turned on/off by
- * {@link #setValidating(boolean)} method. By default is validation turned off.
- * This validation should be refactored in future. Validation should be provided
- * either by {@link ObjectInput} or some new interface.
- *
- * This input template also provides restart, skip, statistics and transaction
- * features by implementing corresponding interfaces.
- *
- * @author peter.zozom
- * @see ObjectInput
- * @see ObjectInputFactory
- */
-public class XmlInputSource implements InputSource, Skippable, Restartable,
- TransactionSynchronization, StatisticsProvider, InitializingBean, DisposableBean {
-
- private static final Log log = LogFactory.getLog(XmlInputSource.class);
-
- private static final String DEFAULT_ENCODING = "UTF-8";
-
- /*
- * Unique source name used to construct this xml reader input source -
- * specified by the configuration file.
- */
- private String sourceName = null;
-
- private Resource resource;
-
- private ObjectInputFactory inputFactory;
-
- private boolean validating = false;
-
- private String encoding = DEFAULT_ENCODING;
-
- private Properties statistics = new Properties();
-
- public static final String READ_STATISTICS_NAME = "Read";
-
- public static final String RESTART_DATA_NAME = "xmlinputtemplate.currentRecordCount";
-
- private InputState state = new InputState();
-
- // accessor method for the threadlocal state object
- private InputState getState() {
- return (InputState) state;
- }
-
- public void afterPropertiesSet() throws Exception {
- Assert.notNull(resource);
- Assert.state(resource.exists(), "Input resource does not exist: ["+resource+"]");
- }
-
- /**
- * Setter for input resource.
- *
- * @param resource
- */
- public void setResource(Resource resource) {
- this.resource = resource;
- }
-
- /**
- * Return current status of the validation flag
- *
- * @return
- */
- public boolean isValidating() {
- return validating;
- }
-
- /**
- * Turn validation on/off for the input source
- *
- * @param validating
- */
- public void setValidating(boolean validating) {
- this.validating = validating;
- }
-
- /**
- * Initialize the input source and validates input XML file if validation is
- * turned on. This method should be called for each thread using same
- * XmlInputTemplate instance.
- *
- * @see org.springframework.batch.item.ResourceLifecycle#open()
- */
- public void open() {
- InputState is = getState();
- if (!is.initialized) {
- registerSynchronization();
- initializeObjectInput();
- }
- }
-
- /**
- * Registers object for transaction synchronization
- */
- protected void registerSynchronization() {
- BatchTransactionSynchronizationManager.registerSynchronization(this);
- }
-
- /**
- * Close the input source
- *
- * @see org.springframework.batch.item.ResourceLifecycle#close()
- */
- public void close() {
- InputState is = getState();
- is.objectInput.close();
- is.initialized = false;
- }
-
- /**
- * Calls close to ensure that bean factories can close and always release
- * resources.
- *
- * @see org.springframework.beans.factory.DisposableBean#destroy()
- */
- public void destroy() throws Exception {
- close();
- }
-
- /*
- * Initializes and obtains the ObjectInput from the ObjectInputFactory and
- * validates input XML file if validation is turned on.
- */
- private void initializeObjectInput() {
- InputState is = getState();
- is.initialized = false;
-
- if (isValidating()) {
- validateInputFile(resource);
- }
-
- is.objectInput = inputFactory.createObjectInput(resource, getEncoding());
-
- is.lastCommitPoint = is.objectInput.position();
- is.initialized = true;
- }
-
- /*
- * Validates input xml file against XSD schema.
- *
- * @param file File to be validated
- */
- private void validateInputFile(Resource resource) {
- try {
- SAXParserFactory factory = getSaxFactory();
-
- factory.setValidating(true);
- factory.setNamespaceAware(true);
- factory.setFeature("http://apache.org/xml/features/validation/schema", true);
-
- SAXParser parser = factory.newSAXParser();
- DefaultHandler handler = getDefaultHandler();
- parser.parse(resource.getInputStream(), handler, resource.getURL().toExternalForm());
- }
- catch (ParserConfigurationException pce) {
- log.error(pce);
- throw new BatchEnvironmentException("Unable to configure parser.", pce);
- }
- catch (SAXException se) {
- log.error(se);
- throw new BatchEnvironmentException("Error during parsing the input file.", se);
- }
- catch (IOException ioe) {
- log.error(ioe);
- throw new BatchEnvironmentException("Error reading input file.", ioe);
- }
- }
-
- /*
- * Get default handler for xml validation
- *
- * @return instance of DefaultHandler
- */
- private DefaultHandler getDefaultHandler() {
- return new XmlErrorHandler();
- }
-
- /*
- * Creates instance of SAXParserFactory
- *
- * @return instance of SAXParserFactory @throws FactoryConfigurationError
- */
- protected SAXParserFactory getSaxFactory() throws FactoryConfigurationError {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- return factory;
- }
-
- /**
- * Return the next record from the input file and map it to a value object.
- *
- * @return next record if found or null to signal the end of
- * the input data.
- * @see org.springframework.batch.io.InputSource
- */
- public Object read() {
- InputState is = getState();
-
- if (!is.initialized) {
- open();
- }
-
- Object result = null;
-
- do {
- result = readNextRecord();
- is.currentRecordCount++;
- } while (is.skipLines.contains(new Integer(is.currentRecordCount)));
-
- return result;
- }
-
- /*
- * Reads next record
- *
- * @return next record
- */
- private Object readNextRecord() {
- InputState is = getState();
- Object result;
-
- try {
- result = is.objectInput.readObject();
- }
- catch (EOFException eofe) {
- log.debug("Parsing of XML finished");
- result = null;
- }
- catch (IOException ioe) {
- log.error(ioe);
- throw new BatchCriticalException("Unable to read from ObjectInputStream", ioe);
- }
- catch (ClassNotFoundException cnfe) {
- log.error(cnfe);
- throw new BatchEnvironmentException("Bad xml mapping", cnfe);
- }
-
- return result;
- }
-
- /**
- * Postprocess after transaction commit/rollback. Called from transaction
- * manager.
- *
- * @param status indicates whether it was a rollback or commit
- */
- public void afterCompletion(int status) {
- if (status == TransactionSynchronization.STATUS_COMMITTED) {
- transactionComitted();
- }
- else if (status == TransactionSynchronization.STATUS_ROLLED_BACK) {
- transactionRolledback();
- }
- }
-
- /*
- * Postprocess after transaction commit
- */
- private void transactionComitted() {
- InputState is = getState();
- is.skipLines = new ArrayList();
- is.lastCommitPoint = is.objectInput.position();
- }
-
- /*
- * Postprocess after transaction rollback
- */
- private void transactionRolledback() {
- InputState is = getState();
- is.currentRecordCount = 0;
-
- // remember list of skipped lines and last commit point
- List sl = is.skipLines;
- long cp = is.lastCommitPoint;
- // XMLStreamReader is forward only, so we need to start from beginnig
- close();
- // this will also reset skipLines
- open();
- // so after init get new InputState and set skipLines and
- // lastCommitPoint
- is = getState();
- is.skipLines = sl;
- is.lastCommitPoint = cp;
-
- long currentLocation = is.objectInput.position();
- while (currentLocation < is.lastCommitPoint) {
- readNextRecord();
- is.currentRecordCount++;
- currentLocation = is.objectInput.position();
- }
- }
-
- /**
- * Returns name of the input source.
- *
- * @return input source name
- */
- public String getName() {
- return sourceName;
- }
-
- /**
- * Sets name of the input source.
- *
- */
- public void setName(String newName) {
- this.sourceName = newName;
- }
-
- /**
- * This method returns the restart data for the input source. It returns the
- * current record count which can be used to re-initialze the batch job in
- * case of restart.
- *
- * @see org.springframework.batch.container.Restartable#getRestartData()
- */
- public RestartData getRestartData() {
- Properties restartData = new Properties();
- restartData.setProperty(RESTART_DATA_NAME, String.valueOf(getState().currentRecordCount));
- return new GenericRestartData(restartData);
- }
-
- /**
- * This method initializes the input source for restart. It opens the input
- * file and position the xml reader according to information provided by the
- * restart data.
- *
- * @param restartData restart data information
- * @see org.springframework.batch.container.Restartable#initForRestart(java.lang.Object)
- */
- public void restoreFrom(RestartData restartData) {
- if (restartData == null || restartData.getProperties() == null ||
- restartData.getProperties().getProperty(RESTART_DATA_NAME) == null) {
- return;
- }
-
- InputState is = getState();
- int startAtRecord = Integer.parseInt(restartData.getProperties().getProperty(RESTART_DATA_NAME));
-
- for (int i = 0; i < startAtRecord; i++) {
- readNextRecord();
- }
-
- is.currentRecordCount = startAtRecord;
- }
-
- /**
- * Skip the current record.
- * @see org.springframework.batch.container.advice.SkipAdvice#skip()
- */
- public void skip() {
- InputState is = getState();
- is.skipLines.add(new Integer(is.currentRecordCount));
- }
-
- /**
- * Get encoding.
- * @return the character encoding of the stream
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * Set encoding.
- * @param encoding the character encoding of the stream
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Get statistics for the processed input.
- * @return actual statistics for the processed input
- * @see org.springframework.batch.container.advice.StatisticsAdvice#getStatistics()
- */
- public Properties getStatistics() {
-
- statistics.setProperty(READ_STATISTICS_NAME, String.valueOf(getState().currentRecordCount));
- return statistics;
- }
-
- /**
- * Set the ObjectInputFactory which is used for retrieving ObjectInput
- * @param inputFactory the factory to use
- */
- public void setInputFactory(ObjectInputFactory inputFactory) {
- this.inputFactory = inputFactory;
- }
-
- /* *** Intentionally unimplemented methods *** */
-
- public void suspend() {
- }
-
- public void resume() {
- }
-
- public void beforeCommit(boolean arg0) {
- }
-
- public void beforeCompletion() {
- }
-
- public void afterCommit() {
- }
-
- /**
- * Value object holding state of the input source.
- */
- private static class InputState {
- boolean initialized = false;
-
- int currentRecordCount = 0;
-
- ObjectInput objectInput;
-
- List skipLines = new ArrayList();
-
- long lastCommitPoint;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource2.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource2.java
deleted file mode 100644
index 9a9b867d0..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/XmlInputSource2.java
+++ /dev/null
@@ -1,397 +0,0 @@
-package org.springframework.batch.io.xml;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.batch.io.InputSource;
-import org.springframework.batch.io.Skippable;
-import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
-import org.springframework.batch.restart.GenericRestartData;
-import org.springframework.batch.restart.RestartData;
-import org.springframework.batch.restart.Restartable;
-import org.springframework.batch.statistics.StatisticsProvider;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.dao.DataAccessResourceFailureException;
-import org.springframework.oxm.Unmarshaller;
-import org.springframework.transaction.support.TransactionSynchronization;
-import org.springframework.transaction.support.TransactionSynchronizationAdapter;
-import org.springframework.util.Assert;
-
-/**
- *
XmlInputSource2 is {@link InputSource} implementation which processes XML input file - * and maps XML elements to objects. It uses {@link org.springframework.oxm.Unmarshaller} - * for parsing XML and for OXM mapping. This allows to plug-in various OXM frameworks. - * Spring-ws' OXM package provides implementations for Castor, JAXB, JiBX, - * XmlBeans and XStream.
- * - *{@link org.springframework.oxm.Unmarshaller} always processes whole XML - * input at once, but we need to process only one record per one module - * iteration. Therefore XmlInputSource2 uses {@link UnmarshallerAdapter} which cuts XML - * into smaller pieces (each piece contains a single record) and calls the unmarshaller - * to process only this single piece (record).
- * - *XmlInputSource2 configuration
- *Mandatory bean properties: - *
Optional bean properties (if not set, default value is used): - *
Limitations: - *
<folder> - * <folder></folder> <- this is not supported - * <file></file> - * </folder> - * <folder> - * <file></file> - * </folder>- *
- * This output template also provides restart, statistics and transaction - * features by implementing corresponding 'advice' interfaces. - * - * @author peter.zozom - * @see ObjectOutput - * @see ObjectOutputFactory - */ -public class XmlOutputSource implements OutputSource, Restartable, StatisticsProvider, TransactionSynchronization, - DisposableBean { - private static final Log log = LogFactory.getLog(XmlOutputSource.class); - - private static final String DEFAULT_ENCODING = "UTF-8"; - - private ObjectOutputFactory outputFactory; - - private String encoding = DEFAULT_ENCODING; - - private Resource resource; - - private Properties statistics = new Properties(); - - /* - * Unique source name used to construct this xml reader input source - - * specified by the configuration file. - */ - private String sourceName = null; - - public static final String WRITTEN_STATISTICS_NAME = "Written"; - - public static final String RESTART_DATA_NAME = "xmloutputtemplate.currentRecordCount"; - - private OutputState state; - - // Accessor method for the state object - private OutputState getState() { - if (state == null) { - state = new OutputState(); - } - return state; - } - - public void afterPropertiesSet() throws Exception { - Assert.notNull(resource); - Assert.state(resource.getFile().canWrite(), "Resource is not writable"); - } - - /** - * Setter for resource. Represents a file that can be written. - * - * @param resource - */ - public void setResource(Resource resource) { - this.resource = resource; - } - - /** - * Initialize the output source. This method should be called for each - * thread using same XmlOutputTemplate instance. - * - * @see org.springframework.batch.item.ResourceLifecycle#open() - */ - public void open() { - - OutputState os = getState(); - if (!os.initialized) { - } - } - - /** - * Registers object for transaction synchronization - */ - protected void registerSynchronization() { - BatchTransactionSynchronizationManager.registerSynchronization(this); - } - - /** - * Just calls {@link #close()} so that bean factories will clean up - * resources correctly. - * - * @see org.springframework.beans.factory.DisposableBean#destroy() - */ - public void destroy() throws Exception { - close(); - } - - /** - * Close the output source - * - * @see org.springframework.batch.item.ResourceLifecycle#close() - */ - public void close() { - OutputState os = getState(); - try { - if (os != null && os.objectOutput != null) { - os.objectOutput.close(); - } - } - finally { - if (os != null) { - os.initialized = false; - os.restarted = false; - } - } - } - - /* - * Initializes and obtains a ObjectOutput from ObjectOutputFactory. - */ - private void initializeXmlWriter() { - OutputState os = getState(); - os.initialized = false; - File file; - - try { - file = resource.getFile(); - - // If the output source was restarted, keep existing file. - // If the output source was not restarted, check following: - // - if the file should be deleted, delete it if it was exiting and - // create blank file, - // - if the file should not be deleted, if it already exists, throw - // an exception, - // - if the file was not existing, create new. - if (!os.restarted) { - if (file.exists()) { - if (os.shouldDeleteIfExists) { - file.delete(); - } - else { - throw new BatchEnvironmentException("Resource already exists: " + resource); - } - } - file.createNewFile(); - } - - } - catch (IOException ioe) { - log.error(ioe); - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", ioe); - } - - os.objectOutput = outputFactory.createObjectOutput(resource, encoding); - - if (os.restarted) { - os.objectOutput.afterRestart(new Long(os.lastMarkedByteOffsetPosition)); - checkFileSize(); - } - - os.initialized = true; - } - - /** - * Write the value object to output xml stream. - * @param output the value object - * @see org.springframework.batch.io.OutputSource#write(java.lang.Object) - */ - public void write(Object output) { - OutputState os = getState(); - if (!os.initialized) { - open(); - initializeXmlWriter(); - } - - try { - os.objectOutput.writeObject(output); - os.objectsWritten++; - } - catch (IOException ioe) { - log.error(ioe); - throw new DataAccessResourceFailureException("Unable to write to ObjectOutputStream", ioe); - } - } - - /** - * Return the name of the output source. - */ - public void setName(String newName) { - this.sourceName = newName; - } - - /** - * Set the name of the output source. - * - * @see org.springframework.batch.restart.Restartable#getName() - */ - public String getName() { - return sourceName; - } - - /** - * Postprocess after transaction commit/rollback. Called from transaction - * manager. - * - * @param status indicates whether it was a rollback or commit - */ - public void afterCompletion(int status) { - if (status == TransactionSynchronization.STATUS_COMMITTED) { - transactionComitted(); - } - else if (status == TransactionSynchronization.STATUS_ROLLED_BACK) { - transactionRolledback(); - } - } - - /* - * Postprocess after transaction commit - */ - private void transactionComitted() { - OutputState os = getState(); - - os.objectOutput.flush(); - os.lastMarkedByteOffsetPosition = this.position(); - } - - /* - * Postprocess after transaction rollback - */ - private void transactionRolledback() { - checkFileSize(); - resetPositionForRestart(); - } - - /* - * This method removes any information in the file before this reset point. - * - * @param resetByteOffset a long integer representing the byte offset to - * trunction and reposition the file cursor to for restarting. - */ - private void resetPositionForRestart() { - OutputState os = getState(); - os.objectOutput.truncate(os.lastMarkedByteOffsetPosition); - os.objectOutput.position(os.lastMarkedByteOffsetPosition); - } - - /* - * Checks (on setState) to make sure that the current output file's size is - * not smaller than the last saved commit point. If it is, then the file has - * been damaged in some way and whole task must be started over again from - * the beginning. - */ - private void checkFileSize() { - OutputState os = getState(); - long size = -1; - - size = os.objectOutput.size(); - - Assert.state(size >= os.lastMarkedByteOffsetPosition, "Current file size is smaller than size at last commit"); - } - - /* - * Return the byte offset position of the cursor in the output file as a - * long integer. - * - * @return long integer representing the byte offset position of the cursor - * in the output file. - */ - private long position() { - OutputState os = getState(); - return os.objectOutput.position(); - } - - /** - * Get statistics for the processed output. - * @return actual statistics for the processed output - * @see org.springframework.batch.container.advice.StatisticsAdvice#getStatistics() - */ - public Properties getStatistics() { - - statistics.setProperty(WRITTEN_STATISTICS_NAME, new Long(getState().objectsWritten).toString()); - return statistics; - } - - /** - * Set encoding. - * @param encoding the character encoding of the stream - */ - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - /** - * Set the ObjectOutputFactory which is used for retrieving ObjectOutput - * @param outputFactory the factory to use - */ - public void setOutputFactory(ObjectOutputFactory outputFactory) { - this.outputFactory = outputFactory; - } - - /* *** Intentionally unimplemented methods *** */ - - public void suspend() { - } - - public void resume() { - } - - public void beforeCommit(boolean arg0) { - } - - public void beforeCompletion() { - } - - public void afterCommit() { - } - - /* - * Value object holding state of the output source. - */ - private static class OutputState { - private boolean initialized = false; - - private ObjectOutput objectOutput; - - private long lastMarkedByteOffsetPosition = 0; - - private long objectsWritten = 0; - - private boolean shouldDeleteIfExists = true; - - private boolean restarted = false; - - } - - public void restoreFrom(RestartData data) { - if (data == null || data.getProperties() == null || - data.getProperties().getProperty(RESTART_DATA_NAME) == null) { - return; - } - - OutputState os = getState(); - os.lastMarkedByteOffsetPosition = Long.parseLong(data.getProperties().getProperty(RESTART_DATA_NAME)); - os.restarted = true; - initializeXmlWriter(); - } - - /** - * This method returns the restart data for the output source. It returns - * the current byte offset position of the cursor in the output file which - * can be used to re-initialze the batch job in case of restart. - * - * @see org.springframework.batch.container.Restartable#getRestartData() - */ - - public RestartData getRestartData() { - Properties restartData = new Properties(); - restartData.setProperty(RESTART_DATA_NAME, new Long(position()).toString()); - return new GenericRestartData(restartData); - } - - /** - * This method initializes the output source for restart. It opens the - * output file and position the xml writer according to information provided - * by the restart data. - * - * @param restartData restart data information - * @see org.springframework.batch.container.advice.RestartAdvice#initForRestart(java.lang.Object) - */ - public void initForRestart(Object restartData) { - - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/package.html b/infrastructure/src/main/java/org/springframework/batch/io/xml/package.html deleted file mode 100644 index 8e827d2e0..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/package.html +++ /dev/null @@ -1,7 +0,0 @@ - -
--Infrastructure implementations of io xml concerns. -
- - diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeAlias.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeAlias.java deleted file mode 100644 index 250bbc9b0..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeAlias.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Represents alias for an attribute. - * @author peter.zozom - */ -public class AttributeAlias { - - private String alias; - - private String attributeName; - - /** - * @return the alias - */ - public String getAlias() { - return alias; - } - - /** - * Set alias for attribute - * @param alias the alias itself - */ - public void setAlias(String alias) { - this.alias = alias; - } - - /** - * @return the attribute name - */ - public String getAttributeName() { - return attributeName; - } - - /** - * Set the attribute name. - * @param attributeName the name of the attribute - */ - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeProperties.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeProperties.java deleted file mode 100644 index 921a849c7..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/AttributeProperties.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Defines which XML attribute to use for a field or a specific type. - * @author peter.zozom - */ -public class AttributeProperties { - - private String type; - - private String fieldName; - - /** - * @return the field name which will be rendered as XML attribute - */ - public String getFieldName() { - return fieldName; - } - - /** - * Set the field to be rendered as XML attribute - * @param fieldName the name of the field - */ - public void setFieldName(String fieldName) { - this.fieldName = fieldName; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - /** - * Set type to be used for XML attribute. - * @param type the name of the type to be rendered as XML attribute - */ - public void setType(String type) { - this.type = type; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ClassAlias.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ClassAlias.java deleted file mode 100644 index 254d4e207..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ClassAlias.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Represents mapping of a class to a shorter name to be used in XML elements. - * @author peter.zozom - */ -public class ClassAlias { - - private String name; - - private String type; - - private String defaultImplementation; - - /** - * @return the default implementation of the type - */ - public String getDefaultImplementation() { - return defaultImplementation; - } - - /** - * Set default implementation of type to use. - * @param defaultImplementation Default implementation of type to use if no - * other specified. - */ - public void setDefaultImplementation(String defaultImplementation) { - this.defaultImplementation = defaultImplementation; - } - - /** - * @return short name for the type - */ - public String getName() { - return name; - } - - /** - * Set short name. - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return aliased type - */ - public String getType() { - return type; - } - - /** - * Set aliased type. - * @param type type to be aliased - */ - public void setType(String type) { - this.type = type; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ConverterProperties.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ConverterProperties.java deleted file mode 100644 index 0b977011a..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ConverterProperties.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.io.xml.xstream; - -import com.thoughtworks.xstream.XStream; - -/** - * Represents converter to be registered for parsing. Converter acts as a - * strategy for converting a particular type of class to XML and back again. - * - * @author peter.zozom - */ - -public class ConverterProperties { - private String className; - - private int priority = XStream.PRIORITY_NORMAL; - - /** - * @return converter class name - */ - protected String getClassName() { - return className; - } - - /** - * Set converter class name. - * @param className converter class name - */ - protected void setClassName(String className) { - this.className = className; - } - - /** - * @return converter priority - */ - protected int getPriority() { - return priority; - } - - /** - * @param priority converter priority - */ - protected void setPriority(int priority) { - this.priority = priority; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/DefaultImplementation.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/DefaultImplementation.java deleted file mode 100644 index c4e452118..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/DefaultImplementation.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Defines default implementation of a class which should associated with an - * object. Whenever XStream encounters an instance of this type, it will use the - * default implementation instead. For example, java.util.ArrayList is the - * default implementation of java.util.List. - * @author peter.zozom - */ -public class DefaultImplementation { - - private String defaultImpl; - - private String type; - - /** - * @return class name of the default implementation - */ - public String getDefaultImpl() { - return defaultImpl; - } - - /** - * Set the class name of the default implementation which should be - * associated with ofType. - * @param defaultImpl class name of the default implementation - */ - public void setDefaultImpl(String defaultImpl) { - this.defaultImpl = defaultImpl; - } - - /** - * @return type name associated with default implementation - */ - public String getType() { - return type; - } - - /** - * Set type name which should be associated with default implementation. - * @param ofType type name - */ - public void setType(String ofType) { - this.type = ofType; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/FieldAlias.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/FieldAlias.java deleted file mode 100644 index 4b842dddb..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/FieldAlias.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Represents an alias for a field name. - * @author peter.zozom - */ -public class FieldAlias { - private String aliasName; - - private String type; - - private String fieldName; - - /** - * @return field alias - */ - public String getAliasName() { - return aliasName; - } - - /** - * Set field alias name. - * @param aliasName the alias itself - */ - public void setAliasName(String aliasName) { - this.aliasName = aliasName; - } - - /** - * @return field name to be aliased - */ - public String getFieldName() { - return fieldName; - } - - /** - * Set the name of the field to be aliased. - * @param fieldName the name of the field to be aliased - */ - public void setFieldName(String fieldName) { - this.fieldName = fieldName; - } - - /** - * @return the type that declares the field - */ - public String getType() { - return type; - } - - /** - * Set the type that declares the field. - * @param type the type that declares the field - */ - public void setType(String type) { - this.type = type; - } -} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ImplicitCollection.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ImplicitCollection.java deleted file mode 100644 index 8a93d1aaa..000000000 --- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/ImplicitCollection.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.io.xml.xstream; - -/** - * Represents implicit collection definition. Implicit collection is used for: - *java.util.ArrayList.
- * @param fieldName name of the field in the ownerType
- */
- protected void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- /**
- * @return element name of the implicit collection
- */
- protected String getItemFieldName() {
- return itemFieldName;
- }
-
- /**
- * Set element name of the implicit collection.
- * @param itemFieldName element name of the implicit collection
- */
- protected void setItemFieldName(String itemFieldName) {
- this.itemFieldName = itemFieldName;
- }
-
- /**
- * @return type of the items to be part of this collection
- */
- protected String getItemType() {
- return itemType;
- }
-
- /**
- * Set yype of the items to be part of this collection (aliased with
- * ItemFieldName, if provided).
- * @param itemType type of the items to be part of this collection
- */
- protected void setItemType(String itemType) {
- this.itemType = itemType;
- }
-
- /**
- * @return class owning the implicit collection
- */
- protected String getOwnerType() {
- return ownerType;
- }
-
- /**
- * Set class that owns implicit collection.
- * @param ownerType class owning the implicit collection
- */
- protected void setOwnerType(String ownerType) {
- this.ownerType = ownerType;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/Mapping.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/Mapping.java
deleted file mode 100644
index 7833ef4c5..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/Mapping.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-/**
- * Represents a mapping of qualified tag names to Java class names allowing
- * class aliases and namespace aware mappings of qualified tag names to class
- * names.
- * @author peter.zozom
- * @see javax.xml.namespace.QName
- */
-public class Mapping {
-
- private String namespaceURI;
-
- private String localPart;
-
- private String prefix;
-
- private String className;
-
- /**
- * @return class name
- */
- public String getClassName() {
- return className;
- }
-
- /**
- * Set Java type which will be mapped.
- * @param className type name to be mapped
- */
- public void setClassName(String className) {
- this.className = className;
- }
-
- /**
- * @return local part of the qualified name
- */
- public String getLocalPart() {
- return localPart;
- }
-
- /**
- * Set local part of the qualified name.
- * @param localPart local part of the qualified name
- * @see javax.xml.namespace.QName
- */
- public void setLocalPart(String localPart) {
- this.localPart = localPart;
- }
-
- /**
- * @return namespace URI of the qualified name
- */
- public String getNamespaceURI() {
- return namespaceURI;
- }
-
- /**
- * Set namespace URI of the qualified name.
- * @param namespaceURI namespace URI of the qualified name
- * @see javax.xml.namespace.QName
- */
- public void setNamespaceURI(String namespaceURI) {
- this.namespaceURI = namespaceURI;
- }
-
- /**
- * @return prefix of the qualified name
- */
- public String getPrefix() {
- return prefix;
- }
-
- /**
- * Set prefix of the qualified name.
- * @param prefix prefix of the qualified name
- * @see javax.xml.namespace.QName
- */
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/OmmitedField.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/OmmitedField.java
deleted file mode 100644
index 03ef27a49..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/OmmitedField.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-/**
- * Defines a field which shouldn't be serialized. To omit a field you must
- * always provide the declaring type and not necessarily the type that is
- * converted.
- * @author peter.zozom
- *
- */
-public class OmmitedField {
- private String type;
-
- private String fieldName;
-
- /**
- * @return field which should be ommited
- */
- protected String getFieldName() {
- return fieldName;
- }
-
- /**
- * Set field which should be ommited.
- * @param fieldName field which should be ommited
- */
- protected void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- /**
- * @return declaring type of the ommited field
- */
- protected String getType() {
- return type;
- }
-
- /**
- * Set declaring type of the ommited field.
- * @param type declaring type of the ommited field
- */
- protected void setType(String type) {
- this.type = type;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/TypeAlias.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/TypeAlias.java
deleted file mode 100644
index 68a6f3d1b..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/TypeAlias.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-/**
- * Represents mapping a type to a shorter name to be used in XML elements. Any
- * class that is assignable to this type will be aliased to the same name.
- * @author peter.zozom
- */
-public class TypeAlias {
-
- private String name;
-
- private String type;
-
- /**
- * @return short name for the type
- */
- public String getName() {
- return name;
- }
-
- /**
- * Set short name.
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return aliased type
- */
- public String getType() {
- return type;
- }
-
- /**
- * Set aliased type.
- * @param type type to be aliased
- */
- public void setType(String type) {
- this.type = type;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfiguration.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfiguration.java
deleted file mode 100644
index 98e51d53b..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfiguration.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-import java.util.List;
-import java.util.Map;
-
-import com.thoughtworks.xstream.XStream;
-
-/**
- * Value object, which holds configuration for XStream.
- *
- * @author peter.zozom
- * @author Dave Syer
- *
- * @see XStreamConfigurationFactoryBean
- * @see Mapping
- * @see ClassAlias
- * @see TypeAlias
- * @see FieldAlias
- * @see AttributeAlias
- * @see AttributeProperties
- * @see ConverterProperties
- * @see XStream#setMode(int)
- * @see ImplicitCollection
- * @see OmmitedField
- * @see XStream#addImmutableType(Class)
- * @see DefaultImplementation
- */
-public class XStreamConfiguration {
-
- private List mappings = null;
-
- private String rootElementName = null;
-
- private Map rootElementAttributes;
-
- private List classAliases = null;
-
- private List typeAliases = null;
-
- private List fieldAliases = null;
-
- private List attributeAliases = null;
-
- private List attributes = null;
-
- private List converters = null;
-
- private int mode = XStream.XPATH_RELATIVE_REFERENCES;
-
- private List implicitCollections = null;
-
- private List ommitedFields = null;
-
- private List immutableTypes = null;
-
- private List defaultImplementations = null;
-
- /**
- * @return list of the {@link DefaultImplementation} objects
- */
- public List getDefaultImplementations() {
- return defaultImplementations;
- }
-
- /**
- * Set list of default implementations.
- * @param defaultImplementations list of the {@link DefaultImplementation}
- * objects
- * @see DefaultImplementation
- */
- public void setDefaultImplementations(List defaultImplementations) {
- this.defaultImplementations = defaultImplementations;
- }
-
- /**
- * @return list of the immutable type names
- */
- public List getImmutableTypes() {
- return immutableTypes;
- }
-
- /**
- * Set list of immutable types.
- * @param immutableTypes list of the immutable type names
- * @see XStream#addImmutableType(Class)
- */
- public void setImmutableTypes(List immutableTypes) {
- this.immutableTypes = immutableTypes;
- }
-
- /**
- * @return list of the {@link AttributeAlias} objects
- */
- public List getAttributeAliases() {
- return attributeAliases;
- }
-
- /**
- * Set list of attribute aliases.
- * @param attributeAliases list of the {@link AttributeAlias} objects
- * @see AttributeAlias
- */
- public void setAttributeAliases(List attributeAliases) {
- this.attributeAliases = attributeAliases;
- }
-
- /**
- * @return list of the {@link AttributeProperties} objects
- */
- public List getAttributes() {
- return attributes;
- }
-
- /**
- * Set list of attribute properties.
- * @param attributes list of the {@link AttributeProperties}
- * objects
- * @see AttributeProperties
- */
- public void setAttributes(List attributes) {
- this.attributes = attributes;
- }
-
- /**
- * @return the classAliases
- */
- public List getClassAliases() {
- return classAliases;
- }
-
- /**
- * Set list of class aliases.
- * @param classAliases the classAliases to set
- * @see ClassAlias
- */
- public void setClassAliases(List classAliases) {
- this.classAliases = classAliases;
- }
-
- /**
- * @return list of the {@link ConverterProperties} objects
- */
- public List getConverters() {
- return converters;
- }
-
- /**
- * Set list of custom converters.
- * @param converters list of the {@link ConverterProperties} objects
- * @see ConverterProperties
- */
- public void setConverters(List converters) {
- this.converters = converters;
- }
-
- /**
- * @return the fieldAliases
- */
- public List getFieldAliases() {
- return fieldAliases;
- }
-
- /**
- * Set list of field aliases.
- * @param fieldAliases the list of fieldAliases to set
- * @see FieldAlias
- */
- public void setFieldAliases(List fieldAliases) {
- this.fieldAliases = fieldAliases;
- }
-
- /**
- * @return list of the {@link ImplicitCollections} objects
- */
- public List getImplicitCollections() {
- return implicitCollections;
- }
-
- /**
- * Set list of implicit collection definitions.
- * @param implicitCollections list of the {@link ImplicitCollections}
- * objects
- * @see ImplicitCollection
- */
- public void setImplicitCollections(List implicitCollections) {
- this.implicitCollections = implicitCollections;
- }
-
- /**
- * @return list of the {@link Mapping} objects
- */
- public List getMappings() {
- return mappings;
- }
-
- /**
- * Set list of "qualified tag name - to - class name" mappigs.
- * @param mappings list of the {@link Mapping} objects
- * @see Mapping
- */
- public void setMappings(List mappings) {
- this.mappings = mappings;
- }
-
- /**
- * @return the actual mode
- */
- public int getMode() {
- return mode;
- }
-
- /**
- * Set mode for dealing with duplicate references. If not provided, default
- * value is used ({@link XStream#XPATH_RELATIVE_REFERENCES}).
- * @param mode the mode to set
- * @see XStream#setMode(int)
- */
- public void setMode(int mode) {
- this.mode = mode;
- }
-
- /**
- * @return list of the {@link OmmitedFields} objects
- */
- public List getOmmitedFields() {
- return ommitedFields;
- }
-
- /**
- * Set list of ommited fields.
- * @param ommitedFields list of the {@link OmmitedFields} objects
- * @see OmmitedField
- */
- public void setOmmitedFields(List ommitedFields) {
- this.ommitedFields = ommitedFields;
- }
-
- /**
- * @return the root element attributes
- */
- public Map getRootElementAttributes() {
- return rootElementAttributes;
- }
-
- /**
- * Set attributes of root element. Each Map entry has key = "attribute name"
- * and value = "attribute value".
- * @param rootElementAttributes map of the root element attributes
- */
- public void setRootElementAttributes(Map rootElementAttributes) {
- this.rootElementAttributes = rootElementAttributes;
- }
-
- /**
- * @return the root element name
- */
- public String getRootElementName() {
- return rootElementName;
- }
-
- /**
- * Set name of the root element. Valid only for writing to XML.
- * @param rootElementName the root element name
- */
- public void setRootElementName(String rootElementName) {
- this.rootElementName = rootElementName;
- }
-
- /**
- * @return the list of the {@link TypeAlias} objects
- */
- public List getTypeAliases() {
- return typeAliases;
- }
-
- /**
- * Set list of type aliases.
- * @param typeAliases list of the {@link TypeAlias} objects
- * @see TypeAlias
- */
- public void setTypeAliases(List typeAliases) {
- this.typeAliases = typeAliases;
- }
-
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfigurationFactoryBean.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfigurationFactoryBean.java
deleted file mode 100644
index b3f17dd31..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamConfigurationFactoryBean.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map.Entry;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.io.exception.BatchEnvironmentException;
-import org.springframework.beans.factory.config.AbstractFactoryBean;
-import org.springframework.core.io.Resource;
-
-import com.thoughtworks.xstream.XStream;
-
-/**
- * Factory creates {@link XStreamConfiguration} object, which hold XStream's
- * configuration settings. These settings are read from provided configuration
- * XML file.
- *
- * @author peter.zozom
- * @author Dave Syer
- */
-public class XStreamConfigurationFactoryBean extends AbstractFactoryBean {
-
- private Log log = LogFactory.getLog(XStreamConfigurationFactoryBean.class);
-
- private Resource resource;
-
- /**
- * Creates {@link XStreamConfiguration} object from XStream's config file.
- * @return XStream's configuration settings.
- */
- private XStreamConfiguration getXStreamConfiguration() {
-
- XStream stream = new XStream();
- setConfigAliases(stream);
-
- XStreamConfiguration xsc;
- try {
- InputStream is = resource.getInputStream();
- xsc = (XStreamConfiguration) stream.fromXML(is);
- is.close();
- }
- catch (IOException ioe) {
- log.debug(ioe);
- throw new BatchEnvironmentException("Could not read XStream mapping file.", ioe);
- }
-
- return xsc;
- }
-
- /*
- * Set aliases necessary for parsing configuration file in xstream format.
- */
- private void setConfigAliases(XStream stream) {
-
- stream.aliasField("root-element-name", XStreamConfiguration.class, "rootElementName");
- stream.aliasField("root-element-attributes", XStreamConfiguration.class, "rootElementAttributes");
-
- stream.alias("class-alias", ClassAlias.class);
- stream.aliasField("default-implementation", ClassAlias.class, "defaultImplementation");
- stream.aliasField("class-aliases", XStreamConfiguration.class, "classAliases");
-
- stream.alias("type-alias", TypeAlias.class);
- stream.aliasField("type-aliases", XStreamConfiguration.class, "typeAliases");
-
- stream.alias("field-alias", FieldAlias.class);
- stream.aliasField("alias-name", FieldAlias.class, "aliasName");
- stream.aliasField("field-name", FieldAlias.class, "fieldName");
- stream.aliasField("field-aliases", XStreamConfiguration.class, "fieldAliases");
-
- stream.alias("attribute-alias", AttributeAlias.class);
- stream.aliasField("attribute-name", AttributeAlias.class, "attributeName");
- stream.aliasField("attribute-aliases", XStreamConfiguration.class, "attributeAliases");
-
- stream.alias("attribute-properties", AttributeProperties.class);
- stream.aliasField("field-name", AttributeProperties.class, "fieldName");
- stream.aliasField("attributes", XStreamConfiguration.class, "attributes");
-
- stream.alias("converter-properties", ConverterProperties.class);
- stream.aliasField("class-name", ConverterProperties.class, "className");
-
- stream.alias("implicit-collection", ImplicitCollection.class);
- stream.aliasField("owner-type", ImplicitCollection.class, "ownerType");
- stream.aliasField("item-type", ImplicitCollection.class, "itemType");
- stream.aliasField("field-name", ImplicitCollection.class, "fieldName");
- stream.aliasField("item-field-name", ImplicitCollection.class, "itemFieldName");
- stream.aliasField("implicit-collections", XStreamConfiguration.class, "implicitCollections");
-
- stream.alias("ommited-field", OmmitedField.class);
- stream.aliasField("field-name", OmmitedField.class, "fieldName");
- stream.aliasField("ommited-fields", XStreamConfiguration.class, "ommitedFields");
-
- stream.alias("default-implementation", DefaultImplementation.class);
- stream.aliasField("default-impl", DefaultImplementation.class, "defaultImpl");
- stream.aliasField("default-implementations", XStreamConfiguration.class, "defaultImplementations");
-
- stream.aliasField("immutable-types", XStreamConfiguration.class, "immutableTypes");
-
- stream.alias("attribute", Entry.class);
- stream.alias("mapping", Mapping.class);
- stream.aliasField("class-name", Mapping.class, "className");
- stream.alias("configuration", XStreamConfiguration.class);
- stream.alias("key", java.lang.String.class);
- stream.alias("value", java.lang.String.class);
- stream.alias("type", java.lang.String.class);
- }
-
- /**
- * Set the filename of the configuration XML file.
- * @param configFile resource for reading configuration
- */
- public void setConfigFile(Resource resource) {
- this.resource = resource;
- }
-
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
- */
- protected Object createInstance() throws Exception {
- return getXStreamConfiguration();
- }
-
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType()
- */
- public Class getObjectType() {
- return XStreamConfiguration.class;
- }
-}
diff --git a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamFactory.java b/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamFactory.java
deleted file mode 100644
index d73a27813..000000000
--- a/infrastructure/src/main/java/org/springframework/batch/io/xml/xstream/XStreamFactory.java
+++ /dev/null
@@ -1,853 +0,0 @@
-/*
- * 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.io.xml.xstream;
-
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.channels.FileChannel;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.io.exception.BatchEnvironmentException;
-import org.springframework.batch.io.xml.ObjectInput;
-import org.springframework.batch.io.xml.ObjectInputFactory;
-import org.springframework.batch.io.xml.ObjectOutput;
-import org.springframework.batch.io.xml.ObjectOutputFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.dao.DataAccessResourceFailureException;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.converters.Converter;
-import com.thoughtworks.xstream.converters.SingleValueConverter;
-import com.thoughtworks.xstream.io.xml.QNameMap;
-import com.thoughtworks.xstream.io.xml.StaxReader;
-import com.thoughtworks.xstream.io.xml.StaxWriter;
-
-/**
- * XStreamFactory class implements both factory interfaces -
- * {@link ObjectInputFactory} and {@link ObjectOutputFactory}. Factory methods
- * {@link #createObjectInput(Resource, String)} and
- * {@link #createObjectOutput(Resource, String)} return implementations of
- * {@link ObjectInput} and {@link ObjectOutput} interfaces. These
- * implementations (ObjectInputWrapper and ObjecOutputWrapper) are defined as
- * factory's inner classes. They are wrapping StAX reader/writer for accessing
- * xml streams, XStream mapper for mapping Xml-to-ValueObjects and
- * {@link FileChannel} for file manipulation This factory implementation uses
- * {@link XStreamConfiguration} as source for XStream configuration settings.
- *
- * @author peter.zozom
- * @see ObjectInputFactory
- * @see ObjectOutputFactory
- * @see XStreamConfiguration
- */
-public class XStreamFactory implements ObjectOutputFactory, ObjectInputFactory {
- private static final Log log = LogFactory.getLog(XStreamFactory.class);
-
- private XStreamConfiguration config;
-
- /**
- * Set the XStream's configuration.
- * @param config value object holding XStream's configuration settings
- */
- public void setConfig(XStreamConfiguration config) {
- this.config = config;
- }
-
- /*
- * Set up XStream. Proctected visibility modifier is used to allow easier
- * testing of set...() methods.
- */
- protected void setUpXStream(XStream stream) {
- setClassAliases(stream);
- setTypeAliases(stream);
- setFieldAliases(stream);
- setAttributeAliases(stream);
- setAttributes(stream);
- registerConverters(stream);
- setMode(stream);
- addImplicitCollections(stream);
- setOmittedFileds(stream);
- addImmutableTypes(stream);
- addDefaultImplementations(stream);
- }
-
- /*
- * Iterate over list of DefaultImplementation objects and add default
- * implementations to the XStream.
- */
- private void addDefaultImplementations(XStream stream) {
-
- // get list of DefaultImplementation objects
- List defaultImplementations = config.getDefaultImplementations();
- // if not null iterate over list
- if (defaultImplementations != null) {
- for (Iterator i = defaultImplementations.iterator(); i.hasNext();) {
- DefaultImplementation di = (DefaultImplementation) i.next();
-
- // try to create Class object for default implementation class
- // name
- Class defaultImplementation;
- try {
- defaultImplementation = Class.forName(di.getDefaultImpl());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + di.getDefaultImpl(), cnfe);
- }
-
- // try to create Class object for ofType class name
- Class ofType;
- try {
- ofType = Class.forName(di.getType());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + di.getType(), cnfe);
- }
-
- // add default implementation
- stream.addDefaultImplementation(defaultImplementation, ofType);
- }
- }
- }
-
- /*
- * Iterate over list of immutable type names and pass them to the XStream.
- */
- private void addImmutableTypes(XStream stream) {
- // get list of names of immutable types
- List immutableTypes = config.getImmutableTypes();
- // if not null iterate over list
- if (immutableTypes != null) {
- for (Iterator i = immutableTypes.iterator(); i.hasNext();) {
- String it = (String) i.next();
-
- // try to create Class object for immutableTypeName
- Class immutableType;
- try {
- immutableType = Class.forName(it);
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + it, cnfe);
- }
-
- // add immutable type
- stream.addImmutableType(immutableType);
- }
- }
-
- }
-
- /*
- * Iterate over list of OmmitField objects and register ommited fields to
- * the XStream.
- */
- private void setOmittedFileds(XStream stream) {
- // get list of OmmitedField objects
- List ommitedFields = config.getOmmitedFields();
- // if not null iterate over list
- if (ommitedFields != null) {
- for (Iterator i = ommitedFields.iterator(); i.hasNext();) {
- OmmitedField ommitedField = (OmmitedField) i.next();
-
- // register field to be ommited
- try {
- stream.omitField(Class.forName(ommitedField.getType()), ommitedField.getFieldName());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + ommitedField.getType(), cnfe);
- }
- }
- }
- }
-
- /*
- * Iterate over list of ImplicitCollection objects and add implicit
- * collections to the XStream. XStream has 3 methods for adding implicit
- * collections. Decision which method to call is based on provided settings.
- */
- private void addImplicitCollections(XStream stream) {
- // get list of ImplicionCollection object
- List implicitCollections = config.getImplicitCollections();
- // if not null iterate over list
- if (implicitCollections != null) {
- for (Iterator i = implicitCollections.iterator(); i.hasNext();) {
- ImplicitCollection impCol = (ImplicitCollection) i.next();
- String typeName = impCol.getOwnerType();
-
- // create Class object for typeName
- try {
- Class ownerType = Class.forName(typeName);
-
- // if itemType not provided, add implicit collection for any
- // unmapped xml tag
- if (impCol.getItemType() == null) {
- stream.addImplicitCollection(ownerType, impCol.getFieldName());
- }
- else {
- typeName = impCol.getItemType();
-
- // create Class object for itemType
- Class itemType = Class.forName(typeName);
- // if itemFieldName not provided, add implicit
- // collection for all items of the given itemType
- if (impCol.getItemFieldName() == null) {
- stream.addImplicitCollection(ownerType, impCol.getFieldName(), itemType);
- }
- else {
- // else add implicit collection for all items of the
- // given element name defined by itemFieldName
- stream.addImplicitCollection(ownerType, impCol.getFieldName(), impCol.getItemFieldName(),
- itemType);
- }
- }
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + typeName, cnfe);
- }
- }
- }
- }
-
- /*
- * Set mode for dealing with duplicate references.
- */
- private void setMode(XStream stream) {
- stream.setMode(config.getMode());
- }
-
- /*
- * Iterate over list of ConverterProperties objects and register converters
- * to XStream.
- */
- private void registerConverters(XStream stream) {
- // get list of ConverterProperties
- List converters = config.getConverters();
- // if not null iterate over list
- if (converters != null) {
- for (Iterator i = converters.iterator(); i.hasNext();) {
- ConverterProperties cp = (ConverterProperties) i.next();
-
- // create Class object for converter class name
- try {
- Class converter = Class.forName(cp.getClassName());
-
- // if converter type is assignable to SingleValueConverter,
- // register it as SingleValueConverter
- if (SingleValueConverter.class.isAssignableFrom(converter)) {
- stream.registerConverter((SingleValueConverter) converter.newInstance(), cp.getPriority());
- // if converter type is assignable to Converter,
- // register it as Converter
- }
- else if (Converter.class.isAssignableFrom(converter)) {
- stream.registerConverter((Converter) converter.newInstance(), cp.getPriority());
- }
- else {
- throw new BatchEnvironmentException("Unable to register converter for class: "
- + cp.getClassName());
- }
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + cp.getClassName(), cnfe);
- }
- catch (InstantiationException ie) {
- log.debug(ie);
- throw new BatchEnvironmentException("Unable to instantiate class: " + cp.getClassName(),
- ie);
- }
- catch (IllegalAccessException iae) {
- log.debug(iae);
- throw new BatchEnvironmentException("Unable to instantiate class: " + cp.getClassName(),
- iae);
- }
- }
- }
- }
-
- /*
- * Iterate over list of AttributeProperties objects and map XML attributes
- * to fields or types.
- */
- private void setAttributes(XStream stream) {
- // get list of AttributeProperties objects
- List attributeProperties = config.getAttributes();
- // if not null iterate over list
- if (attributeProperties != null) {
- for (Iterator i = attributeProperties.iterator(); i.hasNext();) {
- AttributeProperties ap = (AttributeProperties) i.next();
- String fieldName = ap.getFieldName();
-
- // create Class object for type name
- try {
- Class type = Class.forName(ap.getType());
-
- // if field name is provided, map attribute to the field
- if (fieldName != null) {
- stream.useAttributeFor(fieldName, type);
- }
- else {
- // else map attribute to the type
- stream.useAttributeFor(type);
- }
-
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + ap.getType(), cnfe);
- }
- }
- }
- }
-
- /*
- * Iterate over list of AttributeAlias objects and configure attribute
- * aliases
- */
- private void setAttributeAliases(XStream stream) {
- // get list of AttributeAlias objects
- List attributeAliases = config.getAttributeAliases();
- // if not null iterate over list
- if (attributeAliases != null) {
- for (Iterator i = attributeAliases.iterator(); i.hasNext();) {
- AttributeAlias alias = (AttributeAlias) i.next();
- stream.aliasAttribute(alias.getAlias(), alias.getAttributeName());
- }
- }
- }
-
- /*
- * Iterate over list of FieldAlias objects and configure field aliases
- */
- private void setFieldAliases(XStream stream) {
- // get list of FieldAlias objects
- List fieldAliases = config.getFieldAliases();
- // if not null iterate over list
- if (fieldAliases != null) {
- for (Iterator i = fieldAliases.iterator(); i.hasNext();) {
- FieldAlias alias = (FieldAlias) i.next();
-
- try {
- stream.aliasField(alias.getAliasName(), Class.forName(alias.getType()), alias.getFieldName());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + alias.getType(), cnfe);
- }
- }
- }
- }
-
- /*
- * Iterate over list of TypeAlias objects and configure type aliases
- */
- private void setTypeAliases(XStream stream) {
- // get list of TypeAlias objects
- List typeAliases = config.getTypeAliases();
- // if not null iterate over list
- if (typeAliases != null) {
- for (Iterator i = typeAliases.iterator(); i.hasNext();) {
- TypeAlias alias = (TypeAlias) i.next();
-
- try {
- stream.aliasType(alias.getName(), Class.forName(alias.getType()));
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + alias.getType(), cnfe);
- }
- }
- }
- }
-
- /*
- * Iterate over list of ClassAlias objects and configure class aliases
- */
- private void setClassAliases(XStream stream) {
- // get list of ClassAlias objects
- List classAliases = config.getClassAliases();
- // if not null iterate over list
- if (classAliases != null) {
- for (Iterator i = classAliases.iterator(); i.hasNext();) {
- ClassAlias alias = (ClassAlias) i.next();
-
- Class type;
- try {
- type = Class.forName(alias.getType());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException("Unable to find class: " + alias.getType(), cnfe);
- }
-
- if (alias.getDefaultImplementation() != null) {
- Class defaultImplementation;
- try {
- defaultImplementation = Class.forName(alias.getDefaultImplementation());
- }
- catch (ClassNotFoundException cnfe) {
- log.debug(cnfe);
- throw new BatchEnvironmentException(
- "Unable to find class: " + alias.getDefaultImplementation(), cnfe);
- }
-
- stream.alias(alias.getName(), type, defaultImplementation);
- }
- else {
- stream.alias(alias.getName(), type);
- }
- }
- }
- }
-
- /*
- * Create QNameMap from list of Mapping objects.
- */
- private QNameMap getMapping() {
-
- List mappings = config.getMappings();
-
- QNameMap map = new QNameMap();
-
- if (mappings != null) {
- for (Iterator i = mappings.iterator(); i.hasNext();) {
- Mapping mapping = (Mapping) i.next();
- QName qname = new QName(mapping.getNamespaceURI(), mapping.getLocalPart(), mapping.getPrefix());
- map.registerMapping(qname, mapping.getClassName());
- }
- }
-
- return map;
- }
-
- /**
- * Creates instance of {@link ObjectInput} which is used by
- * for deserializing object from XML file.
- * @param resource the input XML file
- * @param encoding the encoding to use
- * @return ObjectInput which will read from the provided file
- * @see org.springframework.batch.io.xml.ObjectInputFactory#createObjectInput(Resource,
- * java.lang.String)
- */
- public ObjectInput createObjectInput(Resource resource, String encoding) {
-
- ObjectInput wrapper;
-
- XStream stream = new XStream();
- setUpXStream(stream);
-
- try {
- XMLInputFactory xmlif = XMLInputFactory.newInstance();
- XMLStreamReader xmlReader = xmlif.createXMLStreamReader(resource.getInputStream(), encoding);
-
- StaxReader reader = new StaxReader(getMapping(), xmlReader);
- java.io.ObjectInput input = stream.createObjectInputStream(reader);
- wrapper = new ObjectInputWrapper(xmlReader, input);
- }
- catch (XMLStreamException xse) {
- log.error(xse);
- throw new DataAccessResourceFailureException("Unable to get XML reader", xse);
- }
- catch (IOException ioe) {
- log.error(ioe);
- throw new DataAccessResourceFailureException("Unable to get ObjectInputStream", ioe);
- }
-
- return wrapper;
- }
-
- /**
- * Creates instance of {@link ObjectOutput} which is used by
- * for serializing object to XML file.
- * @param resource the output XML file
- * @param encoding the encoding to use
- * @return ObjectOutput which will write to the provided file
- * @see org.springframework.batch.io.xml.ObjectOutputFactory#createObjectOutput(Resource,
- * java.lang.String)
- */
- public ObjectOutput createObjectOutput(Resource resource, String encoding) {
-
- ObjectOutput wrapper;
- FileChannel channel;
-
- XStream stream = new XStream();
- setUpXStream(stream);
-
- try {
- XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
-
- FileOutputStream os;
-
- try {
- os = new FileOutputStream(resource.getFile(), true);
- channel = os.getChannel();
- }
- catch (FileNotFoundException ioe) {
- log.error(ioe);
- throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]",
- ioe);
- }
-
- XMLStreamWriter xmlWriter = xmlof.createXMLStreamWriter(os, encoding);
-
- StaxWriter writer = new StaxWriter(getMapping(), xmlWriter);
- String rootElementName = config.getRootElementName();
- java.io.ObjectOutput output;
- if (rootElementName != null) {
- output = stream.createObjectOutputStream(writer, rootElementName);
- }
- else {
- output = stream.createObjectOutputStream(writer);
- }
-
- writeAttributes(xmlWriter, config.getRootElementAttributes());
- wrapper = new ObjectOutputWrapper(xmlWriter, channel, output);
-
- }
- catch (XMLStreamException xse) {
- log.error(xse);
- throw new DataAccessResourceFailureException("Unable to get XML writer", xse);
- }
- catch (IOException ioe) {
- log.error(ioe);
- throw new DataAccessResourceFailureException("Unable to get ObjectOutputStream", ioe);
- }
-
- return wrapper;
- }
-
- /*
- * Writes attributes to current xml element
- *
- * @param attributes map of attributes (key, value) @throws
- * XMLStreamException
- */
- private void writeAttributes(XMLStreamWriter xmlWriter, Map attributes) throws XMLStreamException {
- if ((attributes != null) && !attributes.isEmpty()) {
-
- for (Iterator i = attributes.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
- xmlWriter.writeAttribute((String) entry.getKey(), (String) entry.getValue());
- }
- }
- }
-
- /**
- * Implementation of {@link ObjectInput} which wraps
- * {@link java.io.ObjectInput} and {@link XMLStreamReader} (which is StAX
- * parser) objects. Each of these objects handles the same input file on
- * different level and provides different set of methods:
- * -Infrastructure implementations of io xml xstream concerns. -
- - diff --git a/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectInputWrapperTests.java b/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectInputWrapperTests.java deleted file mode 100644 index 160376621..000000000 --- a/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectInputWrapperTests.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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.io.xml; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.ObjectInput; - -import javax.xml.stream.Location; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.easymock.MockControl; -import org.springframework.batch.io.xml.xstream.XStreamFactory.ObjectInputWrapper; -import org.springframework.dao.DataAccessResourceFailureException; - -/** - * Unit tests for {@link ObjectInputWrapper}. - * @author peter.zozom - */ -public class ObjectInputWrapperTests extends TestCase { - - private ObjectInputWrapper wrapper; - - private MockControl readerControl; - - private XMLStreamReader reader; - - private MockControl oiControl; - - private ObjectInput input; - - public void setUp() throws FileNotFoundException, XMLStreamException { - - // create mock reader - readerControl = MockControl.createControl(XMLStreamReader.class); - reader = (XMLStreamReader) readerControl.getMock(); - - // create mock for java.io.ObjectInput - oiControl = MockControl.createControl(ObjectInput.class); - input = (ObjectInput) oiControl.getMock(); - - // create ObjectInputWrapper - wrapper = new ObjectInputWrapper(reader, input); - } - - /** - * Test {@link ObjectInputWrapper#position()}. - */ - public void testPosition() { - - // create mock for Location - MockControl locationControl = MockControl.createControl(Location.class); - Location location = (Location) locationControl.getMock(); - location.getLineNumber(); - locationControl.setReturnValue(104); - locationControl.replay(); - - // set up reader mock - reader.getLocation(); - readerControl.setReturnValue(location); - readerControl.replay(); - - assertEquals(104, wrapper.position()); - - readerControl.verify(); - locationControl.verify(); - } - - /** - * Test {@link ObjectInputWrapper#readObject()} - * @throws ClassNotFoundException - * @throws IOException - */ - public void testReadObject() throws ClassNotFoundException, IOException { - - // set up objectInput mock - input.readObject(); - oiControl.setReturnValue(this); - oiControl.replay(); - - // read object - assertSame(this, wrapper.readObject()); - - oiControl.verify(); - } - - public void testClose() throws XMLStreamException, IOException { - - // TEST CLOSE - - // set up reader mock - reader.close(); - readerControl.replay(); - - // set up objectInput mock - input.close(); - oiControl.replay(); - - wrapper.close(); - - readerControl.verify(); - oiControl.verify(); - - // TEST CLOSE WITH XMLStreamException - - // set up reader mock - readerControl.reset(); - reader.close(); - readerControl.setThrowable(new XMLStreamException()); - readerControl.replay(); - - // set up objectInput mock - oiControl.reset(); - input.close(); - oiControl.replay(); - - try { - wrapper.close(); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException darfe) { - assertTrue(darfe.getCause() instanceof XMLStreamException); - } - - readerControl.verify(); - oiControl.verify(); - - // TEST CLOSE WITH IOException - // set up reader mock - readerControl.reset(); - readerControl.replay(); - - // set up objectInput mock - oiControl.reset(); - input.close(); - oiControl.setThrowable(new IOException()); - oiControl.replay(); - - try { - wrapper.close(); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException darfe) { - assertTrue(darfe.getCause() instanceof IOException); - } - - readerControl.verify(); - oiControl.verify(); - } -} diff --git a/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectOutputWrapperTests.java b/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectOutputWrapperTests.java deleted file mode 100644 index 68c16026d..000000000 --- a/infrastructure/src/test/java/org/springframework/batch/io/xml/ObjectOutputWrapperTests.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - * 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.io.xml; - -import java.io.IOException; -import java.io.ObjectOutput; -import java.nio.ByteBuffer; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.ReadableByteChannel; -import java.nio.channels.WritableByteChannel; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import junit.framework.TestCase; - -import org.easymock.MockControl; -import org.springframework.batch.io.xml.xstream.XStreamFactory.ObjectOutputWrapper; -import org.springframework.dao.DataAccessResourceFailureException; - -/** - * Unit tests for {@link ObjectOutputWrapper}. - * @author peter.zozom - */ -public class ObjectOutputWrapperTests extends TestCase { - - private ObjectOutputWrapper wrapper; - - private MockControl writerControl; - - private XMLStreamWriter writer; - - private MockControl ooControl; - - private ObjectOutput output; - - private MockFileChannel channel; - - public void setUp() { - - // create mock for xml writer - writerControl = MockControl.createControl(XMLStreamWriter.class); - writer = (XMLStreamWriter) writerControl.getMock(); - - // create mock for java.io.objectOutput - ooControl = MockControl.createControl(ObjectOutput.class); - output = (ObjectOutput) ooControl.getMock(); - - // create mock for file channel - channel = new MockFileChannel(); - - // create wrapper - wrapper = new ObjectOutputWrapper(writer, channel, output); - } - - public void testAfterRestart() throws XMLStreamException, IOException { - - // set up writer mock - writer.writeComment(""); - writerControl.replay(); - - // set up objectOutput mock - output.flush(); - ooControl.replay(); - - // call after restart - wrapper.afterRestart(new Long(99)); - - // check size and position - assertEquals(99, channel.size()); - assertEquals(99, channel.position()); - - // TEST EXCEPTION HANDLING - - // set up writer mock - writerControl.reset(); - writer.writeComment(""); - writerControl.setThrowable(new XMLStreamException()); - writerControl.replay(); - - try { - wrapper.afterRestart(new Long(74)); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException bce) { - assertTrue(bce.getCause() instanceof XMLStreamException); - } - - // set up writer mock - writerControl.reset(); - writer.writeComment(""); - writerControl.replay(); - - // set up objectOutput mock - ooControl.reset(); - output.flush(); - ooControl.setThrowable(new IOException()); - ooControl.replay(); - - try { - wrapper.afterRestart(new Long(63)); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException bce) { - assertTrue(bce.getCause() instanceof IOException); - } - } - - public void testClose() throws IOException, XMLStreamException { - - // set up objectOutput mock - output.close(); - ooControl.replay(); - - // set up writer mock - writer.close(); - writerControl.replay(); - - wrapper.close(); - - // test whether channel, writer and output were closed - assertTrue(channel.isClosed()); - ooControl.verify(); - writerControl.verify(); - - // TEST EXCEPTION HANDLING - - ooControl.reset(); - output.close(); - ooControl.setThrowable(new IOException()); - ooControl.replay(); - - try { - wrapper.close(); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException bce) { - assertTrue(bce.getCause() instanceof IOException); - } - - ooControl.reset(); - output.close(); - ooControl.replay(); - - writerControl.reset(); - writer.close(); - writerControl.setThrowable(new XMLStreamException()); - writerControl.replay(); - - try { - wrapper.close(); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException bce) { - assertTrue(bce.getCause() instanceof XMLStreamException); - } - - } - - /** - * Test flush() method. - * @throws IOException - */ - public void testFlush() throws IOException { - - // set up objectOutput mock (second call of flush() method will throw an - // IOException) - output.flush(); - output.flush(); - ooControl.setThrowable(new IOException()); - ooControl.replay(); - - // call flush() twice - wrapper.flush(); - try { - wrapper.flush(); - fail("BatchCriticalException was expected"); - } - catch (DataAccessResourceFailureException bce) { - assertTrue(bce.getCause() instanceof IOException); - } - - // verify method calls - ooControl.verify(); - } - - /** - * Test position() and position(int) methods. - * @throws IOException - */ - public void testPosition() throws IOException { - - // set up fileChannel mock - channel.position(35); - - // test position() - assertEquals(35, wrapper.position()); - - // test position(int) - wrapper.position(93); - assertEquals(93, channel.position()); - - // set exception - channel.setThrowable(new IOException()); - - // test exception handling - try { - wrapper.position(); - fail("BatchEnviromentException was expected"); - } - catch (DataAccessResourceFailureException bee) { - assertTrue(bee.getCause() instanceof IOException); - } - - try { - wrapper.position(33); - fail("BatchEnviromentException was expected"); - } - catch (DataAccessResourceFailureException bee) { - assertTrue(bee.getCause() instanceof IOException); - } - } - - /** - * Test size() and truncate() methods. - * @throws IOException - */ - public void testSizeAndTruncate() throws IOException { - - // set up fileChannel mock - channel.truncate(53); - - // test size() - assertEquals(53, wrapper.size()); - - // test truncate(int) - wrapper.truncate(39); - assertEquals(39, channel.size()); - - // set exception - channel.setThrowable(new IOException()); - - // test exception handling - try { - wrapper.size(); - fail("BatchEnviromentException was expected"); - } - catch (DataAccessResourceFailureException bee) { - assertTrue(bee.getCause() instanceof IOException); - } - - try { - wrapper.truncate(66); - fail("BatchEnviromentException was expected"); - } - catch (DataAccessResourceFailureException bee) { - assertTrue(bee.getCause() instanceof IOException); - } - - } - - /** - * Test writeObject() method. - * @throws IOException - */ - public void testWriteObject() throws IOException { - //TODO why is "this" used as argument to writeObject? - - // set up objectOutput mock - output.writeObject(this); - ooControl.replay(); - - // write object - wrapper.writeObject(this); - - // verify method calls - ooControl.verify(); - } - - /* - * Mock for FileChannel - */ - private static class MockFileChannel extends FileChannel { - - private long position; - - private long size; - - private boolean closed = false; - - private IOException throwable; - - public void setThrowable(IOException throwable) { - this.throwable = throwable; - } - - public long position() throws IOException { - if (throwable != null) { - throw throwable; - } - return position; - } - - public FileChannel position(long newPosition) throws IOException { - if (throwable != null) { - throw throwable; - } - this.position = newPosition; - return null; - } - - public long size() throws IOException { - if (throwable != null) { - throw throwable; - } - return size; - } - - public FileChannel truncate(long size) throws IOException { - if (throwable != null) { - throw throwable; - } - this.size = size; - return null; - } - - protected void implCloseChannel() throws IOException { - closed = true; - } - - public boolean isClosed() { - return closed; - } - - public void force(boolean metaData) throws IOException { - } - - public FileLock lock(long position, long size, boolean shared) throws IOException { - return null; - } - - public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException { - return null; - } - - public int read(ByteBuffer dst) throws IOException { - return 0; - } - - public int read(ByteBuffer dst, long position) throws IOException { - return 0; - } - - public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { - return 0; - } - - public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException { - return 0; - } - - public long transferTo(long position, long count, WritableByteChannel target) throws IOException { - return 0; - } - - public FileLock tryLock(long position, long size, boolean shared) throws IOException { - return null; - } - - public int write(ByteBuffer src) throws IOException { - return 0; - } - - public int write(ByteBuffer src, long position) throws IOException { - return 0; - } - - public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { - return 0; - } - } -} diff --git a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlErrorHandlerTests.java b/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlErrorHandlerTests.java deleted file mode 100644 index a8c785bb7..000000000 --- a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlErrorHandlerTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.io.xml; - -import junit.framework.TestCase; - -import org.springframework.batch.io.xml.XmlErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * Unit test for XmlErrorHandler - * @author peter.zozom - */ -public class XmlErrorHandlerTests extends TestCase { - - XmlErrorHandler handler; - - SAXParseException spe; - - public void setUp() { - handler = new XmlErrorHandler(); - spe = new SAXParseException("test", "pid", "sid", 1, 1); - } - - public void testWarning() { - try { - handler.warning(spe); - } - catch (SAXException se) { - assertSame(spe, se.getException()); - } - } - - public void testError() { - try { - handler.error(spe); - } - catch (SAXException se) { - assertSame(spe, se.getException()); - } - } - - public void testFatalError() { - try { - handler.fatalError(spe); - } - catch (SAXException se) { - assertSame(spe, se.getException()); - } - } - -} diff --git a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSource2Tests.java b/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSource2Tests.java deleted file mode 100644 index cbcffafa8..000000000 --- a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSource2Tests.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.springframework.batch.io.xml; - -import java.io.IOException; - -import javax.xml.transform.Source; -import javax.xml.transform.sax.SAXSource; - -import junit.framework.TestCase; - -import org.easymock.MockControl; -import org.springframework.batch.restart.RestartData; -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; -import org.springframework.oxm.Unmarshaller; -import org.springframework.oxm.XmlMappingException; -import org.springframework.transaction.support.TransactionSynchronization; - -/** - * Unit tests for {@link XmlInputSource2} - * - * @author Robert Kasanicky - */ -public class XmlInputSource2Tests extends TestCase { - - private XmlInputSource2 inputSource = new XmlInputSource2(); - - - private Resource getInputResource() throws IOException { - return new FileSystemResource("src/test/resources/org/springframework/batch/io/xml/test1.xml"); - } - - //@Override - protected void setUp() throws Exception { - inputSource.setRecordElementName("book"); - inputSource.setResource(getInputResource()); - inputSource.setUnmarshaller(new UnmarshallerStub()); - inputSource.setUseSaxParser(true); - } - - - - /** - * Regular usage scenario. - * The actual xml-to-object mapping is delegated to the injected unmarshaller. - */ - public void testRead() throws XmlMappingException, IOException { - MockControl umControl = MockControl.createControl(Unmarshaller.class); - Unmarshaller unmarshaller = (Unmarshaller) umControl.getMock(); - Object expectedDomainObject = new Object(); - unmarshaller.unmarshal(null); - umControl.setDefaultMatcher(MockControl.ALWAYS_MATCHER); - umControl.setDefaultReturnValue(expectedDomainObject); - umControl.replay(); - - inputSource.setUnmarshaller(unmarshaller); - - //there are two records in the input file - assertSame(expectedDomainObject, inputSource.read()); - assertSame(expectedDomainObject, inputSource.read()); - assertNull(inputSource.read()); - } - - public void testReadUntilEnd() { - - } - - /** - * In case of rollback uncommited records are read again. - */ - public void testRollback() { - Object uncommited = inputSource.read(); - inputSource.getSynchronization().afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK); - Object afterRollback = inputSource.read(); - - assertEquals(uncommited, afterRollback); - } - - /** - * Records once marked to be skipped are not returned when read again. - */ - public void testSkip() { - Object first = inputSource.read(); - inputSource.skip(); - inputSource.getSynchronization().afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK); - - Object second = inputSource.read(); - assertFalse(second.equals(first)); - } - - /** - * In case of restart the input source should continue from the position when restart data was saved. - */ - public void testRestart() { - inputSource.read(); - RestartData commitPoint = inputSource.getRestartData(); - Object firstAfterCommit = inputSource.read(); - inputSource.restoreFrom(commitPoint); - assertEquals(firstAfterCommit, inputSource.read()); - - } - - /** - * Returns a fixed-length prefix of the original xml string instead of mapped object. - * - * @author Robert Kasanicky - */ - private static class UnmarshallerStub implements Unmarshaller { - - private static final int PREFIX_LENGTH = 10000; - - public boolean supports(Class clazz) { - return true; - } - - public Object unmarshal(Source source) throws XmlMappingException, IOException { - char[] input = new char[PREFIX_LENGTH]; - SAXSource saxSource = (SAXSource) source; - saxSource.getInputSource().getCharacterStream().read(input); - - return String.valueOf(input); - } - - } -} diff --git a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSourceIntegrationTests.java b/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSourceIntegrationTests.java deleted file mode 100644 index e0d17d6e8..000000000 --- a/infrastructure/src/test/java/org/springframework/batch/io/xml/XmlInputSourceIntegrationTests.java +++ /dev/null @@ -1,428 +0,0 @@ -/* - * 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.io.xml; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.springframework.batch.io.exception.BatchEnvironmentException; -import org.springframework.batch.io.sample.domain.LineItem; -import org.springframework.batch.io.sample.domain.Order; -import org.springframework.batch.io.sample.domain.Shipper; -import org.springframework.batch.io.xml.xstream.FieldAlias; -import org.springframework.batch.io.xml.xstream.Mapping; -import org.springframework.batch.io.xml.xstream.XStreamConfiguration; -import org.springframework.batch.io.xml.xstream.XStreamFactory; -import org.springframework.batch.restart.RestartData; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.transaction.support.TransactionSynchronization; -import org.springframework.util.ClassUtils; - -/** - * Integration test for XmlInputTemplate. It tests reading, xml validation, skip - * and restart functionality. - * @author peter.zozom - */ -public class XmlInputSourceIntegrationTests extends TestCase { - - private final static String INPUT_NAME = "xmlInputTemplate"; - - private XmlInputSource xmlInput; - - private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); - - /** - * Set up XmlInputTemplate: create mock for FileLocator and create - * XStreamConfiguration object. - * @throws Exception - */ - public void setUp() throws Exception { - - // create mock for file locator - Resource resource = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), - "20070125.testStream.xmlFileStep.xml")); - - // Set up XStreamCfg: - XStreamConfiguration streamConfiguration = new XStreamConfiguration(); - - // Step 1: set field aliases - List aliases = new ArrayList(); - - FieldAlias alias = new FieldAlias(); - alias.setAliasName("org.springframework.batch.io.sample.domain.Customer"); - alias.setType("org.springframework.batch.io.sample.domain.Order"); - alias.setFieldName("customer"); - aliases.add(alias); - - alias = new FieldAlias(); - alias.setAliasName("org.springframework.batch.io.sample.domain.Shipper"); - alias.setType("org.springframework.batch.io.sample.domain.Order"); - alias.setFieldName("shipper"); - aliases.add(alias); - - streamConfiguration.setFieldAliases(aliases); - - // Step 2: set mappings - List mappings = new ArrayList(); - - Mapping mapping = new Mapping(); - mapping.setClassName("org.springframework.batch.io.sample.domain.Order"); - mapping.setNamespaceURI("http://adsj.accenture.com/purchaseorders"); - mapping.setLocalPart("order"); - mapping.setPrefix(""); - mappings.add(mapping); - - mapping = new Mapping(); - mapping.setClassName("org.springframework.batch.io.sample.domain.Customer"); - mapping.setNamespaceURI("http://adsj.accenture.com/purchaseorders"); - mapping.setLocalPart("customer"); - mapping.setPrefix(""); - mappings.add(mapping); - - mapping = new Mapping(); - mapping.setClassName("org.springframework.batch.io.sample.domain.LineItem"); - mapping.setNamespaceURI("http://adsj.accenture.com/purchaseorders"); - mapping.setLocalPart("lineItem"); - mapping.setPrefix(""); - mappings.add(mapping); - - mapping = new Mapping(); - mapping.setClassName("org.springframework.batch.io.sample.domain.Shipper"); - mapping.setNamespaceURI("http://adsj.accenture.com/purchaseorders"); - mapping.setLocalPart("shipper"); - mapping.setPrefix(""); - mappings.add(mapping); - - streamConfiguration.setMappings(mappings); - - // Set up input template - xmlInput = new XmlInputSource() { - public void registerSynchronization() { - } - }; - - xmlInput.setResource(resource); - xmlInput.setEncoding("UTF-8"); - xmlInput.setName(INPUT_NAME); - XStreamFactory factory = new XStreamFactory(); - factory.setConfig(streamConfiguration); - xmlInput.setInputFactory(factory); - } - - public void tearDown() { - } - - /** - * Test read functionality. - * @throws ParseException - */ - public void testRead() throws ParseException { - - xmlInput.setValidating(false); - xmlInput.open(); - - // READ FIRST RECORD - Object result = xmlInput.read(); - - // is it Order? - assertTrue(result instanceof Order); - Order order = (Order) result; - // verify customer - assertNotNull(order.getCustomer()); - assertEquals("Gladys Kravitz", order.getCustomer().getName()); - assertEquals("Anytown, PA", order.getCustomer().getAddress()); - assertEquals(34, order.getCustomer().getAge()); - assertEquals(0, order.getCustomer().getMoo()); - assertEquals(0, order.getCustomer().getPoo()); - // verify date - assertEquals(sdf.parse("2003-01-07 14:16:00 GMT"), order.getDate()); - // verify line items - List items = order.getLineItems(); - assertEquals(2, items.size()); - LineItem item = (LineItem) items.get(0); - assertEquals("Burnham's Celestial Handbook, Vol 1", item.getDescription()); - assertEquals(5.0, item.getPerUnitOunces(), 0.0); - assertEquals(21.79, item.getPrice(), 0.0); - assertEquals(2, item.getQuantity()); - item = (LineItem) items.get(1); - assertEquals("Burnham's Celestial Handbook, Vol 2", item.getDescription()); - assertEquals(5.0, item.getPerUnitOunces(), 0.0); - assertEquals(19.89, item.getPrice(), 0.0); - assertEquals(2, item.getQuantity()); - // verify shipper - Shipper shipper = order.getShipper(); - assertEquals("ZipShip", shipper.getName()); - assertEquals(0.74, shipper.getPerOunceRate(), 0.0); - - // READ SECOND RECORD - result = xmlInput.read(); - - // is it Order? - assertTrue(result instanceof Order); - order = (Order) result; - // verify customer - assertNotNull(order.getCustomer()); - assertEquals("John Smith", order.getCustomer().getName()); - assertEquals("Chicago, IL", order.getCustomer().getAddress()); - assertEquals(46, order.getCustomer().getAge()); - assertEquals(0, order.getCustomer().getMoo()); - assertEquals(0, order.getCustomer().getPoo()); - // verify date - assertEquals(sdf.parse("2003-01-07 14:16:02 GMT"), order.getDate()); - // verify line items - items = order.getLineItems(); - assertEquals(3, items.size()); - item = (LineItem) items.get(0); - assertEquals("XmlBeans in Action", item.getDescription()); - assertEquals(3.0, item.getPerUnitOunces(), 0.0); - assertEquals(41.29, item.getPrice(), 0.0); - assertEquals(1, item.getQuantity()); - item = (LineItem) items.get(1); - assertEquals("JSR-173", item.getDescription()); - assertEquals(1.0, item.getPerUnitOunces(), 0.0); - assertEquals(11.99, item.getPrice(), 0.0); - assertEquals(5, item.getQuantity()); - item = (LineItem) items.get(2); - assertEquals("Teach Yourself XML in 21 days", item.getDescription()); - assertEquals(1.0, item.getPerUnitOunces(), 0.0); - assertEquals(35.49, item.getPrice(), 0.0); - assertEquals(1, item.getQuantity()); - // verify shipper - shipper = order.getShipper(); - assertEquals("ZipShip", shipper.getName()); - assertEquals(0.74, shipper.getPerOunceRate(), 0.0); - - // READ LAST RECORD - result = xmlInput.read(); - - // is it Order? - assertTrue(result instanceof Order); - order = (Order) result; - // verify customer - assertNotNull(order.getCustomer()); - assertEquals("Peter Newman", order.getCustomer().getName()); - assertEquals("Cleveland, OH", order.getCustomer().getAddress()); - assertEquals(23, order.getCustomer().getAge()); - assertEquals(0, order.getCustomer().getMoo()); - assertEquals(0, order.getCustomer().getPoo()); - // verify date - assertEquals(sdf.parse("2003-01-07 14:16:35 GMT"), order.getDate()); - // verify line items - items = order.getLineItems(); - assertEquals(1, items.size()); - item = (LineItem) items.get(0); - assertEquals("Java 6", item.getDescription()); - assertEquals(2.0, item.getPerUnitOunces(), 0.0); - assertEquals(12.79, item.getPrice(), 0.0); - assertEquals(3, item.getQuantity()); - // verify shipper - shipper = order.getShipper(); - assertEquals("UPS", shipper.getName()); - assertEquals(0.69, shipper.getPerOunceRate(), 0.0); - - // all records were processed already - assertNull(xmlInput.read()); - - // verify statistics TODO - // Map statistics = xmlInput.getStatistics(); - // assertEquals("4", - // statistics.get(XmlInputTemplate.READ_STATISTICS_NAME)); - - xmlInput.close(); - } - - /** - * Test XML validation - */ - public void testValidation() { - - // turn on xml validation - xmlInput.setValidating(true); - // TEST 1: parse valid xml - xmlInput.open(); - xmlInput.close(); - - } - - public void testInvalidXml() throws Exception { - - xmlInput.setValidating(true); - - // TEST 2: parse invalid xml - xmlInput.setResource(new ByteArrayResource("