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