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