1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.graph.property; 25 26 import net.jcip.annotations.Immutable; 27 28 /** 29 * A runtime exception denoting that a value could not be converted to a specific type because of the value's format. 30 */ 31 @Immutable 32 public class ValueFormatException extends RuntimeException { 33 34 /** 35 */ 36 private static final long serialVersionUID = 1L; 37 38 private final Object value; 39 private final PropertyType targetType; 40 41 /** 42 * @param value the value that was not able to be converted 43 * @param targetType the {@link PropertyType} to which the value was being converted 44 */ 45 public ValueFormatException( Object value, 46 PropertyType targetType ) { 47 this.value = value; 48 this.targetType = targetType; 49 } 50 51 /** 52 * @param value the value that was not able to be converted 53 * @param targetType the {@link PropertyType} to which the value was being converted 54 * @param message the message 55 */ 56 public ValueFormatException( Object value, 57 PropertyType targetType, 58 String message ) { 59 super(message); 60 this.value = value; 61 this.targetType = targetType; 62 } 63 64 /** 65 * @param value the value that was not able to be converted 66 * @param targetType the {@link PropertyType} to which the value was being converted 67 * @param cause the cause of the exception 68 */ 69 public ValueFormatException( Object value, 70 PropertyType targetType, 71 Throwable cause ) { 72 super(cause); 73 this.value = value; 74 this.targetType = targetType; 75 } 76 77 /** 78 * @param value the value that was not able to be converted 79 * @param targetType the {@link PropertyType} to which the value was being converted 80 * @param message the message 81 * @param cause the cause of the exception 82 */ 83 public ValueFormatException( Object value, 84 PropertyType targetType, 85 String message, 86 Throwable cause ) { 87 super(message, cause); 88 this.value = value; 89 this.targetType = targetType; 90 } 91 92 /** 93 * {@inheritDoc} 94 */ 95 @Override 96 public String toString() { 97 return super.toString(); 98 } 99 100 /** 101 * Get the {@link PropertyType} to which the {@link #getValue() value} was being converted. 102 * 103 * @return the target type 104 */ 105 public PropertyType getTargetType() { 106 return targetType; 107 } 108 109 /** 110 * Get the original value that was being converted. 111 * 112 * @return the value 113 */ 114 public Object getValue() { 115 return value; 116 } 117 }