1
2
3
4
5 package pt.digitalis.dif.dem.objects.parameters.errors;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint;
11 import pt.digitalis.dif.dem.objects.parameters.constraints.ParameterConstraintResult;
12 import pt.digitalis.dif.dem.objects.parameters.rules.IParameterRule;
13 import pt.digitalis.dif.dem.objects.parameters.validators.IParameterValidator;
14 import pt.digitalis.dif.utils.ObjectFormatter;
15
16
17
18
19
20
21
22 public class ParameterError {
23
24
25 private IParameterConstraint constraint;
26
27
28 private List<String> errorIDs = new ArrayList<String>();
29
30
31 private ParameterErrorType errorType;
32
33
34 private Exception exception;
35
36
37 private boolean forceShowError = false;
38
39
40 private String id;
41
42
43
44
45 private String message;
46
47
48 private IParameterRule<?> rule;
49
50
51 private IParameterValidator validator;
52
53
54
55
56 public ParameterError()
57 {
58 super();
59 }
60
61
62
63
64
65
66
67
68
69 public ParameterError(String constraintId, ParameterConstraintResult constraintResult)
70 {
71 if (constraintResult.getLanguage() != null)
72 {
73 this.message = constraintResult.getConstraint().validationErrorMessage(constraintResult.getLanguage());
74 }
75 else
76 {
77 this.message = constraintResult.getConstraint().validationErrorMessage();
78 }
79
80 this.errorType = ParameterErrorType.CONSTRAINT;
81 this.id = constraintId;
82 this.constraint = constraintResult.getConstraint();
83 this.validator = null;
84 if (constraintResult.getErrorIDs() != null)
85 {
86 this.errorIDs.addAll(constraintResult.getErrorIDs());
87 }
88 }
89
90
91
92
93
94
95
96
97
98 public ParameterError(String message, ParameterErrorType errorType)
99 {
100 this.message = message;
101 this.errorType = errorType;
102 this.id = null;
103 this.constraint = null;
104 this.validator = null;
105 }
106
107
108
109
110
111
112 public IParameterConstraint getConstraint()
113 {
114 return constraint;
115 }
116
117
118
119
120
121
122 public List<String> getErrorIDs()
123 {
124 return errorIDs;
125 }
126
127
128
129
130
131
132 public ParameterErrorType getErrorType()
133 {
134 return errorType;
135 }
136
137
138
139
140
141
142 public Exception getException()
143 {
144 return exception;
145 }
146
147
148
149
150
151
152 public String getId()
153 {
154 return id;
155 }
156
157
158
159
160
161
162 public String getMessage()
163 {
164 return message;
165 }
166
167
168
169
170
171
172 public IParameterRule<?> getRule()
173 {
174 return rule;
175 }
176
177
178
179
180
181
182 public IParameterValidator getValidator()
183 {
184 return validator;
185 }
186
187
188
189
190
191
192 public boolean isForceShowError()
193 {
194 return forceShowError;
195 }
196
197
198
199
200
201
202
203
204
205 public void setConstraint(String id, IParameterConstraint constraint)
206 {
207 this.id = id;
208 this.constraint = constraint;
209 }
210
211
212
213
214
215
216
217 public void setErrorIDs(List<String> errorIDs)
218 {
219 this.errorIDs = errorIDs;
220 }
221
222
223
224
225
226
227
228 public void setException(Exception exception)
229 {
230 this.exception = exception;
231 }
232
233
234
235
236
237
238
239 public void setForceShowError(boolean forceShowError)
240 {
241 this.forceShowError = forceShowError;
242 }
243
244
245
246
247
248
249
250 public void setId(String newID)
251 {
252 this.id = newID;
253 }
254
255
256
257
258
259
260
261 public void setMessage(String message)
262 {
263 this.message = message;
264 }
265
266
267
268
269
270
271
272 public void setRule(IParameterRule<?> rule)
273 {
274 this.rule = rule;
275 }
276
277
278
279
280
281
282
283
284
285 public void setValidator(String id, IParameterValidator validator)
286 {
287 this.id = id;
288 this.validator = validator;
289 }
290
291
292
293
294 @Override
295 public String toString()
296 {
297 ObjectFormatter formatter = new ObjectFormatter();
298 formatter.addItem("Message", message);
299 formatter.addItem("Error Type", errorType);
300 formatter.addItemIfNotNull("ID", id);
301 formatter.addItemIfNotNull("Constraint", constraint);
302 formatter.addItemIfNotNull("Validator", validator);
303 formatter.addItemIfNotNull("Exception", exception);
304
305 return formatter.getFormatedObject();
306 }
307 }