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