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 @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 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 @SuppressWarnings("unused")
82 @XmlAnyElement
83 private final Collection<Element> _futureElements = null;
84
85
86
87
88
89 @SuppressWarnings("unused")
90 private Campus() {
91 this.code = null;
92 this.name = null;
93 this.shortName = null;
94 this.campusType = null;
95 this.active = false;
96 this.versionNumber = null;
97 this.objectId = null;
98 }
99
100
101
102
103
104
105
106 private Campus(Builder builder) {
107 this.code = builder.getCode();
108 this.name = builder.getName();
109 this.shortName = builder.getShortName();
110 if (builder.campusType != null) {
111 this.campusType = builder.getCampusType().build();
112 } else {
113 this.campusType = null;
114 }
115 this.active = builder.isActive();
116 this.versionNumber = builder.getVersionNumber();
117 this.objectId = builder.getObjectId();
118 }
119
120 @Override
121 public String getCode() {
122 return this.code;
123 }
124
125 @Override
126 public String getName() {
127 return this.name;
128 }
129
130 @Override
131 public String getShortName() {
132 return this.shortName;
133 }
134
135 @Override
136 public CampusType getCampusType() {
137 return this.campusType;
138 }
139
140 @Override
141 public boolean isActive() {
142 return this.active;
143 }
144
145 @Override
146 public Long getVersionNumber() {
147 return versionNumber;
148 }
149
150 @Override
151 public String getObjectId() {
152 return objectId;
153 }
154
155
156
157
158 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 private Builder(String code) {
172 setCode(code);
173 setActive(true);
174 }
175
176
177
178
179
180
181
182
183 public static Builder create(String code) {
184 return new Builder(code);
185 }
186
187
188
189
190
191
192
193 public static Builder create(CampusContract contract) {
194 if (contract == null) {
195 throw new IllegalArgumentException("contract is null");
196 }
197 Builder builder = new Builder(contract.getCode());
198 builder.setName(contract.getName());
199 builder.setShortName(contract.getShortName());
200 if (contract.getCampusType() != null) {
201 builder.setCampusType(CampusType.Builder.create(contract.getCampusType()));
202 }
203 builder.setActive(contract.isActive());
204 builder.setVersionNumber(contract.getVersionNumber());
205 builder.setObjectId(contract.getObjectId());
206 return builder;
207 }
208
209
210
211
212
213
214
215 public void setCode(String code) {
216 if (StringUtils.isBlank(code)) {
217 throw new IllegalArgumentException("code is blank");
218 }
219 this.code = code;
220 }
221
222 public void setName(String name) {
223 this.name = name;
224 }
225
226 public void setShortName(String shortName) {
227 this.shortName = shortName;
228 }
229
230 public void setCampusType(CampusType.Builder campusType) {
231 this.campusType = campusType;
232 }
233
234 public void setActive(boolean active) {
235 this.active = active;
236 }
237
238 public void setVersionNumber(Long versionNumber){
239 this.versionNumber = versionNumber;
240 }
241
242 public void setObjectId(String objectId) {
243 this.objectId = objectId;
244 }
245
246 @Override
247 public String getCode() {
248 return code;
249 }
250
251 @Override
252 public String getName() {
253 return name;
254 }
255
256 @Override
257 public String getShortName() {
258 return shortName;
259 }
260
261 @Override
262 public CampusType.Builder getCampusType() {
263 return campusType;
264 }
265
266 @Override
267 public boolean isActive() {
268 return active;
269 }
270
271 @Override
272 public Long getVersionNumber() {
273 return versionNumber;
274 }
275
276 @Override
277 public String getObjectId() {
278 return objectId;
279 }
280
281
282
283
284
285
286 @Override
287 public Campus build() {
288 return new Campus(this);
289 }
290
291 }
292 @Override
293 public int hashCode() {
294 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
295 }
296
297 @Override
298 public boolean equals(Object obj) {
299 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
300 }
301
302 @Override
303 public String toString() {
304 return ToStringBuilder.reflectionToString(this);
305 }
306
307
308
309
310 static class Constants {
311 final static String ROOT_ELEMENT_NAME = "campus";
312 final static String TYPE_NAME = "CampusType";
313 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS};
314 }
315
316
317
318
319
320 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 }