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