1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.api.component; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
21 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
22 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
23 | |
import org.kuali.rice.core.api.CoreConstants; |
24 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
25 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
26 | |
import org.w3c.dom.Element; |
27 | |
|
28 | |
import javax.xml.bind.annotation.XmlAccessType; |
29 | |
import javax.xml.bind.annotation.XmlAccessorType; |
30 | |
import javax.xml.bind.annotation.XmlAnyElement; |
31 | |
import javax.xml.bind.annotation.XmlElement; |
32 | |
import javax.xml.bind.annotation.XmlRootElement; |
33 | |
import javax.xml.bind.annotation.XmlType; |
34 | |
import java.io.Serializable; |
35 | |
import java.util.Collection; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@XmlRootElement(name = Component.Constants.ROOT_ELEMENT_NAME) |
45 | |
@XmlAccessorType(XmlAccessType.NONE) |
46 | |
@XmlType(name = Component.Constants.TYPE_NAME, propOrder = { |
47 | |
Component.Elements.NAMESPACE_CODE, |
48 | |
Component.Elements.CODE, |
49 | |
Component.Elements.NAME, |
50 | |
Component.Elements.VIRTUAL, |
51 | |
Component.Elements.ACTIVE, |
52 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
53 | |
CoreConstants.CommonElements.OBJECT_ID, |
54 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
55 | |
}) |
56 | 1 | public final class Component implements ComponentContract, ModelObjectComplete { |
57 | |
|
58 | |
private static final long serialVersionUID = -5114772381708593543L; |
59 | |
|
60 | |
@XmlElement(name = Elements.NAMESPACE_CODE, required=true) |
61 | |
private final String namespaceCode; |
62 | |
|
63 | |
@XmlElement(name = Elements.CODE, required=true) |
64 | |
private final String code; |
65 | |
|
66 | |
@XmlElement(name = Elements.NAME, required=true) |
67 | |
private final String name; |
68 | |
|
69 | |
@XmlElement(name = Elements.VIRTUAL, required=true) |
70 | |
private final boolean virtual; |
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 | 3 | @SuppressWarnings("unused") |
82 | |
@XmlAnyElement |
83 | |
private final Collection<Element> _futureElements = null; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | 2 | private Component() { |
89 | 2 | this.namespaceCode = null; |
90 | 2 | this.code = null; |
91 | 2 | this.name = null; |
92 | 2 | this.virtual = false; |
93 | 2 | this.active = true; |
94 | 2 | this.versionNumber = null; |
95 | 2 | this.objectId = null; |
96 | 2 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | 1 | private Component(Builder builder) { |
105 | 1 | namespaceCode = builder.getNamespaceCode(); |
106 | 1 | code = builder.getCode(); |
107 | 1 | name = builder.getName(); |
108 | 1 | virtual = builder.isVirtual(); |
109 | 1 | active = builder.isActive(); |
110 | 1 | versionNumber = builder.getVersionNumber(); |
111 | 1 | this.objectId = builder.getObjectId(); |
112 | 1 | } |
113 | |
|
114 | |
|
115 | |
@Override |
116 | |
public String getNamespaceCode() { |
117 | 0 | return namespaceCode; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public String getCode() { |
122 | 0 | return code; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public String getName() { |
127 | 0 | return name; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public boolean isVirtual() { |
132 | 0 | return virtual; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public boolean isActive() { |
137 | 0 | return active; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public Long getVersionNumber() { |
142 | 0 | return versionNumber; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public String getObjectId() { |
147 | 0 | return objectId; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | 1 | public static final class Builder implements ComponentContract, ModelBuilder, Serializable { |
154 | |
|
155 | |
private static final long serialVersionUID = 5548130104299578283L; |
156 | |
|
157 | |
private String namespaceCode; |
158 | |
private String code; |
159 | |
private String name; |
160 | |
private boolean virtual; |
161 | |
private boolean active; |
162 | |
private Long versionNumber; |
163 | |
private String objectId; |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | 12 | private Builder(String namespaceCode, String code, String name, boolean virtual) { |
169 | 12 | setNamespaceCode(namespaceCode); |
170 | 8 | setCode(code); |
171 | 5 | setName(name); |
172 | 2 | setVirtual(virtual); |
173 | 2 | setActive(true); |
174 | 2 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public static Builder create(String namespaceCode, String code, String name, boolean virtual) { |
187 | 11 | return new Builder(namespaceCode, code, name, virtual); |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public static Builder create(ComponentContract contract) { |
197 | 1 | Builder builder = new Builder(contract.getNamespaceCode(), contract.getCode(), contract.getName(), contract.isVirtual()); |
198 | 1 | builder.setActive(contract.isActive()); |
199 | 1 | builder.setVersionNumber(contract.getVersionNumber()); |
200 | 1 | builder.setObjectId(contract.getObjectId()); |
201 | 1 | return builder; |
202 | |
} |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public void setNamespaceCode(String namespaceCode) { |
211 | 12 | if (StringUtils.isBlank(namespaceCode)) { |
212 | 4 | throw new IllegalArgumentException("namespaceCode is null"); |
213 | |
} |
214 | 8 | this.namespaceCode = namespaceCode; |
215 | 8 | } |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
public void setCode(String code) { |
224 | 8 | if (StringUtils.isBlank(code)) { |
225 | 3 | throw new IllegalArgumentException("code is blank"); |
226 | |
} |
227 | 5 | this.code = code; |
228 | 5 | } |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public void setName(String name) { |
237 | 5 | if (StringUtils.isBlank(name)) { |
238 | 3 | throw new IllegalArgumentException("name is blank"); |
239 | |
} |
240 | 2 | this.name = name; |
241 | 2 | } |
242 | |
|
243 | |
@Override |
244 | |
public boolean isVirtual() { |
245 | 1 | return virtual; |
246 | |
} |
247 | |
|
248 | |
public void setVirtual(boolean virtual) { |
249 | 2 | this.virtual = virtual; |
250 | 2 | } |
251 | |
|
252 | |
@Override |
253 | |
public boolean isActive() { |
254 | 1 | return active; |
255 | |
} |
256 | |
|
257 | |
public void setActive(boolean active) { |
258 | 3 | this.active = active; |
259 | 3 | } |
260 | |
|
261 | |
@Override |
262 | |
public String getNamespaceCode() { |
263 | 1 | return namespaceCode; |
264 | |
} |
265 | |
|
266 | |
@Override |
267 | |
public String getCode() { |
268 | 1 | return code; |
269 | |
} |
270 | |
|
271 | |
@Override |
272 | |
public String getName() { |
273 | 1 | return name; |
274 | |
} |
275 | |
|
276 | |
@Override |
277 | |
public Long getVersionNumber() { |
278 | 1 | return versionNumber; |
279 | |
} |
280 | |
|
281 | |
public void setVersionNumber(Long versionNumber) { |
282 | 1 | this.versionNumber = versionNumber; |
283 | 1 | } |
284 | |
|
285 | |
@Override |
286 | |
public String getObjectId() { |
287 | 1 | return objectId; |
288 | |
} |
289 | |
|
290 | |
public void setObjectId(String objectId) { |
291 | 1 | this.objectId = objectId; |
292 | 1 | } |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
@Override |
300 | |
public Component build() { |
301 | 1 | return new Component(this); |
302 | |
} |
303 | |
|
304 | |
} |
305 | |
|
306 | |
@Override |
307 | |
public int hashCode() { |
308 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
public boolean equals(Object obj) { |
313 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
public String toString() { |
318 | 0 | return ToStringBuilder.reflectionToString(this); |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | 0 | static class Constants { |
325 | |
final static String ROOT_ELEMENT_NAME = "component"; |
326 | |
final static String TYPE_NAME = "ComponentType"; |
327 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
328 | |
} |
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | 0 | static class Elements { |
335 | |
final static String CODE = "code"; |
336 | |
final static String NAME = "name"; |
337 | |
final static String VIRTUAL = "virtual"; |
338 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
339 | |
final static String ACTIVE = "active"; |
340 | |
} |
341 | |
|
342 | |
} |