1 16 17 package org.springframework.beans; 18 19 import java.beans.PropertyChangeEvent ; 20 21 import org.springframework.util.ClassUtils; 22 23 29 public class TypeMismatchException extends PropertyAccessException { 30 31 34 public static final String ERROR_CODE = "typeMismatch"; 35 36 37 private Object value; 38 39 private Class requiredType; 40 41 42 47 public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class requiredType) { 48 this(propertyChangeEvent, requiredType, null); 49 } 50 51 57 public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class requiredType, Throwable cause) { 58 super(propertyChangeEvent, 59 "Failed to convert property value of type [" + 60 (propertyChangeEvent.getNewValue() != null ? 61 ClassUtils.getQualifiedName(propertyChangeEvent.getNewValue().getClass()) : null) + "]" + 62 (requiredType != null ? 63 " to required type [" + ClassUtils.getQualifiedName(requiredType) + "]" : "") + 64 (propertyChangeEvent.getPropertyName() != null ? 65 " for property '" + propertyChangeEvent.getPropertyName() + "'" : ""), 66 cause); 67 this.value = propertyChangeEvent.getNewValue(); 68 this.requiredType = requiredType; 69 } 70 71 76 public TypeMismatchException(Object value, Class requiredType) { 77 this(value, requiredType, null); 78 } 79 80 86 public TypeMismatchException(Object value, Class requiredType, Throwable cause) { 87 super("Failed to convert value of type [" + 88 (value != null ? 89 ClassUtils.getQualifiedName(value.getClass()) : null) + "]" + 90 (requiredType != null ? 91 " to required type [" + ClassUtils.getQualifiedName(requiredType) + "]" : ""), 92 cause); 93 this.value = value; 94 this.requiredType = requiredType; 95 } 96 97 98 101 public Object getValue() { 102 return value; 103 } 104 105 108 public Class getRequiredType() { 109 return requiredType; 110 } 111 112 public String getErrorCode() { 113 return ERROR_CODE; 114 } 115 116 } 117 | Popular Tags |