blob: aae231739e1275eb335efd9d74072d2ca8937ca5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*
@VaadinApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* Class for combining multiple error messages together.
*
* @author Vaadin Ltd
* @version
* @VERSION@
* @since 3.0
*/
@SuppressWarnings("serial")
public class CompositeErrorMessage implements ErrorMessage, Serializable {
/**
* Array of all the errors.
*/
private final List<ErrorMessage> errors;
/**
* Level of the error.
*/
private int level;
/**
* Constructor for CompositeErrorMessage.
*
* @param errorMessages
* the Array of error messages that are listed togeter. Nulls are
* ignored, but at least one message is required.
*/
public CompositeErrorMessage(ErrorMessage[] errorMessages) {
errors = new ArrayList<ErrorMessage>(errorMessages.length);
level = Integer.MIN_VALUE;
for (int i = 0; i < errorMessages.length; i++) {
addErrorMessage(errorMessages[i]);
}
if (errors.size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
}
/**
* Constructor for CompositeErrorMessage.
*
* @param errorMessages
* the Collection of error messages that are listed together. At
* least one message is required.
*/
public CompositeErrorMessage(
Collection<? extends ErrorMessage> errorMessages) {
errors = new ArrayList<ErrorMessage>(errorMessages.size());
level = Integer.MIN_VALUE;
for (final Iterator<? extends ErrorMessage> i = errorMessages
.iterator(); i.hasNext();) {
addErrorMessage(i.next());
}
if (errors.size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
}
/**
* The error level is the largest error level in
*
* @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
*/
public final int getErrorLevel() {
return level;
}
/**
* Adds a error message into this composite message. Updates the level
* field.
*
* @param error
* the error message to be added. Duplicate errors are ignored.
*/
private void addErrorMessage(ErrorMessage error) {
if (error != null && !errors.contains(error)) {
errors.add(error);
final int l = error.getErrorLevel();
if (l > level) {
level = l;
}
}
}
/**
* Gets Error Iterator.
*
* @return the error iterator.
*/
public Iterator<ErrorMessage> iterator() {
return errors.iterator();
}
/**
* @see com.vaadin.terminal.Paintable#paint(com.vaadin.terminal.PaintTarget)
*/
public void paint(PaintTarget target) throws PaintException {
if (errors.size() == 1) {
(errors.iterator().next()).paint(target);
} else {
target.startTag("error");
if (level > 0 && level <= ErrorMessage.INFORMATION) {
target.addAttribute("level", "info");
} else if (level <= ErrorMessage.WARNING) {
target.addAttribute("level", "warning");
} else if (level <= ErrorMessage.ERROR) {
target.addAttribute("level", "error");
} else if (level <= ErrorMessage.CRITICAL) {
target.addAttribute("level", "critical");
} else {
target.addAttribute("level", "system");
}
// Paint all the exceptions
for (final Iterator<ErrorMessage> i = errors.iterator(); i
.hasNext();) {
i.next().paint(target);
}
target.endTag("error");
}
}
/* Documented in super interface */
public void addListener(RepaintRequestListener listener) {
}
/* Documented in super interface */
public void removeListener(RepaintRequestListener listener) {
}
/* Documented in super interface */
public void requestRepaint() {
}
/* Documented in super interface */
public void requestRepaintRequests() {
}
/**
* Returns a comma separated list of the error messages.
*
* @return String, comma separated list of error messages.
*/
@Override
public String toString() {
String retval = "[";
int pos = 0;
for (final Iterator<ErrorMessage> i = errors.iterator(); i.hasNext();) {
if (pos > 0) {
retval += ",";
}
pos++;
retval += i.next().toString();
}
retval += "]";
return retval;
}
public String getDebugId() {
return null;
}
public void setDebugId(String id) {
throw new UnsupportedOperationException(
"Setting testing id for this Paintable is not implemented");
}
}
|