1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.location.api.country;
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 @XmlRootElement(name = Country.Constants.ROOT_ELEMENT_NAME)
41 @XmlAccessorType(XmlAccessType.NONE)
42 @XmlType(name = Country.Constants.TYPE_NAME, propOrder = {
43 Country.Elements.CODE,
44 Country.Elements.ALTERNATE_CODE,
45 Country.Elements.NAME,
46 Country.Elements.RESTRICTED,
47 Country.Elements.ACTIVE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.FUTURE_ELEMENTS
50 })
51 public final class Country extends AbstractDataTransferObject implements CountryContract {
52 private static final long serialVersionUID = -8975392777320033940L;
53
54 @XmlElement(name = Elements.CODE, required = true)
55 private final String code;
56
57 @XmlElement(name = Elements.ALTERNATE_CODE, required = false)
58 private final String alternateCode;
59
60 @XmlElement(name = Elements.NAME, required = false)
61 private final String name;
62
63 @XmlElement(name = Elements.RESTRICTED, required = true)
64 private final boolean restricted;
65
66 @XmlElement(name = Elements.ACTIVE, required = true)
67 private final boolean active;
68
69 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
70 private final Long versionNumber;
71
72 @SuppressWarnings("unused")
73 @XmlAnyElement
74 private final Collection<Element> _futureElements = null;
75
76
77
78
79 @SuppressWarnings("unused")
80 private Country() {
81 this.code = null;
82 this.alternateCode = null;
83 this.name = null;
84 this.restricted = false;
85 this.active = false;
86 this.versionNumber = null;
87 }
88
89 private Country(Builder builder) {
90 this.code = builder.getCode();
91 this.alternateCode = builder.getAlternateCode();
92 this.name = builder.getName();
93 this.restricted = builder.isRestricted();
94 this.active = builder.isActive();
95 this.versionNumber = builder.getVersionNumber();
96 }
97
98
99 @Override
100 public String getCode() {
101 return this.code;
102 }
103
104
105 @Override
106 public String getAlternateCode() {
107 return this.alternateCode;
108 }
109
110
111 @Override
112 public String getName() {
113 return this.name;
114 }
115
116
117 @Override
118 public boolean isActive() {
119 return this.active;
120 }
121
122
123 @Override
124 public boolean isRestricted() {
125 return this.restricted;
126 }
127
128
129 @Override
130 public Long getVersionNumber() {
131 return this.versionNumber;
132 }
133
134
135
136
137 public static class Builder implements CountryContract, ModelBuilder, Serializable {
138 private static final long serialVersionUID = -4786917485397379322L;
139
140 private String code;
141 private String alternateCode;
142 private String name;
143 private boolean restricted;
144 private boolean active;
145 private Long versionNumber;
146
147 private Builder(String code, String alternateCode, String name,
148 boolean restricted, boolean active) {
149 this.setCode(code);
150 this.setAlternateCode(alternateCode);
151 this.setName(name);
152 this.setRestricted(restricted);
153 this.setActive(active);
154 }
155
156 public static Builder create(String code, String name) {
157 return new Builder(code, null, name, false, true);
158 }
159
160 public static Builder create(String code, String alternatePostalCode, String name,
161 boolean restricted, boolean active) {
162 return new Builder(code, alternatePostalCode, name, restricted, active);
163 }
164
165 public static Builder create(CountryContract cc) {
166 Builder builder = new Builder(cc.getCode(), cc.getAlternateCode(),
167 cc.getName(), cc.isRestricted(), cc.isActive());
168 builder.setVersionNumber(cc.getVersionNumber());
169 return builder;
170 }
171
172 @Override
173 public Country build() {
174 return new Country(this);
175 }
176
177
178
179
180
181
182 public void setCode(String code) {
183 if (StringUtils.isBlank(code)) {
184 throw new IllegalArgumentException("code cannot be blank or null");
185 }
186 this.code = code;
187 }
188
189 @Override
190 public String getCode() {
191 return this.code;
192 }
193
194
195
196
197
198
199 public void setAlternateCode(String alternatePostalCode) {
200 this.alternateCode = alternatePostalCode;
201 }
202
203 @Override
204 public String getAlternateCode() {
205 return this.alternateCode;
206 }
207
208
209
210
211
212
213 public void setName(String name) {
214 this.name = name;
215 }
216
217 @Override
218 public String getName() {
219 return this.name;
220 }
221
222
223
224
225
226
227 public void setActive(boolean active) {
228 this.active = active;
229 }
230
231 @Override
232 public boolean isActive() {
233 return this.active;
234 }
235
236
237
238
239
240
241 public void setVersionNumber(Long versionNumber) {
242 this.versionNumber = versionNumber;
243 }
244
245 @Override
246 public Long getVersionNumber() {
247 return this.versionNumber;
248 }
249
250
251
252
253
254
255 public void setRestricted(boolean restricted) {
256 this.restricted = restricted;
257 }
258
259 @Override
260 public boolean isRestricted() {
261 return this.restricted;
262 }
263 }
264
265
266
267
268
269 static class Elements {
270 final static String CODE = "code";
271 final static String ALTERNATE_CODE = "alternateCode";
272 final static String NAME = "name";
273 final static String RESTRICTED = "restricted";
274 final static String ACTIVE = "active";
275 }
276
277
278
279
280 static class Constants {
281 final static String ROOT_ELEMENT_NAME = "country";
282 final static String TYPE_NAME = "CountryType";
283 }
284
285 public static class Cache {
286 public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + Country.Constants.TYPE_NAME;
287 }
288 }