01: package org.conform;
02:
03: import java.util.*;
04:
05: /**
06: * ValidationException
07: * <p/>
08: * Thrown if the validation of a field fails.
09: */
10: public class ValidationException extends RuntimeException {
11: Collection<Message> messages;
12:
13: public ValidationException(Message message) {
14: messages = Collections.singleton(message);
15: }
16:
17: public ValidationException(Collection<Message> messages) {
18: this .messages = messages;
19: }
20:
21: public Collection<Message> getMessages() {
22: return Collections.unmodifiableCollection(messages);
23: }
24:
25: public static class Message {
26: String code;
27: Object[] arguments;
28:
29: public Message(String code) {
30: this .code = code;
31: }
32:
33: public Message(String code, Object[] arguments) {
34: this .code = code;
35: this .arguments = arguments;
36: }
37:
38: public String getCode() {
39: return code;
40: }
41:
42: public Object[] getArguments() {
43: return arguments;
44: }
45:
46: public boolean equals(Object o) {
47: if (this == o)
48: return true;
49: if (o == null || getClass() != o.getClass())
50: return false;
51:
52: final Message message = (Message) o;
53:
54: if (!code.equals(message.code))
55: return false;
56:
57: return true;
58: }
59:
60: public int hashCode() {
61: return code.hashCode();
62: }
63:
64: public String toString() {
65: return code;
66: }
67: }
68:
69: public String toString() {
70: return "" + messages;
71: }
72: }
|