Search in sources :

Example 1 with NoSuchDataException

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);
    }
}
Also used : DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) DataStoreException(org.apache.sis.storage.DataStoreException) DataStoreContentException(org.apache.sis.storage.DataStoreContentException) DataStoreReferencingException(org.apache.sis.storage.DataStoreReferencingException) Envelope(org.opengis.geometry.Envelope) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) RasterFormatException(java.awt.image.RasterFormatException)

Aggregations

RasterFormatException (java.awt.image.RasterFormatException)1 DisjointExtentException (org.apache.sis.coverage.grid.DisjointExtentException)1 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 DataStoreReferencingException (org.apache.sis.storage.DataStoreReferencingException)1 NoSuchDataException (org.apache.sis.storage.NoSuchDataException)1 Envelope (org.opengis.geometry.Envelope)1