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