1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util;
17
18 import org.apache.commons.lang.ArrayUtils;
19 import org.apache.commons.lang.StringUtils;
20
21 import java.io.Serializable;
22 import java.util.Arrays;
23
24
25
26
27
28
29 public class ErrorMessage implements Serializable {
30 private static final long serialVersionUID = 4397449554212875250L;
31
32 private String namespaceCode;
33 private String componentCode;
34
35 private String errorKey;
36 private String[] messageParameters;
37
38 private String messagePrefixKey;
39 private String[] messagePrefixParameters;
40
41 private String messageSuffixKey;
42 private String[] messageSuffixParameters;
43
44
45
46
47 public ErrorMessage() {
48 }
49
50
51
52
53
54
55
56 public ErrorMessage(String errorKey, String... messageParameters) {
57 if (StringUtils.isBlank(errorKey)) {
58 StringBuilder builder = null;
59 if (messageParameters != null && messageParameters.length > 0) {
60 builder = new StringBuilder(" Message parameters are: ");
61 for (String param: messageParameters) {
62 builder.append(param).append("\n");
63 }
64 } else {
65 builder = new StringBuilder(" Message parameters were null or empty.");
66 }
67 throw new IllegalArgumentException("invalid (blank) errorKey." + builder.toString());
68 }
69
70 setErrorKey(errorKey);
71 setMessageParameters((String[]) ArrayUtils.clone(messageParameters));
72 }
73
74
75
76
77
78
79
80
81
82
83
84 public String getNamespaceCode() {
85 return namespaceCode;
86 }
87
88
89
90
91
92
93 public void setNamespaceCode(String namespaceCode) {
94 this.namespaceCode = namespaceCode;
95 }
96
97
98
99
100
101
102
103
104
105
106
107 public String getComponentCode() {
108 return componentCode;
109 }
110
111
112
113
114
115
116 public void setComponentCode(String componentCode) {
117 this.componentCode = componentCode;
118 }
119
120
121
122
123
124
125 public void setErrorKey(String errorKey) {
126 if (StringUtils.isBlank(errorKey)) {
127 throw new IllegalArgumentException("invalid (blank) errorKey");
128 }
129
130 this.errorKey = errorKey;
131 }
132
133
134
135
136
137
138 public String getErrorKey() {
139 return errorKey;
140 }
141
142
143
144
145
146
147 public void setMessageParameters(String[] messageParameters) {
148 this.messageParameters = messageParameters;
149 }
150
151
152
153
154
155
156
157 public String[] getMessageParameters() {
158 return messageParameters;
159 }
160
161
162
163
164 @Override
165 public String toString() {
166 StringBuffer s = new StringBuffer(getErrorKey());
167
168 String[] params = getMessageParameters();
169 if (params != null) {
170 s.append("(");
171 for (int i = 0; i < params.length; ++i) {
172 if (i > 0) {
173 s.append(", ");
174 }
175 s.append(params[i]);
176 }
177 s.append(")");
178 }
179 return s.toString();
180 }
181
182
183
184
185 @Override
186 public boolean equals(Object obj) {
187 boolean equals = false;
188
189 if (this == obj) {
190 equals = true;
191 } else if (obj instanceof ErrorMessage) {
192 ErrorMessage other = (ErrorMessage) obj;
193
194 if (StringUtils.equals(getErrorKey(), other.getErrorKey())) {
195 equals = Arrays.equals(getMessageParameters(), other.getMessageParameters());
196 }
197 }
198
199 return equals;
200 }
201
202
203
204
205
206
207 @Override
208 public int hashCode() {
209 int hashCode = 5011966;
210
211 if (getErrorKey() != null) {
212 hashCode = getErrorKey().hashCode();
213 }
214
215 return hashCode;
216 }
217
218
219
220
221
222
223
224
225 public String getMessagePrefixKey() {
226 return messagePrefixKey;
227 }
228
229
230
231
232
233
234 public void setMessagePrefixKey(String messagePrefixKey) {
235 this.messagePrefixKey = messagePrefixKey;
236 }
237
238
239
240
241
242
243
244
245 public String getMessageSuffixKey() {
246 return messageSuffixKey;
247 }
248
249
250
251
252
253
254 public void setMessageSuffixKey(String messageSuffixKey) {
255 this.messageSuffixKey = messageSuffixKey;
256 }
257
258
259
260
261
262
263
264 public String[] getMessagePrefixParameters() {
265 return messagePrefixParameters;
266 }
267
268
269
270
271
272
273 public void setMessagePrefixParameters(String[] messagePrefixParameters) {
274 this.messagePrefixParameters = messagePrefixParameters;
275 }
276
277
278
279
280
281
282
283 public String[] getMessageSuffixParameters() {
284 return messageSuffixParameters;
285 }
286
287
288
289
290
291
292 public void setMessageSuffixParameters(String[] messageSuffixParameters) {
293 this.messageSuffixParameters = messageSuffixParameters;
294 }
295 }