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