1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.api.campus; |
18 | |
|
19 | |
|
20 | |
import java.io.Serializable; |
21 | |
import java.util.Collection; |
22 | |
|
23 | |
import javax.xml.bind.annotation.XmlAccessType; |
24 | |
import javax.xml.bind.annotation.XmlAccessorType; |
25 | |
import javax.xml.bind.annotation.XmlAnyElement; |
26 | |
import javax.xml.bind.annotation.XmlElement; |
27 | |
import javax.xml.bind.annotation.XmlRootElement; |
28 | |
import javax.xml.bind.annotation.XmlType; |
29 | |
|
30 | |
import org.apache.commons.lang.StringUtils; |
31 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
32 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
33 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
34 | |
import org.kuali.rice.core.api.CoreConstants; |
35 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
36 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
37 | |
import org.w3c.dom.Element; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 5 | @XmlRootElement(name = Campus.Constants.ROOT_ELEMENT_NAME) |
46 | |
@XmlAccessorType(XmlAccessType.NONE) |
47 | |
@XmlType(name = Campus.Constants.TYPE_NAME, propOrder = { |
48 | |
Campus.Elements.CODE, |
49 | |
Campus.Elements.NAME, |
50 | |
Campus.Elements.SHORT_NAME, |
51 | |
Campus.Elements.CAMPUS_TYPE, |
52 | |
Campus.Elements.ACTIVE, |
53 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
54 | |
CoreConstants.CommonElements.OBJECT_ID, |
55 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
56 | |
}) |
57 | 4 | public final class Campus implements CampusContract, ModelObjectComplete { |
58 | |
private static final long serialVersionUID = 2288194493838509380L; |
59 | |
|
60 | |
@XmlElement(name = Elements.CODE, required=true) |
61 | |
private final String code; |
62 | |
|
63 | |
@XmlElement(name = Elements.NAME, required=false) |
64 | |
private final String name; |
65 | |
|
66 | |
@XmlElement(name = Elements.SHORT_NAME, required=false) |
67 | |
private final String shortName; |
68 | |
|
69 | |
@XmlElement(name = Elements.CAMPUS_TYPE, required=false) |
70 | |
private final CampusType campusType; |
71 | |
|
72 | |
@XmlElement(name = Elements.ACTIVE, required=false) |
73 | |
private final boolean active; |
74 | |
|
75 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
76 | |
private final Long versionNumber; |
77 | |
|
78 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
79 | |
private final String objectId; |
80 | |
|
81 | 7 | @SuppressWarnings("unused") |
82 | |
@XmlAnyElement |
83 | |
private final Collection<Element> _futureElements = null; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
@SuppressWarnings("unused") |
90 | 3 | private Campus() { |
91 | 3 | this.code = null; |
92 | 3 | this.name = null; |
93 | 3 | this.shortName = null; |
94 | 3 | this.campusType = null; |
95 | 3 | this.active = false; |
96 | 3 | this.versionNumber = null; |
97 | 3 | this.objectId = null; |
98 | 3 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 4 | private Campus(Builder builder) { |
107 | 4 | this.code = builder.getCode(); |
108 | 4 | this.name = builder.getName(); |
109 | 4 | this.shortName = builder.getShortName(); |
110 | 4 | if (builder.campusType != null) { |
111 | 2 | this.campusType = builder.getCampusType().build(); |
112 | |
} else { |
113 | 2 | this.campusType = null; |
114 | |
} |
115 | 4 | this.active = builder.isActive(); |
116 | 4 | this.versionNumber = builder.getVersionNumber(); |
117 | 4 | this.objectId = builder.getObjectId(); |
118 | 4 | } |
119 | |
|
120 | |
@Override |
121 | |
public String getCode() { |
122 | 1 | return this.code; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public String getName() { |
127 | 1 | return this.name; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public String getShortName() { |
132 | 1 | return this.shortName; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public CampusType getCampusType() { |
137 | 5 | return this.campusType; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public boolean isActive() { |
142 | 1 | return this.active; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public Long getVersionNumber() { |
147 | 1 | return versionNumber; |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public String getObjectId() { |
152 | 1 | return objectId; |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 9 | public static class Builder implements CampusContract, ModelBuilder, Serializable { |
159 | |
private static final long serialVersionUID = -3130728718673871762L; |
160 | |
private String code; |
161 | |
private String name; |
162 | |
private String shortName; |
163 | |
private CampusType.Builder campusType; |
164 | |
private boolean active; |
165 | |
private Long versionNumber; |
166 | |
private String objectId; |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | 6 | private Builder(String code) { |
172 | 6 | setCode(code); |
173 | 5 | setActive(true); |
174 | 5 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public static Builder create(String code) { |
184 | 3 | return new Builder(code); |
185 | |
} |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public static Builder create(CampusContract contract) { |
194 | 4 | if (contract == null) { |
195 | 1 | throw new IllegalArgumentException("contract is null"); |
196 | |
} |
197 | 3 | Builder builder = new Builder(contract.getCode()); |
198 | 3 | builder.setName(contract.getName()); |
199 | 3 | builder.setShortName(contract.getShortName()); |
200 | 3 | if (contract.getCampusType() != null) { |
201 | 2 | builder.setCampusType(CampusType.Builder.create(contract.getCampusType())); |
202 | |
} |
203 | 3 | builder.setActive(contract.isActive()); |
204 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
205 | 3 | builder.setObjectId(contract.getObjectId()); |
206 | 3 | return builder; |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public void setCode(String code) { |
216 | 6 | if (StringUtils.isBlank(code)) { |
217 | 1 | throw new IllegalArgumentException("code is blank"); |
218 | |
} |
219 | 5 | this.code = code; |
220 | 5 | } |
221 | |
|
222 | |
public void setName(String name) { |
223 | 3 | this.name = name; |
224 | 3 | } |
225 | |
|
226 | |
public void setShortName(String shortName) { |
227 | 3 | this.shortName = shortName; |
228 | 3 | } |
229 | |
|
230 | |
public void setCampusType(CampusType.Builder campusType) { |
231 | 2 | this.campusType = campusType; |
232 | 2 | } |
233 | |
|
234 | |
public void setActive(boolean active) { |
235 | 8 | this.active = active; |
236 | 8 | } |
237 | |
|
238 | |
public void setVersionNumber(Long versionNumber){ |
239 | 3 | this.versionNumber = versionNumber; |
240 | 3 | } |
241 | |
|
242 | |
public void setObjectId(String objectId) { |
243 | 3 | this.objectId = objectId; |
244 | 3 | } |
245 | |
|
246 | |
@Override |
247 | |
public String getCode() { |
248 | 5 | return code; |
249 | |
} |
250 | |
|
251 | |
@Override |
252 | |
public String getName() { |
253 | 5 | return name; |
254 | |
} |
255 | |
|
256 | |
@Override |
257 | |
public String getShortName() { |
258 | 5 | return shortName; |
259 | |
} |
260 | |
|
261 | |
@Override |
262 | |
public CampusType.Builder getCampusType() { |
263 | 3 | return campusType; |
264 | |
} |
265 | |
|
266 | |
@Override |
267 | |
public boolean isActive() { |
268 | 5 | return active; |
269 | |
} |
270 | |
|
271 | |
@Override |
272 | |
public Long getVersionNumber() { |
273 | 5 | return versionNumber; |
274 | |
} |
275 | |
|
276 | |
@Override |
277 | |
public String getObjectId() { |
278 | 5 | return objectId; |
279 | |
} |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
@Override |
287 | |
public Campus build() { |
288 | 4 | return new Campus(this); |
289 | |
} |
290 | |
|
291 | |
} |
292 | |
@Override |
293 | |
public int hashCode() { |
294 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
295 | |
} |
296 | |
|
297 | |
@Override |
298 | |
public boolean equals(Object obj) { |
299 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public String toString() { |
304 | 0 | return ToStringBuilder.reflectionToString(this); |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | 0 | static class Constants { |
311 | |
final static String ROOT_ELEMENT_NAME = "campus"; |
312 | |
final static String TYPE_NAME = "CampusType"; |
313 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
314 | |
} |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | 0 | static class Elements { |
321 | |
final static String CODE = "code"; |
322 | |
final static String NAME = "name"; |
323 | |
final static String SHORT_NAME = "shortName"; |
324 | |
final static String CAMPUS_TYPE = "campusType"; |
325 | |
final static String ACTIVE = "active"; |
326 | |
} |
327 | |
} |