1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import java.util.Vector;
27
28
29
30 /***
31 * This exception may be thrown by user code in classes implementing the
32 * interceptor interface Allows developers to define more then one error - to
33 * be used in conjunction with the XML errors mechanism
34 */
35 public class MultipleValidationException extends ValidationException {
36 private Vector messages = null;
37
38 /***
39 * Creates a new MultipleValidationException object.
40 *
41 * @param message DOCUMENT ME!
42 */
43 public MultipleValidationException(String message) {
44 super();
45 addMessage(message);
46 }
47
48
49 /***
50 * Creates a new MultipleValidationException object.
51 *
52 * @param messages DOCUMENT ME!
53 */
54 public MultipleValidationException(Vector messages) {
55 super();
56 this.setMessages(messages);
57 }
58
59 /***
60 * Returns the detail message string of this throwable. <br>
61 * Override the <code>getMessage</code> method of the
62 * <code>Throwable</code> class. <br>
63 * Note: the Throwable class' <code>toString</code> method calls
64 * <code>getLocalizedMessage()</code> to get the string representation of
65 * the detaile error message. The original
66 * <code>getLocalizedMessage()</code> implementation calls
67 * <code>getMessage()</code>. <br>
68 * Overriding <code>getMessage</code> to get the multiple messages from
69 * this exception class let Log4j category classes log all the error
70 * messages. (fossato, 2002.11.29)
71 *
72 * @return the detail message string of this <tt>Throwable</tt> instance
73 */
74 public String getMessage() {
75 StringBuffer sb = new StringBuffer();
76
77 if (messages != null) {
78 for (int i = 0; i < messages.size(); i++) {
79 Object o = messages.elementAt(i);
80
81 if (o != null) {
82 sb.append(o.toString())
83 .append("\n");
84 }
85 }
86 }
87
88 return sb.toString();
89 }
90
91
92 /***
93 * Sets the messages
94 *
95 * @param messages The messages to set
96 */
97 public void setMessages(Vector messages) {
98 this.messages = messages;
99 }
100
101
102 /***
103 * Gets the messages
104 *
105 * @return Returns a Vector
106 */
107 public Vector getMessages() {
108 return messages;
109 }
110
111
112 /***
113 * DOCUMENT ME!
114 *
115 * @param message DOCUMENT ME!
116 */
117 public void addMessage(String message) {
118 if (messages == null) {
119 messages = new Vector();
120 }
121 messages.add(new Exception(message));
122 }
123 }