1 23 24 package org.infoglue.cms.exception; 25 26 27 37 public class ConstraintException extends Exception { 38 41 private String errorCode; 43 private String fieldName; 45 private ConstraintException chainedException; 47 48 49 50 53 59 public ConstraintException(String fieldName, String errorCode) 60 { 61 super(); 62 63 this.fieldName = (fieldName == null) ? "" : fieldName; 65 this.errorCode = (errorCode == null) ? "" : errorCode; 66 } 67 68 71 public ConstraintException(String fieldName, String errorCode, ConstraintException chainedException) { 72 this(fieldName, errorCode); 73 this.chainedException = chainedException; 74 } 75 76 77 78 80 83 public void setChainedException(ConstraintException chainedException) { 84 this.chainedException = chainedException; 85 } 86 87 90 public ConstraintException getChainedException() { 91 return this.chainedException; 92 } 93 94 97 public String getFieldName() { 98 return this.fieldName; 99 } 100 101 104 public String getErrorCode() { 105 return this.errorCode; 106 } 107 108 109 110 113 116 public String getMessage() { 117 return "Constrain violated on field [" + this.fieldName + "], code [" + this.errorCode + "]"; 118 } 119 120 121 122 124 127 public String toString() { 128 return "<ConstraintException>[" + getFieldName() + "," + getErrorCode() + "]"; 129 } 130 131 140 public boolean equals(Object o) { 141 if(o == null || !(o instanceof ConstraintException)) { 142 return false; 143 } 144 final ConstraintException e = (ConstraintException) o; 145 return getFieldName().equals(e.getFieldName()) && getErrorCode().equals(e.getErrorCode()); 146 } 147 148 154 public int hashCode() { 155 return (getFieldName() + getErrorCode()).hashCode(); 156 } 157 158 159 160 } | Popular Tags |