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