use of org.apache.sis.storage.NoSuchDataException in project sis by apache.
the class AbstractGridResource method canNotRead.
/**
* Creates an exception for a failure to load data. If the failure may be caused by an envelope
* outside the resource domain, that envelope will be inferred from the {@code request} argument.
*
* @param filename some identification (typically a file name) of the data that can not be read.
* @param request the requested domain, or {@code null} if unspecified.
* @param cause the cause of the failure, or {@code null} if none.
* @return the exception to throw.
*/
protected final DataStoreException canNotRead(final String filename, final GridGeometry request, Throwable cause) {
final int DOMAIN = 1, REFERENCING = 2, CONTENT = 3;
// One of above constants, with 0 for "none of above".
int type = 0;
Envelope bounds = null;
if (cause instanceof DisjointExtentException) {
type = DOMAIN;
if (request != null && request.isDefined(GridGeometry.ENVELOPE)) {
bounds = request.getEnvelope();
}
} else if (cause instanceof RuntimeException) {
Throwable c = cause.getCause();
if (isReferencing(c)) {
type = REFERENCING;
cause = c;
} else if (cause instanceof ArithmeticException || cause instanceof RasterFormatException) {
type = CONTENT;
}
} else if (isReferencing(cause)) {
type = REFERENCING;
}
final String message = createExceptionMessage(filename, bounds);
switch(type) {
case DOMAIN:
return new NoSuchDataException(message, cause);
case REFERENCING:
return new DataStoreReferencingException(message, cause);
case CONTENT:
return new DataStoreContentException(message, cause);
default:
return new DataStoreException(message, cause);
}
}
Aggregations