001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * Copyright © 2004-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.parameter; 019 020import org.opengis.annotation.UML; 021import static org.opengis.annotation.Specification.*; 022 023 024/** 025 * Thrown by {@link ParameterValue} setter methods when they are given an invalid value. 026 * The value may be invalid because it is not assignable to the Java 027 * {@linkplain ParameterDescriptor#getValueClass() value class}, not a member of the 028 * {@linkplain ParameterDescriptor#getValidValues() valid values} set, or any other reason. 029 * This exception is typically thrown by the following methods: 030 * 031 * <ul> 032 * <li>{@link ParameterValue#setValue(int)}</li> 033 * <li>{@link ParameterValue#setValue(double)}</li> 034 * <li>{@link ParameterValue#setValue(Object)}</li> 035 * <li>Any other setter method.</li> 036 * </ul> 037 * 038 * @author Martin Desruisseaux (IRD) 039 * @version 3.0 040 * @since 1.0 041 * 042 * @see InvalidParameterTypeException 043 */ 044@UML(identifier="GC_InvalidParameterValue", specification=OGC_01004) 045public class InvalidParameterValueException extends IllegalArgumentException { 046 /** 047 * Serial number for inter-operability with different versions. 048 */ 049 private static final long serialVersionUID = 3814037056147642789L; 050 051 /** 052 * The parameter name. 053 */ 054 private final String parameterName; 055 056 /** 057 * The invalid parameter value. 058 */ 059 @SuppressWarnings("serial") // Typicall a String, Integer, Double or URI instance. 060 private final Object value; 061 062 /** 063 * Creates an exception with the specified invalid value. 064 * 065 * @param message the detail message, saved for later retrieval by the {@link #getMessage()} method. 066 * @param parameterName the parameter name. 067 * @param value the invalid parameter value. 068 */ 069 public InvalidParameterValueException(String message, String parameterName, Object value) { 070 super(message); 071 this.parameterName = parameterName; 072 this.value = value; 073 } 074 075 /** 076 * Creates an exception with the specified invalid value as a floating point. 077 * 078 * @param message the detail message, saved for later retrieval by the {@link #getMessage()} method. 079 * @param parameterName the parameter name. 080 * @param value the invalid parameter value. 081 */ 082 public InvalidParameterValueException(String message, String parameterName, double value) { 083 this(message, parameterName, Double.valueOf(value)); 084 } 085 086 /** 087 * Creates an exception with the specified invalid value as an integer. 088 * 089 * @param message the detail message, saved for later retrieval by the {@link #getMessage()} method. 090 * @param parameterName the parameter name. 091 * @param value the invalid parameter value. 092 */ 093 public InvalidParameterValueException(String message, String parameterName, int value) { 094 this(message, parameterName, Integer.valueOf(value)); 095 } 096 097 /** 098 * Creates an exception with the specified message, cause and invalid value. 099 * 100 * @param message the detail message, saved for later retrieval by the {@link #getMessage()} method. 101 * @param cause the cause, saved for later retrieval by the {@link #getCause()} method. 102 * @param parameterName the parameter name. 103 * @param value the invalid parameter value. 104 * 105 * @since 3.1 106 */ 107 public InvalidParameterValueException(String message, Throwable cause, String parameterName, Object value) { 108 super(message, cause); 109 this.parameterName = parameterName; 110 this.value = value; 111 } 112 113 /** 114 * Returns the parameter name. 115 * 116 * @return the parameter name. 117 */ 118 public String getParameterName() { 119 return parameterName; 120 } 121 122 /** 123 * Returns the invalid parameter value. 124 * 125 * @return the invalid parameter value. 126 */ 127 public Object getValue() { 128 return value; 129 } 130}