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 org.opengis.annotation.UML;
035 import static org.opengis.annotation.Specification.*;
036
037
038 /**
039 * Thrown by {@link ParameterValue} setter methods when they are given an invalid value.
040 *
041 * @author Martin Desruisseaux (IRD)
042 * @version 3.0
043 * @since 1.0
044 *
045 * @see ParameterValue#setValue(int)
046 * @see ParameterValue#setValue(double)
047 * @see ParameterValue#setValue(Object)
048 */
049 @UML(identifier="GC_InvalidParameterValue", specification=OGC_01004)
050 public class InvalidParameterValueException extends IllegalArgumentException {
051 /**
052 * Serial number for inter-operability with different versions.
053 */
054 private static final long serialVersionUID = 3814037056147642789L;
055
056 /**
057 * The parameter name.
058 */
059 private final String parameterName;
060
061 /**
062 * The invalid parameter value.
063 */
064 private final Object value;
065
066 /**
067 * Creates an exception with the specified invalid value.
068 *
069 * @param message The detail message, or {@code null} if none. The detail message
070 * is saved for later retrieval by the {@link #getMessage()} method.
071 * @param parameterName The parameter name.
072 * @param value The invalid parameter value.
073 */
074 public InvalidParameterValueException(String message, String parameterName, Object value) {
075 super(message);
076 this.parameterName = parameterName;
077 this.value = value;
078 }
079
080 /**
081 * Creates an exception with the specified invalid value as a floating point.
082 *
083 * @param message The detail message, or {@code null} if none. The detail message
084 * is saved for later retrieval by the {@link #getMessage()} method.
085 * @param parameterName The parameter name.
086 * @param value The invalid parameter value.
087 */
088 public InvalidParameterValueException(String message, String parameterName, double value) {
089 this(message, parameterName, Double.valueOf(value));
090 }
091
092 /**
093 * Creates an exception with the specified invalid value as an integer.
094 *
095 * @param message The detail message, or {@code null} if none. The detail message
096 * is saved for later retrieval by the {@link #getMessage()} method.
097 * @param parameterName The parameter name.
098 * @param value The invalid parameter value.
099 */
100 public InvalidParameterValueException(String message, String parameterName, int value) {
101 this(message, parameterName, Integer.valueOf(value));
102 }
103
104 /**
105 * Creates an exception with the specified message, cause and invalid value.
106 *
107 * @param message The detail message, or {@code null} if none. The detail message
108 * is saved for later retrieval by the {@link #getMessage()} method.
109 * @param cause The cause, or {@code null} if none. The cause is saved
110 * for later retrieval by the {@link #getCause()} method.
111 * @param parameterName The parameter name.
112 * @param value The invalid parameter value.
113 *
114 * @since 3.1
115 */
116 public InvalidParameterValueException(String message, Throwable cause, String parameterName, Object value) {
117 super(message, cause);
118 this.parameterName = parameterName;
119 this.value = value;
120 }
121
122 /**
123 * Returns the parameter name.
124 *
125 * @return The parameter name.
126 */
127 public String getParameterName() {
128 return parameterName;
129 }
130
131 /**
132 * Returns the invalid parameter value.
133 *
134 * @return The invalid parameter value.
135 */
136 public Object getValue() {
137 return value;
138 }
139 }