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