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