1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.util; |
17 | |
|
18 | |
|
19 | |
import org.apache.commons.lang.ArrayUtils; |
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
|
22 | |
import java.io.Serializable; |
23 | |
import java.util.Arrays; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class ErrorMessage implements Serializable { |
32 | |
private String errorKey; |
33 | |
private String[] messageParameters; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public ErrorMessage() { |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public ErrorMessage(String errorKey, String... messageParameters) { |
48 | 0 | if (StringUtils.isBlank(errorKey)) { |
49 | 0 | throw new IllegalArgumentException("invalid (blank) errorKey"); |
50 | |
} |
51 | |
|
52 | 0 | setErrorKey(errorKey); |
53 | 0 | setMessageParameters((String[]) ArrayUtils.clone(messageParameters)); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
public void setErrorKey(String errorKey) { |
58 | 0 | if (StringUtils.isBlank(errorKey)) { |
59 | 0 | throw new IllegalArgumentException("invalid (blank) errorKey"); |
60 | |
} |
61 | |
|
62 | 0 | this.errorKey = errorKey; |
63 | 0 | } |
64 | |
|
65 | |
public String getErrorKey() { |
66 | 0 | return errorKey; |
67 | |
} |
68 | |
|
69 | |
|
70 | |
public void setMessageParameters(String[] messageParameters) { |
71 | 0 | this.messageParameters = messageParameters; |
72 | 0 | } |
73 | |
|
74 | |
public String[] getMessageParameters() { |
75 | 0 | return messageParameters; |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Override |
83 | |
public String toString() { |
84 | 0 | StringBuffer s = new StringBuffer(getErrorKey()); |
85 | |
|
86 | 0 | String[] params = getMessageParameters(); |
87 | 0 | if (params != null) { |
88 | 0 | s.append("("); |
89 | 0 | for (int i = 0; i < params.length; ++i) { |
90 | 0 | if (i > 0) { |
91 | 0 | s.append(", "); |
92 | |
} |
93 | 0 | s.append(params[i]); |
94 | |
} |
95 | 0 | s.append(")"); |
96 | |
} |
97 | 0 | return s.toString(); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
@Override |
106 | |
public boolean equals(Object obj) { |
107 | 0 | boolean equals = false; |
108 | |
|
109 | 0 | if (this == obj) { |
110 | 0 | equals = true; |
111 | |
} |
112 | 0 | else if (obj instanceof ErrorMessage) { |
113 | 0 | ErrorMessage other = (ErrorMessage) obj; |
114 | |
|
115 | 0 | if (StringUtils.equals(getErrorKey(), other.getErrorKey())) { |
116 | 0 | equals = Arrays.equals(getMessageParameters(), other.getMessageParameters()); |
117 | |
} |
118 | |
} |
119 | |
|
120 | 0 | return equals; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
@Override |
129 | |
public int hashCode() { |
130 | 0 | int hashCode = 5011966; |
131 | |
|
132 | 0 | if (getErrorKey() != null) { |
133 | 0 | hashCode = getErrorKey().hashCode(); |
134 | |
} |
135 | |
|
136 | 0 | return hashCode; |
137 | |
} |
138 | |
} |