1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.api.country; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
import java.util.Collection; |
21 | |
|
22 | |
import javax.xml.bind.annotation.XmlAccessType; |
23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
24 | |
import javax.xml.bind.annotation.XmlAnyElement; |
25 | |
import javax.xml.bind.annotation.XmlElement; |
26 | |
import javax.xml.bind.annotation.XmlRootElement; |
27 | |
import javax.xml.bind.annotation.XmlType; |
28 | |
|
29 | |
import org.apache.commons.lang.StringUtils; |
30 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
31 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
32 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
33 | |
import org.kuali.rice.core.api.CoreConstants; |
34 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
35 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
36 | |
import org.w3c.dom.Element; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@XmlRootElement(name = Country.Constants.ROOT_ELEMENT_NAME) |
44 | |
@XmlAccessorType(XmlAccessType.NONE) |
45 | |
@XmlType(name = Country.Constants.TYPE_NAME, propOrder = { |
46 | |
Country.Elements.CODE, |
47 | |
Country.Elements.ALTERNATE_CODE, |
48 | |
Country.Elements.NAME, |
49 | |
Country.Elements.RESTRICTED, |
50 | |
Country.Elements.ACTIVE, |
51 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
52 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
53 | |
}) |
54 | 5 | public final class Country implements CountryContract, ModelObjectComplete { |
55 | |
private static final long serialVersionUID = -8975392777320033940L; |
56 | |
|
57 | |
@XmlElement(name = Elements.CODE, required = true) |
58 | |
private final String code; |
59 | |
|
60 | |
@XmlElement(name = Elements.ALTERNATE_CODE, required = false) |
61 | |
private final String alternateCode; |
62 | |
|
63 | |
@XmlElement(name = Elements.NAME, required = false) |
64 | |
private final String name; |
65 | |
|
66 | |
@XmlElement(name = Elements.RESTRICTED, required = true) |
67 | |
private final boolean restricted; |
68 | |
|
69 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
70 | |
private final boolean active; |
71 | |
|
72 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
73 | |
private final Long versionNumber; |
74 | |
|
75 | 8 | @SuppressWarnings("unused") |
76 | |
@XmlAnyElement |
77 | |
private final Collection<Element> _futureElements = null; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@SuppressWarnings("unused") |
83 | 3 | private Country() { |
84 | 3 | this.code = null; |
85 | 3 | this.alternateCode = null; |
86 | 3 | this.name = null; |
87 | 3 | this.restricted = false; |
88 | 3 | this.active = false; |
89 | 3 | this.versionNumber = null; |
90 | 3 | } |
91 | |
|
92 | 5 | private Country(Builder builder) { |
93 | 5 | this.code = builder.getCode(); |
94 | 5 | this.alternateCode = builder.getAlternateCode(); |
95 | 5 | this.name = builder.getName(); |
96 | 5 | this.restricted = builder.isRestricted(); |
97 | 5 | this.active = builder.isActive(); |
98 | 5 | this.versionNumber = builder.getVersionNumber(); |
99 | 5 | } |
100 | |
|
101 | |
@Override |
102 | |
public String getCode() { |
103 | 1 | return this.code; |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public String getAlternateCode() { |
108 | 1 | return this.alternateCode; |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public String getName() { |
113 | 1 | return this.name; |
114 | |
} |
115 | |
|
116 | |
@Override |
117 | |
public boolean isActive() { |
118 | 0 | return this.active; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public boolean isRestricted() { |
123 | 0 | return this.restricted; |
124 | |
} |
125 | |
|
126 | |
@Override |
127 | |
public Long getVersionNumber() { |
128 | 0 | return this.versionNumber; |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
public int hashCode() { |
133 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public boolean equals(Object obj) { |
138 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
139 | |
} |
140 | |
|
141 | |
@Override |
142 | |
public String toString() { |
143 | 0 | return ToStringBuilder.reflectionToString(this); |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | 5 | public static class Builder implements CountryContract, ModelBuilder, Serializable { |
150 | |
private static final long serialVersionUID = -4786917485397379322L; |
151 | |
|
152 | |
private String code; |
153 | |
private String alternateCode; |
154 | |
private String name; |
155 | |
private boolean restricted; |
156 | |
private boolean active; |
157 | |
private Long versionNumber; |
158 | |
|
159 | |
private Builder(String code, String alternateCode, String name, |
160 | 9 | boolean restricted, boolean active) { |
161 | 9 | this.setCode(code); |
162 | 7 | this.setAlternateCode(alternateCode); |
163 | 7 | this.setName(name); |
164 | 7 | this.setRestricted(restricted); |
165 | 7 | this.setActive(active); |
166 | 7 | } |
167 | |
|
168 | |
public static Builder create(String code, String name) { |
169 | 1 | return new Builder(code, null, name, false, true); |
170 | |
} |
171 | |
|
172 | |
public static Builder create(String code, String alternatePostalCode, String name, |
173 | |
boolean restricted, boolean active) { |
174 | 5 | return new Builder(code, alternatePostalCode, name, restricted, active); |
175 | |
} |
176 | |
|
177 | |
public static Builder create(CountryContract cc) { |
178 | 3 | Builder builder = new Builder(cc.getCode(), cc.getAlternateCode(), |
179 | |
cc.getName(), cc.isRestricted(), cc.isActive()); |
180 | 3 | builder.setVersionNumber(cc.getVersionNumber()); |
181 | 3 | return builder; |
182 | |
} |
183 | |
|
184 | |
@Override |
185 | |
public Country build() { |
186 | 5 | return new Country(this); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public void setCode(String code) { |
195 | 9 | if (StringUtils.isBlank(code)) { |
196 | 2 | throw new IllegalArgumentException("code cannot be blank or null"); |
197 | |
} |
198 | 7 | this.code = code; |
199 | 7 | } |
200 | |
|
201 | |
@Override |
202 | |
public String getCode() { |
203 | 7 | return this.code; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public void setAlternateCode(String alternatePostalCode) { |
212 | 7 | this.alternateCode = alternatePostalCode; |
213 | 7 | } |
214 | |
|
215 | |
@Override |
216 | |
public String getAlternateCode() { |
217 | 7 | return this.alternateCode; |
218 | |
} |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public void setName(String name) { |
226 | 7 | this.name = name; |
227 | 7 | } |
228 | |
|
229 | |
@Override |
230 | |
public String getName() { |
231 | 7 | return this.name; |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
public void setActive(boolean active) { |
240 | 7 | this.active = active; |
241 | 7 | } |
242 | |
|
243 | |
@Override |
244 | |
public boolean isActive() { |
245 | 7 | return this.active; |
246 | |
} |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public void setVersionNumber(Long versionNumber) { |
254 | 4 | this.versionNumber = versionNumber; |
255 | 4 | } |
256 | |
|
257 | |
@Override |
258 | |
public Long getVersionNumber() { |
259 | 7 | return this.versionNumber; |
260 | |
} |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public void setRestricted(boolean restricted) { |
268 | 7 | this.restricted = restricted; |
269 | 7 | } |
270 | |
|
271 | |
@Override |
272 | |
public boolean isRestricted() { |
273 | 7 | return this.restricted; |
274 | |
} |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | 0 | static class Elements { |
282 | |
final static String CODE = "code"; |
283 | |
final static String ALTERNATE_CODE = "alternateCode"; |
284 | |
final static String NAME = "name"; |
285 | |
final static String RESTRICTED = "restricted"; |
286 | |
final static String ACTIVE = "active"; |
287 | |
} |
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | 0 | static class Constants { |
293 | |
final static String ROOT_ELEMENT_NAME = "country"; |
294 | |
final static String TYPE_NAME = "CountryType"; |
295 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
296 | |
} |
297 | |
} |