001/*
002 *    GeoAPI - Java interfaces for OGC/ISO standards
003 *    Copyright © 2015-2023 Open Geospatial Consortium, Inc.
004 *    http://www.geoapi.org
005 *
006 *    Licensed under the Apache License, Version 2.0 (the "License");
007 *    you may not use this file except in compliance with the License.
008 *    You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *    Unless required by applicable law or agreed to in writing, software
013 *    distributed under the License is distributed on an "AS IS" BASIS,
014 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 *    See the License for the specific language governing permissions and
016 *    limitations under the License.
017 */
018package org.opengis.feature;
019
020import java.util.Collection;
021
022
023/**
024 * Thrown when an {@link Attribute} value or a {@link FeatureAssociation} does not met the constraints
025 * (other than Java class) specified by its type. This exception can be thrown by implementations that
026 * perform validity checks. Such verifications happen typically in the following methods:
027 * <ul>
028 *   <li>In {@code Attribute}:
029 *     <ul>
030 *       <li>{@link Attribute#setValue(Object) setValue(Object)}</li>
031 *       <li>{@link Attribute#setValues(Collection) setValues(Collection)}</li>
032 *     </ul>
033 *   </li>
034 *   <li>In {@code FeatureAssociation}:
035 *     <ul>
036 *       <li>{@link FeatureAssociation#setValue(Feature) setValue(Feature)}</li>
037 *       <li>{@link FeatureAssociation#setValues(Collection) setValues(Collection)}</li>
038 *     </ul>
039 *   </li>
040 *   <li>In {@code Feature}:
041 *     <ul>
042 *       <li>{@link Feature#setProperty(Property) setProperty(Property)}</li>
043 *       <li>{@link Feature#setPropertyValue(String, Object) setPropertyValue(String, Object)}</li>
044 *     </ul>
045 *   </li>
046 * </ul>
047 *
048 * <h2>Exception for invalid class</h2>
049 * Libraries may throw {@link ClassCastException} instead of this {@code InvalidPropertyValueException} when
050 * the given value is not an instance of the expected class (typically {@link AttributeType#getValueClass()}).
051 * The reason is that libraries may rely on Java parameterized types, which throws {@code ClassCastException}
052 * at runtime when the objects are used in an unsafe way. Libraries may also rely on {@link Class#cast(Object)}
053 * or {@link Class#asSubclass(Class)} standard methods, which are designed to throw {@code ClassCastException},
054 * or may way to be consistent with all the above.
055 *
056 * @author  Martin Desruisseaux (Geomatys)
057 * @version 3.1
058 * @since   3.1
059 */
060public class InvalidPropertyValueException extends IllegalArgumentException {
061    /**
062     * Serial number for inter-operability with different versions.
063     */
064    private static final long serialVersionUID = 3769646492399262226L;
065
066    /**
067     * Creates an exception with no message.
068     */
069    public InvalidPropertyValueException() {
070        super();
071    }
072
073    /**
074     * Creates an exception with the specified message.
075     *
076     * @param message  the detail message, saved for later retrieval by the {@link #getMessage()} method.
077     */
078    public InvalidPropertyValueException(final String message) {
079        super(message);
080    }
081
082    /**
083     * Creates an exception with the specified message and cause.
084     *
085     * @param message  the detail message, saved for later retrieval by the {@link #getMessage()} method.
086     * @param cause    the cause, saved for later retrieval by the {@link #getCause()} method.
087     */
088    public InvalidPropertyValueException(final String message, final Throwable cause) {
089        super(message, cause);
090    }
091}