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 | 3 | 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 | 5 | @SuppressWarnings("unused") |
81 | |
@XmlAnyElement |
82 | |
private final Collection<Element> _futureElements = null; |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
@SuppressWarnings("unused") |
88 | 2 | private PostalCode() { |
89 | 2 | this.code = null; |
90 | 2 | this.cityName = null; |
91 | 2 | this.countryCode = null; |
92 | 2 | this.stateCode = null; |
93 | 2 | this.countyCode = null; |
94 | 2 | this.active = false; |
95 | 2 | this.versionNumber = null; |
96 | 2 | } |
97 | |
|
98 | 3 | private PostalCode(Builder builder) { |
99 | 3 | code = builder.getCode(); |
100 | 3 | cityName = builder.getCityName(); |
101 | 3 | countryCode = builder.getCountryCode(); |
102 | 3 | stateCode = builder.getStateCode(); |
103 | 3 | countyCode = builder.getCountyCode(); |
104 | 3 | active = builder.isActive(); |
105 | 3 | versionNumber = builder.getVersionNumber(); |
106 | 3 | } |
107 | |
|
108 | |
|
109 | |
@Override |
110 | |
public String getCode() { |
111 | 0 | return code; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
@Override |
116 | |
public String getCityName() { |
117 | 0 | return cityName; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
@Override |
122 | |
public String getCountryCode() { |
123 | 0 | return countryCode; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
@Override |
128 | |
public String getStateCode() { |
129 | 0 | return stateCode; |
130 | |
} |
131 | |
|
132 | |
|
133 | |
@Override |
134 | |
public String getCountyCode() { |
135 | 0 | return countyCode; |
136 | |
} |
137 | |
|
138 | |
|
139 | |
@Override |
140 | |
public boolean isActive() { |
141 | 0 | return active; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
@Override |
146 | |
public Long getVersionNumber() { |
147 | 0 | return versionNumber; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | 3 | 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 | 20 | private Builder(String code, String countryCode) { |
166 | 20 | setCode(code); |
167 | 16 | setCountryCode(countryCode); |
168 | 13 | } |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public static Builder create(String code, String countryCode) { |
174 | 18 | final Builder builder = new Builder(code, countryCode); |
175 | 11 | builder.setActive(true); |
176 | 11 | return builder; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public static Builder create(PostalCodeContract contract) { |
183 | 2 | final Builder builder = new Builder(contract.getCode(), contract.getCountryCode()); |
184 | 2 | builder.setActive(contract.isActive()); |
185 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
186 | 2 | if (StringUtils.isNotBlank(contract.getCountyCode())) { |
187 | 1 | builder.setCountyCode(contract.getCountyCode()); |
188 | |
} |
189 | |
|
190 | 2 | if (StringUtils.isNotBlank(contract.getCityName())) { |
191 | 1 | builder.setCityName(contract.getCityName()); |
192 | |
} |
193 | |
|
194 | 2 | if (StringUtils.isNotBlank(contract.getStateCode())) { |
195 | 1 | builder.setStateCode(contract.getStateCode()); |
196 | |
} |
197 | 2 | return builder; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public String getCode() { |
202 | 4 | return code; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public void setCode(String code) { |
212 | 20 | if (StringUtils.isBlank(code)) { |
213 | 4 | throw new IllegalArgumentException("code is blank"); |
214 | |
} |
215 | |
|
216 | 16 | this.code = code; |
217 | 16 | } |
218 | |
|
219 | |
@Override |
220 | |
public String getCityName() { |
221 | 4 | return cityName; |
222 | |
} |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
public void setCityName(String cityName) { |
231 | 4 | if (StringUtils.isBlank(cityName)) { |
232 | 3 | throw new IllegalArgumentException("cityName is blank"); |
233 | |
} |
234 | |
|
235 | 1 | this.cityName = cityName; |
236 | 1 | } |
237 | |
|
238 | |
@Override |
239 | |
public String getCountryCode() { |
240 | 4 | return countryCode; |
241 | |
} |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
public void setCountryCode(String countryCode) { |
251 | 16 | if (StringUtils.isBlank(countryCode)) { |
252 | 3 | throw new IllegalArgumentException("countryCode is blank"); |
253 | |
} |
254 | |
|
255 | 13 | this.countryCode = countryCode; |
256 | 13 | } |
257 | |
|
258 | |
@Override |
259 | |
public String getStateCode() { |
260 | 4 | return stateCode; |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
public void setStateCode(String stateCode) { |
271 | 4 | if (StringUtils.isBlank(stateCode)) { |
272 | 3 | throw new IllegalArgumentException("stateCode is blank"); |
273 | |
} |
274 | |
|
275 | 1 | this.stateCode = stateCode; |
276 | 1 | } |
277 | |
|
278 | |
@Override |
279 | |
public String getCountyCode() { |
280 | 4 | return countyCode; |
281 | |
} |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
public void setCountyCode(String countyCode) { |
291 | 4 | if (StringUtils.isBlank(countyCode)) { |
292 | 3 | throw new IllegalArgumentException("countyCode is blank"); |
293 | |
} |
294 | |
|
295 | 1 | this.countyCode = countyCode; |
296 | 1 | } |
297 | |
|
298 | |
@Override |
299 | |
public boolean isActive() { |
300 | 4 | return active; |
301 | |
} |
302 | |
|
303 | |
public void setActive(boolean active) { |
304 | 13 | this.active = active; |
305 | 13 | } |
306 | |
|
307 | |
@Override |
308 | |
public Long getVersionNumber() { |
309 | 4 | return versionNumber; |
310 | |
} |
311 | |
|
312 | |
public void setVersionNumber(Long versionNumber) { |
313 | 2 | this.versionNumber = versionNumber; |
314 | 2 | } |
315 | |
|
316 | |
@Override |
317 | |
public PostalCode build() { |
318 | 3 | return new PostalCode(this); |
319 | |
} |
320 | |
} |
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | 0 | 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 | 0 | 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 | 0 | public static class Cache { |
344 | |
public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + PostalCode.Constants.TYPE_NAME; |
345 | |
} |
346 | |
} |