001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Management Committee (PMC)
005: * (C) 2005, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.coverage;
018:
019: // J2SE dependencies
020: import java.util.Date;
021:
022: // OpenGIS dependencies
023: import org.opengis.geometry.Envelope;
024: import org.opengis.coverage.PointOutsideCoverageException;
025:
026: // Geotools dependencies
027: import org.geotools.resources.i18n.Errors;
028: import org.geotools.resources.i18n.ErrorKeys;
029:
030: /**
031: * Thrown when an {@code evaluate(...)} method method is invoked with a point outside coverage.
032: * This subclass of {@code PointOutsideCoverage} exception is used when the dimension of the
033: * out-of-bounds ordinate is known.
034: *
035: * @since 2.1
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/main/java/org/geotools/coverage/OrdinateOutsideCoverageException.java $
037: * @version $Id: OrdinateOutsideCoverageException.java 24925 2007-03-27 20:12:08Z jgarnett $
038: * @author Martin Desruisseaux
039: */
040: public class OrdinateOutsideCoverageException extends
041: PointOutsideCoverageException {
042: /**
043: * Serial number for interoperability with different versions.
044: */
045: private static final long serialVersionUID = -4718948524305632185L;
046:
047: /**
048: * The dimension of the out-of-bounds ordinate.
049: */
050: private final int dimension;
051:
052: /**
053: * The coverage envelope, or {@code null} if unknown.
054: */
055: private final Envelope envelope;
056:
057: /**
058: * Creates an exception with the specified message.
059: *
060: * @param message The detail message. The detail message is saved for
061: * later retrieval by the {@link #getMessage()} method.
062: * @param dimension The dimension of the out-of-bounds ordinate.
063: */
064: public OrdinateOutsideCoverageException(final String message,
065: final int dimension) {
066: super (message);
067: this .dimension = dimension;
068: this .envelope = null;
069: }
070:
071: /**
072: * Creates an exception with the specified message.
073: *
074: * @param message The detail message. The detail message is saved for
075: * later retrieval by the {@link #getMessage()} method.
076: * @param dimension The dimension of the out-of-bounds ordinate.
077: * @param envelope The coverage envelope, or {@code null} if unknown.
078: *
079: * @since 2.3
080: */
081: public OrdinateOutsideCoverageException(final String message,
082: final int dimension, final Envelope envelope) {
083: super (message);
084: this .dimension = dimension;
085: this .envelope = envelope;
086: }
087:
088: /**
089: * Creates an exception with the specified cause and an automaticaly formatted message. This
090: * constructor assumes that the out-of-bounds value was the temporal ordinate (i.e. the date).
091: * This condition should be verified before to invoke this constructor. A localized error
092: * message including the specified date is then formatted.
093: * <p>
094: * This constructor is for internal use by {@code evaluate(Point2D, Date, ...)} methods in
095: * {@link SpatioTemporalCoverage3D}, in order to replace dates as numerical values by a more
096: * explicit string. Users can still get the numerical value if they looks at the cause of this
097: * exception.
098: */
099: OrdinateOutsideCoverageException(
100: final OrdinateOutsideCoverageException cause,
101: final Date date) {
102: super (Errors.format(ErrorKeys.DATE_OUTSIDE_COVERAGE_$1, date));
103: dimension = cause.dimension;
104: envelope = cause.envelope;
105: initCause(cause);
106: }
107:
108: /**
109: * Returns the dimension of the out-of-bounds ordinate.
110: */
111: public int getOutOfBoundsDimension() {
112: return dimension;
113: }
114:
115: /**
116: * Returns the coverage envelope, or {@code null} if unknown.
117: *
118: * @since 2.3
119: */
120: public Envelope getCoverageEnvelope() {
121: return envelope;
122: }
123: }
|