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