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.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.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 | |
@XmlRootElement(name = State.Constants.ROOT_ELEMENT_NAME) |
40 | |
@XmlAccessorType(XmlAccessType.NONE) |
41 | |
@XmlType(name = State.Constants.TYPE_NAME, propOrder = { |
42 | |
State.Elements.CODE, |
43 | |
State.Elements.NAME, |
44 | |
State.Elements.COUNTRY_CODE, |
45 | |
State.Elements.ACTIVE, |
46 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
47 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
48 | |
}) |
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 | |
@Override |
94 | |
public String getCode() { |
95 | 0 | return code; |
96 | |
} |
97 | |
|
98 | |
@Override |
99 | |
public String getName() { |
100 | 0 | return name; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public String getCountryCode() { |
105 | 0 | return countryCode; |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public boolean isActive() { |
110 | 0 | return active; |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public Long getVersionNumber() { |
115 | 0 | return versionNumber; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | 3 | public static class Builder implements StateContract, ModelBuilder, Serializable { |
122 | |
|
123 | |
private static final long serialVersionUID = 7077484401017765844L; |
124 | |
|
125 | |
private String code; |
126 | |
|
127 | |
private String name; |
128 | |
|
129 | |
private String countryCode; |
130 | |
|
131 | |
private boolean active; |
132 | |
|
133 | |
private Long versionNumber; |
134 | |
|
135 | 14 | private Builder(String code, String name, String countryCode) { |
136 | 14 | setCode(code); |
137 | 10 | setName(name); |
138 | 7 | setCountryCode(countryCode); |
139 | 4 | } |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public static Builder create(String code, String name, String countryCode) { |
149 | 12 | final Builder builder = new Builder(code, name, countryCode); |
150 | 2 | builder.setActive(true); |
151 | 2 | return builder; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public static Builder create(StateContract contract) { |
158 | 2 | final Builder builder = new Builder(contract.getCode(), contract.getName(), contract.getCountryCode()); |
159 | 2 | builder.setActive(contract.isActive()); |
160 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
161 | 2 | return builder; |
162 | |
} |
163 | |
|
164 | |
@Override |
165 | |
public String getCode() { |
166 | 4 | return code; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public void setCode(String code) { |
175 | 14 | if (StringUtils.isBlank(code)) { |
176 | 4 | throw new IllegalArgumentException("code is blank"); |
177 | |
} |
178 | |
|
179 | 10 | this.code = code; |
180 | 10 | } |
181 | |
|
182 | |
@Override |
183 | |
public String getName() { |
184 | 4 | return name; |
185 | |
} |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public void setName(String name) { |
193 | 10 | if (StringUtils.isBlank(name)) { |
194 | 3 | throw new IllegalArgumentException("name is blank"); |
195 | |
} |
196 | |
|
197 | 7 | this.name = name; |
198 | 7 | } |
199 | |
|
200 | |
@Override |
201 | |
public String getCountryCode() { |
202 | 4 | return countryCode; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public void setCountryCode(String countryCode) { |
211 | 7 | if (StringUtils.isBlank(countryCode)) { |
212 | 3 | throw new IllegalArgumentException("countryCode is blank"); |
213 | |
} |
214 | |
|
215 | 4 | this.countryCode = countryCode; |
216 | 4 | } |
217 | |
|
218 | |
@Override |
219 | |
public boolean isActive() { |
220 | 4 | return active; |
221 | |
} |
222 | |
|
223 | |
public void setActive(boolean active) { |
224 | 4 | this.active = active; |
225 | 4 | } |
226 | |
|
227 | |
@Override |
228 | |
public Long getVersionNumber() { |
229 | 4 | return versionNumber; |
230 | |
} |
231 | |
|
232 | |
public void setVersionNumber(Long versionNumber) { |
233 | 2 | this.versionNumber = versionNumber; |
234 | 2 | } |
235 | |
|
236 | |
@Override |
237 | |
public State build() { |
238 | 3 | return new State(this); |
239 | |
} |
240 | |
} |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | 0 | static class Constants { |
246 | |
final static String ROOT_ELEMENT_NAME = "state"; |
247 | |
final static String TYPE_NAME = "StateType"; |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | 0 | static class Elements { |
255 | |
final static String CODE = "code"; |
256 | |
final static String NAME = "name"; |
257 | |
final static String COUNTRY_CODE = "countryCode"; |
258 | |
final static String ACTIVE = "active"; |
259 | |
} |
260 | |
|
261 | |
} |