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