[BATCH-430] Removed the batch.io.exception package and moved classes to their approved locations

This commit is contained in:
nebhale
2008-03-07 14:18:49 +00:00
parent b2396b3ef4
commit 609ce9d347
94 changed files with 216 additions and 566 deletions

View File

@@ -1,49 +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.exception;
/**
* This exception is thrown when there is a critical configuration error and the
* current job or module execution cannot continue.
*
* @author Kerry O'Brien
*/
public class ConfigurationException extends InfrastructureException {
private static final long serialVersionUID = 759498454063502984L;
/**
* @param msg
* @param ex
*/
public ConfigurationException(String msg, Throwable ex) {
super(msg, ex);
}
/**
* @param msg
*/
public ConfigurationException(String msg) {
super(msg);
}
/**
* @param nested
*/
public ConfigurationException(Throwable nested) {
super(nested);
}
}

View File

@@ -1,65 +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.exception;
/**
* Indicates to the framework that a critical error has occurred and processing
* should immediately stop.
*
* @author Lucas Ward
*
*/
public class InfrastructureException extends RuntimeException {
private static final long serialVersionUID = 8838982304219248527L;
/**
* Constructs a new instance with a default error code of 1.
*
* @param msg the exception message.
*
*/
public InfrastructureException(String msg) {
super(msg);
}
/**
* Constructs a new instance with a default error code of 1.
*
* @param msg the exception message.
*
*/
public InfrastructureException(String msg, Throwable nested) {
super(msg, nested);
}
/**
* Constructs a new instance with a nested exception. The error code is
* defaulted to 1 and the message is empty.
*/
public InfrastructureException(Throwable nested) {
super(nested);
}
/**
* Constructs a new instance, the error code is defaulted to one and the
* message is empty.
*/
public InfrastructureException() {
super();
}
}

View File

@@ -1,42 +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.exception;
import org.springframework.batch.item.ItemReader;
/**
* This exception indicates an error encountered while reading. It should generally
* be thrown by classes that implement the {@link ItemReader} interface.
*
* @author Lucas Ward
*/
public class ReadFailureException extends InfrastructureException {
private static final long serialVersionUID = 4113323182216735223L;
public ReadFailureException(String msg, Throwable ex) {
super(msg, ex);
}
public ReadFailureException(String msg) {
super(msg);
}
public ReadFailureException(Throwable nested) {
super(nested);
}
}

View File

@@ -1,57 +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.exception;
import org.springframework.batch.item.ItemWriter;
/**
* Exception thrown after encountering an error during a write. It should
* generally be thrown by classes that implement the {@link ItemWriter}
* interface.
*
* @author Lucas Ward
*/
public class WriteFailureException extends InfrastructureException {
private static final long serialVersionUID = -1933213086873834098L;
private final Object item;
public WriteFailureException(String msg, Throwable ex, Object item) {
super(msg, ex);
this.item = item;
}
public WriteFailureException(String msg) {
this(msg, null, null);
}
public WriteFailureException(Throwable nested) {
this("", nested, null);
}
public WriteFailureException(String msg, Object item){
this(msg, null, item);
}
public WriteFailureException(Throwable nested, Object item){
this("", nested, item);
}
public Object getItem() {
return item;
}
}

View File

@@ -1,7 +0,0 @@
<html>
<body>
<p>
Infrastructure implementations of io exception concerns.
</p>
</body>
</html>

View File

@@ -1,7 +0,0 @@
<html>
<body>
<p>
Infrastructure implementations of io concerns.
</p>
</body>
</html>

View File

@@ -41,7 +41,7 @@ public interface ItemReader {
*
* @throws Exception if an underlying resource is unavailable.
*/
Object read() throws Exception, UnexpectedInputException, NoWorkFoundException;
Object read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException;
/**
* Mark the stream so that it can be reset later and the items backed out.<br/>

View File

@@ -13,28 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.exception;
package org.springframework.batch.item;
/**
* Exception indicating that an error has been encountered
* parsing io, typically from a file.
*
* Exception indicating that an error has been encountered parsing io, typically from a file.
*
* @author Lucas Ward
*
* @author Ben Hale
*/
public class ParsingException extends RuntimeException {
public class ParseException extends ItemReaderException {
private static final long serialVersionUID = 2953386084409312312L;
public ParsingException(String message) {
super(message);
}
public ParsingException(String message, Throwable cause) {
/**
* Create a new {@link ParseException} based on a message and another exception.
*
* @param message the message for this exception
* @param cause the other exception
*/
public ParseException(String message, Throwable cause) {
super(message, cause);
}
public ParsingException(Throwable cause) {
super(cause);
/**
* Create a new {@link ParseException} based on a message.
*
* @param message the message for this exception
*/
public ParseException(String message) {
super(message);
}
}

View File

@@ -22,7 +22,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.io.exception.FlatFileParsingException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ExecutionContextUserSupport;
import org.springframework.batch.item.ItemReader;
@@ -188,7 +187,7 @@ public class FlatFileItemReader extends ExecutionContextUserSupport implements I
} catch (RuntimeException ex) {
// add current line count to message and re-throw
int lineCount = getReader().getPosition();
throw new FlatFileParsingException("Parsing error at line: " + lineCount + " in resource=" + path
throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=" + path
+ ", input=[" + line + "]", ex, line, lineCount);
}
}

View File

@@ -25,8 +25,6 @@ import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.charset.UnsupportedCharsetException;
import org.springframework.batch.io.exception.ConfigurationException;
import org.springframework.batch.io.exception.InfrastructureException;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ExecutionContextUserSupport;
@@ -34,6 +32,8 @@ import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.MarkFailedException;
import org.springframework.batch.item.ResetFailedException;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetCreator;
import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
@@ -191,7 +191,13 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
throw new ItemStreamException("ItemStream not open or already closed.");
}
Assert.notNull(executionContext, "ExecutionContext must not be null");
executionContext.putLong(getKey(RESTART_DATA_NAME), state.position());
try {
executionContext.putLong(getKey(RESTART_DATA_NAME), state.position());
} catch (IOException e) {
throw new ItemStreamException("ItemStream does not return current position properly", e);
}
executionContext.putLong(getKey(WRITTEN_STATISTICS_NAME), state.linesWritten);
executionContext.putLong(getKey(RESTART_COUNT_STATISTICS_NAME), state.restartCount);
}
@@ -240,19 +246,15 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
/**
* Return the byte offset position of the cursor in the output file as a long integer.
*/
public long position() {
public long position() throws IOException {
long pos = 0;
if (fileChannel == null) {
return 0;
}
try {
outputBufferedWriter.flush();
pos = fileChannel.position();
} catch (IOException e) {
throw new InfrastructureException("An Error occured while trying to get filechannel position", e);
}
outputBufferedWriter.flush();
pos = fileChannel.position();
return pos;
@@ -308,38 +310,37 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
* @param data
* @param offset
* @param length
* @throws IOException
*/
public void write(String line) {
public void write(String line) throws IOException {
if (!initialized) {
initializeBufferedWriter();
}
try {
outputBufferedWriter.write(line);
outputBufferedWriter.flush();
linesWritten++;
} catch (IOException e) {
throw new InfrastructureException("An Error occured while trying to write to FlatFileItemWriter", e);
}
outputBufferedWriter.write(line);
outputBufferedWriter.flush();
linesWritten++;
}
/**
* Truncate the output at the last known good point.
*
* @throws IOException
*/
public void truncate() {
try {
fileChannel.truncate(lastMarkedByteOffsetPosition);
fileChannel.position(lastMarkedByteOffsetPosition);
} catch (IOException e) {
throw new InfrastructureException("An Error occured while truncating output file", e);
}
public void truncate() throws IOException {
fileChannel.truncate(lastMarkedByteOffsetPosition);
fileChannel.position(lastMarkedByteOffsetPosition);
}
/**
* Mark the current position.
*/
public void mark() {
lastMarkedByteOffsetPosition = this.position();
try {
lastMarkedByteOffsetPosition = this.position();
} catch (IOException e) {
throw new MarkFailedException("Unable to get position for mark", e);
}
}
/**
@@ -381,12 +382,12 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
try {
fileChannel = (new FileOutputStream(file.getAbsolutePath(), true)).getChannel();
} catch (FileNotFoundException fnfe) {
throw new ConfigurationException("Bad filename property parameter " + file, fnfe);
throw new ItemStreamException("Bad filename property parameter " + file, fnfe);
}
outputBufferedWriter = getBufferedWriter(fileChannel, encoding, bufferSize);
// in case of restarting reset position to last commited point
// in case of restarting reset position to last committed point
if (restarted) {
this.reset();
}
@@ -423,9 +424,13 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
* moved to (if it is, throws an environment exception), then it truncates the file to that reset position, and
* set the cursor to start writing at that point.
*/
public void reset() throws InfrastructureException {
public void reset() throws ResetFailedException {
checkFileSize();
getOutputState().truncate();
try {
getOutputState().truncate();
} catch (IOException e) {
throw new ResetFailedException("Unable to truncate file", e);
}
}
/**
@@ -440,11 +445,11 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
outputBufferedWriter.flush();
size = fileChannel.size();
} catch (IOException e) {
throw new InfrastructureException("An Error occured while checking file size", e);
throw new ResetFailedException("An Error occured while checking file size", e);
}
if (size < lastMarkedByteOffsetPosition) {
throw new InfrastructureException("Current file size is smaller than size at last commit");
throw new ResetFailedException("Current file size is smaller than size at last commit");
}
}
@@ -453,7 +458,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
public void clear() throws ClearFailedException {
try {
getOutputState().reset();
} catch (InfrastructureException e) {
} catch (Exception e) {
throw new ClearFailedException("Could not reset the state of the writer", e);
}
}

View File

@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.exception;
package org.springframework.batch.item.file;
import org.springframework.batch.item.ParseException;
/**
* Exception thrown when errors are encountered
@@ -23,37 +25,31 @@ package org.springframework.batch.io.exception;
* an error table.
*
* @author Lucas Ward
*
* @author Ben Hale
*/
public class FlatFileParsingException extends ParsingException {
private static final long serialVersionUID = 2529197834044942724L;
public class FlatFileParseException extends ParseException {
private String input;
private int lineNumber;
public FlatFileParsingException(String message, String input) {
public FlatFileParseException(String message, String input) {
super(message);
this.input = input;
}
public FlatFileParsingException(String message, String input, int lineNumber) {
public FlatFileParseException(String message, String input, int lineNumber) {
super(message);
this.input = input;
this.lineNumber = lineNumber;
}
public FlatFileParsingException(String message, Throwable cause, String input, int lineNumber) {
public FlatFileParseException(String message, Throwable cause, String input, int lineNumber) {
super(message, cause);
this.input = input;
this.lineNumber = lineNumber;
}
public FlatFileParsingException(Throwable cause, String input) {
super(cause);
this.input = input;
}
public String getInput() {
return input;
}

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.item.file.transform;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.exception.ConfigurationException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -40,8 +40,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
public static final char DELIMITER_COMMA = ',';
/**
* Convenient constant for the common case of a " character used to escape
* delimiters or line endings.
* Convenient constant for the common case of a " character used to escape delimiters or line endings.
*/
public static final char DEFAULT_QUOTE_CHARACTER = '"';
@@ -53,8 +52,8 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
private String quoteString;
/**
* Create a new instance of the {@link DelimitedLineTokenizer} class for the
* common case where the delimiter is a {@link #DELIMITER_COMMA comma}.
* Create a new instance of the {@link DelimitedLineTokenizer} class for the common case where the delimiter is a
* {@link #DELIMITER_COMMA comma}.
*
* @see #DelimitedLineTokenizer(char)
* @see #DELIMITER_COMMA
@@ -69,10 +68,8 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
* @param delimiter the desired delimiter
*/
public DelimitedLineTokenizer(char delimiter) {
if (delimiter == DEFAULT_QUOTE_CHARACTER) {
throw new ConfigurationException("'" + DEFAULT_QUOTE_CHARACTER
+ "' is not allowed as delimiter for tokenizers.");
}
Assert.state(delimiter != DEFAULT_QUOTE_CHARACTER, "[" + DEFAULT_QUOTE_CHARACTER
+ "] is not allowed as delimiter for tokenizers.");
this.delimiter = delimiter;
setQuoteCharacter(DEFAULT_QUOTE_CHARACTER);
@@ -80,6 +77,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
/**
* Setter for the delimiter character.
*
* @param delimiter
*/
public void setDelimiter(char delimiter) {
@@ -87,10 +85,9 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
}
/**
* Public setter for the quoteCharacter. The quote character can be used to
* extend a field across line endings or to enclose a String which contains
* the delimiter. Inside a quoted token the quote character can be used to
* escape itself, thus "a""b""c" is tokenized to a"b"c.
* Public setter for the quoteCharacter. The quote character can be used to extend a field across line endings or to
* enclose a String which contains the delimiter. Inside a quoted token the quote character can be used to escape
* itself, thus "a""b""c" is tokenized to a"b"c.
*
* @param quoteCharacter the quoteCharacter to set
*
@@ -102,8 +99,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
}
/**
* Yields the tokens resulting from the splitting of the supplied
* <code>line</code>.
* Yields the tokens resulting from the splitting of the supplied <code>line</code>.
*
* @param line the line to be tokenized
*
@@ -143,8 +139,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
}
lastCut = i + 1;
}
else if (isQuoteCharacter(currentChar)) {
} else if (isQuoteCharacter(currentChar)) {
inQuoted = !inQuoted;
}
@@ -154,9 +149,9 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
}
/**
* If the string is quoted strip (possibly with whitespace outside the
* quotes (which will be stripped), replace escaped quotes inside the
* string. Quotes are escaped with double instances of the quote character.
* If the string is quoted strip (possibly with whitespace outside the quotes (which will be stripped), replace
* escaped quotes inside the string. Quotes are escaped with double instances of the quote character.
*
* @param string
* @return the same string but stripped and unescaped if necessary
*/
@@ -166,7 +161,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
value = StringUtils.replace(value, "" + quoteCharacter + quoteCharacter, "" + quoteCharacter);
int endLength = value.length() - 1;
// used to deal with empty quoted values
if(endLength == 0) {
if (endLength == 0) {
endLength = 1;
}
string = value.substring(1, endLength);
@@ -176,9 +171,9 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
/**
* Is this string surrounded by quite characters?
*
* @param value
* @return true if the value starts and ends with the
* {@link #quoteCharacter}
* @return true if the value starts and ends with the {@link #quoteCharacter}
*/
private boolean isQuoted(String value) {
if (value.startsWith(quoteString) && value.endsWith(quoteString)) {
@@ -191,8 +186,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
* Is the supplied character the delimiter character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is the delimiter
* character
* @return <code>true</code> if the supplied character is the delimiter character
* @see DelimitedLineTokenizer#DelimitedLineTokenizer(char)
*/
private boolean isDelimiterCharacter(char c) {
@@ -203,8 +197,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
* Is the supplied character a quote character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is an quote
* character
* @return <code>true</code> if the supplied character is an quote character
* @see #setQuoteCharacter(char)
*/
protected boolean isQuoteCharacter(char c) {

View File

@@ -20,7 +20,6 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.io.exception.ValidationException;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.FieldError;

View File

@@ -14,21 +14,34 @@
* limitations under the License.
*/
package org.springframework.batch.io.exception;
package org.springframework.batch.item.validator;
import org.springframework.batch.item.ItemReaderException;
/**
* This exception should be thrown when there are validation errors.
*
* @author Ben Hale
*/
public class ValidationException extends ReadFailureException {
private static final long serialVersionUID = 7926495144451758088L;
public ValidationException(String message) {
super(message);
}
public class ValidationException extends ItemReaderException {
/**
* Create a new {@link ValidationException} based on a message and another exception.
*
* @param message the message for this exception
* @param cause the other exception
*/
public ValidationException(String message, Throwable cause) {
super(message, cause);
}
/**
* Create a new {@link ValidationException} based on a message.
*
* @param message the message for this exception
*/
public ValidationException(String message) {
super(message);
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.item.validator;
import org.springframework.batch.io.exception.ValidationException;
/**
* Interface used to validate objects.

View File

@@ -19,7 +19,6 @@ package org.springframework.batch.support;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.springframework.batch.io.exception.DynamicMethodInvocationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.MethodInvoker;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.io.exception;
package org.springframework.batch.support;
import org.springframework.util.MethodInvoker;