1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.api.postalcode; |
18 | |
|
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.core.api.CoreConstants; |
22 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
23 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
24 | |
import org.w3c.dom.Element; |
25 | |
|
26 | |
import javax.xml.bind.annotation.XmlAccessType; |
27 | |
import javax.xml.bind.annotation.XmlAccessorType; |
28 | |
import javax.xml.bind.annotation.XmlAnyElement; |
29 | |
import javax.xml.bind.annotation.XmlElement; |
30 | |
import javax.xml.bind.annotation.XmlRootElement; |
31 | |
import javax.xml.bind.annotation.XmlType; |
32 | |
import java.io.Serializable; |
33 | |
import java.util.Collection; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@XmlRootElement(name = PostalCode.Constants.ROOT_ELEMENT_NAME) |
43 | |
@XmlAccessorType(XmlAccessType.NONE) |
44 | |
@XmlType(name = PostalCode.Constants.TYPE_NAME, propOrder = { |
45 | |
PostalCode.Elements.CODE, |
46 | |
PostalCode.Elements.CITY_NAME, |
47 | |
PostalCode.Elements.COUNTRY_CODE, |
48 | |
PostalCode.Elements.STATE_CODE, |
49 | |
PostalCode.Elements.ACTIVE, |
50 | |
PostalCode.Elements.COUNTY_CODE, |
51 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
52 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
53 | |
}) |
54 | 3 | public final class PostalCode extends AbstractDataTransferObject implements PostalCodeContract { |
55 | |
|
56 | |
private static final long serialVersionUID = 6097498602725305353L; |
57 | |
|
58 | |
@XmlElement(name = Elements.CODE, required = true) |
59 | |
private final String code; |
60 | |
|
61 | |
@XmlElement(name = Elements.CITY_NAME, required = false) |
62 | |
private final String cityName; |
63 | |
|
64 | |
@XmlElement(name = Elements.COUNTRY_CODE, required = true) |
65 | |
private final String countryCode; |
66 | |
|
67 | |
@XmlElement(name = Elements.STATE_CODE, required = false) |
68 | |
private final String stateCode; |
69 | |
|
70 | |
@XmlElement(name = Elements.COUNTY_CODE, required = false) |
71 | |
private final String countyCode; |
72 | |
|
73 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
74 | |
private final boolean active; |
75 | |
|
76 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
77 | |
private final Long versionNumber; |
78 | |
|
79 | 5 | @SuppressWarnings("unused") |
80 | |
@XmlAnyElement |
81 | |
private final Collection<Element> _futureElements = null; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
@SuppressWarnings("unused") |
87 | 2 | private PostalCode() { |
88 | 2 | this.code = null; |
89 | 2 | this.cityName = null; |
90 | 2 | this.countryCode = null; |
91 | 2 | this.stateCode = null; |
92 | 2 | this.countyCode = null; |
93 | 2 | this.active = false; |
94 | 2 | this.versionNumber = null; |
95 | 2 | } |
96 | |
|
97 | 3 | private PostalCode(Builder builder) { |
98 | 3 | code = builder.getCode(); |
99 | 3 | cityName = builder.getCityName(); |
100 | 3 | countryCode = builder.getCountryCode(); |
101 | 3 | stateCode = builder.getStateCode(); |
102 | 3 | countyCode = builder.getCountyCode(); |
103 | 3 | active = builder.isActive(); |
104 | 3 | versionNumber = builder.getVersionNumber(); |
105 | 3 | } |
106 | |
|
107 | |
@Override |
108 | |
public String getCode() { |
109 | 0 | return code; |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public String getCityName() { |
114 | 0 | return cityName; |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public String getCountryCode() { |
119 | 0 | return countryCode; |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public String getStateCode() { |
124 | 0 | return stateCode; |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public String getCountyCode() { |
129 | 0 | return countyCode; |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public boolean isActive() { |
134 | 0 | return active; |
135 | |
} |
136 | |
|
137 | |
@Override |
138 | |
public Long getVersionNumber() { |
139 | 0 | return versionNumber; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | 3 | public static class Builder implements PostalCodeContract, ModelBuilder, Serializable { |
146 | |
|
147 | |
private static final long serialVersionUID = 7077484401017765844L; |
148 | |
|
149 | |
private String code; |
150 | |
private String cityName; |
151 | |
private String countryCode; |
152 | |
private String stateCode; |
153 | |
private String countyCode; |
154 | |
private boolean active; |
155 | |
private Long versionNumber; |
156 | |
|
157 | 20 | private Builder(String code, String countryCode) { |
158 | 20 | setCode(code); |
159 | 16 | setCountryCode(countryCode); |
160 | 13 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public static Builder create(String code, String countryCode) { |
166 | 18 | final Builder builder = new Builder(code, countryCode); |
167 | 11 | builder.setActive(true); |
168 | 11 | return builder; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public static Builder create(PostalCodeContract contract) { |
175 | 2 | final Builder builder = new Builder(contract.getCode(), contract.getCountryCode()); |
176 | 2 | builder.setActive(contract.isActive()); |
177 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
178 | 2 | if (StringUtils.isNotBlank(contract.getCountyCode())) { |
179 | 1 | builder.setCountyCode(contract.getCountyCode()); |
180 | |
} |
181 | |
|
182 | 2 | if (StringUtils.isNotBlank(contract.getCityName())) { |
183 | 1 | builder.setCityName(contract.getCityName()); |
184 | |
} |
185 | |
|
186 | 2 | if (StringUtils.isNotBlank(contract.getStateCode())) { |
187 | 1 | builder.setStateCode(contract.getStateCode()); |
188 | |
} |
189 | 2 | return builder; |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
public String getCode() { |
194 | 4 | return code; |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public void setCode(String code) { |
204 | 20 | if (StringUtils.isBlank(code)) { |
205 | 4 | throw new IllegalArgumentException("code is blank"); |
206 | |
} |
207 | |
|
208 | 16 | this.code = code; |
209 | 16 | } |
210 | |
|
211 | |
@Override |
212 | |
public String getCityName() { |
213 | 4 | return cityName; |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public void setCityName(String cityName) { |
223 | 4 | if (StringUtils.isBlank(cityName)) { |
224 | 3 | throw new IllegalArgumentException("cityName is blank"); |
225 | |
} |
226 | |
|
227 | 1 | this.cityName = cityName; |
228 | 1 | } |
229 | |
|
230 | |
@Override |
231 | |
public String getCountryCode() { |
232 | 4 | return countryCode; |
233 | |
} |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
public void setCountryCode(String countryCode) { |
243 | 16 | if (StringUtils.isBlank(countryCode)) { |
244 | 3 | throw new IllegalArgumentException("countryCode is blank"); |
245 | |
} |
246 | |
|
247 | 13 | this.countryCode = countryCode; |
248 | 13 | } |
249 | |
|
250 | |
@Override |
251 | |
public String getStateCode() { |
252 | 4 | return stateCode; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
public void setStateCode(String stateCode) { |
263 | 4 | if (StringUtils.isBlank(stateCode)) { |
264 | 3 | throw new IllegalArgumentException("stateCode is blank"); |
265 | |
} |
266 | |
|
267 | 1 | this.stateCode = stateCode; |
268 | 1 | } |
269 | |
|
270 | |
@Override |
271 | |
public String getCountyCode() { |
272 | 4 | return countyCode; |
273 | |
} |
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
public void setCountyCode(String countyCode) { |
283 | 4 | if (StringUtils.isBlank(countyCode)) { |
284 | 3 | throw new IllegalArgumentException("countyCode is blank"); |
285 | |
} |
286 | |
|
287 | 1 | this.countyCode = countyCode; |
288 | 1 | } |
289 | |
|
290 | |
@Override |
291 | |
public boolean isActive() { |
292 | 4 | return active; |
293 | |
} |
294 | |
|
295 | |
public void setActive(boolean active) { |
296 | 13 | this.active = active; |
297 | 13 | } |
298 | |
|
299 | |
@Override |
300 | |
public Long getVersionNumber() { |
301 | 4 | return versionNumber; |
302 | |
} |
303 | |
|
304 | |
public void setVersionNumber(Long versionNumber) { |
305 | 2 | this.versionNumber = versionNumber; |
306 | 2 | } |
307 | |
|
308 | |
@Override |
309 | |
public PostalCode build() { |
310 | 3 | return new PostalCode(this); |
311 | |
} |
312 | |
} |
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | 0 | static class Constants { |
318 | |
final static String ROOT_ELEMENT_NAME = "postalCode"; |
319 | |
final static String TYPE_NAME = "PostalCodeType"; |
320 | |
} |
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | 0 | static class Elements { |
327 | |
final static String CODE = "code"; |
328 | |
final static String CITY_NAME = "cityName"; |
329 | |
final static String COUNTRY_CODE = "countryCode"; |
330 | |
final static String STATE_CODE = "stateCode"; |
331 | |
final static String COUNTY_CODE = "countyCode"; |
332 | |
final static String ACTIVE = "active"; |
333 | |
} |
334 | |
} |