1 56 57 package org.jdom.contrib.schema; 58 59 65 public class ValidationError { 66 67 public final static Severity WARNING = new Severity(0); 68 69 public final static Severity ERROR = new Severity(1); 70 71 public final static Severity FATAL = new Severity(2); 72 73 76 private final Severity severity; 77 78 81 private final String message; 82 83 86 private final Object node; 87 88 94 public ValidationError(Severity severity, String message) { 95 this(severity, message, null); 96 } 97 98 105 public ValidationError(Severity severity, String message, Object node) { 106 this.severity = severity; 107 this.message = message; 108 this.node = node; 109 } 110 111 116 public Severity getSeverity() { 117 return this.severity; 118 } 119 120 125 public String getMessage() { 126 return this.message; 127 } 128 129 134 public Object getNode() { 135 return this.node; 136 } 137 138 146 public String toString() { 147 StringBuffer buf = new StringBuffer (); 148 149 buf.append('['); 150 if (this.severity == WARNING) { 151 buf.append("WARNING"); 152 } 153 else if (this.severity == ERROR) { 154 buf.append("ERROR"); 155 } 156 else if (this.severity == FATAL) { 157 buf.append("FATAL"); 158 } 159 buf.append("] message: \"").append(this.getMessage()); 160 161 if (this.getNode() != null) { 162 buf.append("\", location: \"").append(this.getNode().toString()); 163 } 164 buf.append("\""); 165 166 return buf.toString(); 167 } 168 169 170 174 public static final class Severity { 175 176 private final int level; 177 178 183 protected Severity(int level) { 184 this.level = level; 185 } 186 187 194 public int hashCode() { 195 return this.level; 196 } 197 198 206 public String toString() { 207 return "[" + this.getClass().getName() + "] " + this.level; 208 } 209 210 223 public boolean equals(Object o) { 224 return ((o == this) || 225 ((o != null) && (this.hashCode() == o.hashCode()) && 226 (this.getClass().getName().equals(o.getClass().getName())))); 227 } 228 } 229 } 230 231 | Popular Tags |