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