001    /*
002     *    GeoAPI - Java interfaces for OGC/ISO standards
003     *    http://www.geoapi.org
004     *
005     *    Copyright (C) 2004-2012 Open Geospatial Consortium, Inc.
006     *    All Rights Reserved. http://www.opengeospatial.org/ogc/legal
007     *
008     *    Permission to use, copy, and modify this software and its documentation, with
009     *    or without modification, for any purpose and without fee or royalty is hereby
010     *    granted, provided that you include the following on ALL copies of the software
011     *    and documentation or portions thereof, including modifications, that you make:
012     *
013     *    1. The full text of this NOTICE in a location viewable to users of the
014     *       redistributed or derivative work.
015     *    2. Notice of any changes or modifications to the OGC files, including the
016     *       date changes were made.
017     *
018     *    THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE
019     *    NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
020     *    TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
021     *    THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
022     *    PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
023     *
024     *    COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
025     *    CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
026     *
027     *    The name and trademarks of copyright holders may NOT be used in advertising or
028     *    publicity pertaining to the software without specific, written prior permission.
029     *    Title to copyright in this software and any associated documentation will at all
030     *    times remain with copyright holders.
031     */
032    package org.opengis.parameter;
033    
034    
035    /**
036     * Thrown by {@link ParameterValue} getter methods when a value can not be casted to the
037     * requested type. For example this exception is thrown when {@link ParameterValue#doubleValue()}
038     * is invoked but the value is not convertible to a {@code double}.
039     *
040     * {@note This exception is of kind <code>IllegalStateException</code> instead than
041     *        <code>IllegalArgumentException</code> because it is not caused by a bad argument.
042     *        It is rather a consequence of a zero-argument method invoked in a context where
043     *        is it not allowed.}
044     *
045     * @departure extension
046     *   This exception is not part of the OGC specification.
047     *
048     * @author  Martin Desruisseaux (IRD)
049     * @version 3.0
050     * @since   1.0
051     *
052     * @see ParameterValue#intValue()
053     * @see ParameterValue#doubleValue()
054     * @see ParameterValue#booleanValue()
055     * @see ParameterValue#stringValue()
056     * @see ParameterValue#valueFile()
057     */
058    public class InvalidParameterTypeException extends IllegalStateException {
059        /**
060         * Serial number for inter-operability with different versions.
061         */
062        private static final long serialVersionUID = 2740762597003093176L;
063    
064        /**
065         * The invalid parameter name.
066         */
067        private final String parameterName;
068    
069        /**
070         * Creates an exception with the specified message and parameter name.
071         *
072         * @param message The detail message, or {@code null} if none. The detail message
073         *                is saved for later retrieval by the {@link #getMessage()} method.
074         * @param parameterName The parameter name.
075         */
076        public InvalidParameterTypeException(String message, String parameterName) {
077            super(message);
078            this.parameterName = parameterName;
079        }
080    
081        /**
082         * Creates an exception with the specified message, cause and parameter name.
083         *
084         * @param message The detail message, or {@code null} if none. The detail message
085         *                is saved for later retrieval by the {@link #getMessage()} method.
086         * @param cause   The cause, or {@code null} if none. The cause is saved
087         *                for later retrieval by the {@link #getCause()} method.
088         * @param parameterName The parameter name.
089         *
090         * @since 3.1
091         */
092        public InvalidParameterTypeException(String message, Throwable cause, String parameterName) {
093            super(message, cause);
094            this.parameterName = parameterName;
095        }
096    
097        /**
098         * Returns the parameter name.
099         *
100         * @return The parameter name.
101         */
102        public String getParameterName() {
103            return parameterName;
104        }
105    }