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    import java.util.List;
035    
036    
037    /**
038     * Thrown by {@link ParameterValueGroup} if adding or removing a {@linkplain ParameterValue
039     * parameter value} would result in more or less parameters than the expected range. The
040     * [{@linkplain ParameterDescriptor#getMinimumOccurs minimum} …
041     *  {@linkplain ParameterDescriptor#getMaximumOccurs maximum}] range is defined by
042     * the {@link ParameterDescriptorGroup} instance associated with the {@code ParameterValueGroup}.
043     * <p>
044     * This exception may be thrown directly by the {@link ParameterValueGroup#addGroup(String)}
045     * method, or indirectly during the {@linkplain List#add add} or {@linkplain List#remove remove}
046     * operations on the list returned by {@link ParameterValueGroup#values()}.
047     *
048     * {@note This exception is of kind <code>IllegalStateException</code> instead than
049     *        <code>IllegalArgumentException</code> because it is not caused by a bad argument.
050     *        It is rather a consequence of an <code>ParameterValueGroup</code> being "full".}
051     *
052     * @departure extension
053     *   This exception is not part of the OGC specification.
054     *
055     * @author  Martin Desruisseaux (IRD)
056     * @version 3.0
057     * @since   2.0
058     *
059     * @see ParameterValueGroup#values()
060     * @see ParameterValueGroup#addGroup(String)
061     */
062    public class InvalidParameterCardinalityException extends IllegalStateException {
063        /**
064         * Serial number for inter-operability with different versions.
065         */
066        private static final long serialVersionUID = 4030549323541812311L;
067    
068        /**
069         * The name of the parameter with invalid cardinality.
070         */
071        private final String parameterName;
072    
073        /**
074         * Creates an exception with the specified message and parameter name.
075         *
076         * @param message The detail message, or {@code null} if none. The detail message
077         *                is saved for later retrieval by the {@link #getMessage()} method.
078         * @param parameterName The name of the parameter with invalid cardinality.
079         */
080        public InvalidParameterCardinalityException(String message, String parameterName) {
081            super(message);
082            this.parameterName = parameterName;
083        }
084    
085        /**
086         * Creates an exception with the specified message, cause and parameter name.
087         *
088         * @param message The detail message, or {@code null} if none. The detail message
089         *                is saved for later retrieval by the {@link #getMessage()} method.
090         * @param cause   The cause, or {@code null} if none. The cause is saved
091         *                for later retrieval by the {@link #getCause()} method.
092         * @param parameterName The name of the parameter with invalid cardinality.
093         *
094         * @since 3.1
095         */
096        public InvalidParameterCardinalityException(String message, Throwable cause, String parameterName) {
097            super(message, cause);
098            this.parameterName = parameterName;
099        }
100    
101        /**
102         * Returns the name of the parameter with invalid cardinality.
103         *
104         * @return The name of the parameter with invalid cardinality.
105         */
106        public String getParameterName() {
107            return parameterName;
108        }
109    }