org.supercsv.ext.exception.SuperCsvCellProcessorException Maven / Gradle / Ivy
/*
* SuperCsvCellProcessorException.java
* created in 2013/04/19
*
* (C) Copyright 2003-2013 GreenDay Project. All rights reserved.
*/
package org.supercsv.ext.exception;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.exception.SuperCSVException;
import org.supercsv.util.CSVContext;
/**
* Exception thrown when CellProcessor execution fails (typically due to invalid input) - constraint validating
* CellProcessors should throw {@link SuperCsvConstraintViolationException} for constraint validation failures.
*
* @version 01-00
* @since 01-00
* @author T.TSUCHIE
*
* @see SuperCSV2.x:org.supercsv.exception.SuperCsvCellProcessorException
*/
public class SuperCsvCellProcessorException extends SuperCSVException {
/** serialVersionUID */
private static final long serialVersionUID = 1L;
public SuperCsvCellProcessorException(final String msg, final CSVContext context, final CellProcessor processor) {
super(msg, context, processor);
}
public SuperCsvCellProcessorException(final String msg, final CSVContext context, final CellProcessor processor, Throwable t) {
super(msg, context, processor, t);
}
public SuperCsvCellProcessorException(final Class expectedType, final Object actualValue,
final CSVContext context, final CellProcessor processor) {
super(getUnexpectedTypeMessage(expectedType, actualValue), context, processor);
}
private static String getUnexpectedTypeMessage(final Class expectedType, final Object actualValue) {
if( expectedType == null ) {
throw new NullPointerException("expectedType should not be null");
}
String expectedClassName = expectedType.getName();
String actualClassName = (actualValue != null) ? actualValue.getClass().getName() : "null";
return String.format("the input value should be of type %s but is %s", expectedClassName, actualClassName);
}
/**
* Returns the String representation of this exception.
*/
@Override
public String toString() {
return String.format("%s: %s%nprocessor=%s%ncontext=%s", getClass().getName(), getMessage(), getOffendingProcessor(),
getCsvContext());
}
}