1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.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 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 @SuppressWarnings("unused")
78 @XmlAnyElement
79 private final Collection<Element> _futureElements = null;
80
81
82
83
84 private Component() {
85 this.namespaceCode = null;
86 this.code = null;
87 this.name = null;
88 this.componentSetId = null;
89 this.active = true;
90 this.versionNumber = null;
91 this.objectId = null;
92 }
93
94
95
96
97
98
99
100 private Component(Builder builder) {
101 namespaceCode = builder.getNamespaceCode();
102 code = builder.getCode();
103 name = builder.getName();
104 componentSetId = builder.getComponentSetId();
105 active = builder.isActive();
106 versionNumber = builder.getVersionNumber();
107 this.objectId = builder.getObjectId();
108 }
109
110
111 @Override
112 public String getNamespaceCode() {
113 return namespaceCode;
114 }
115
116 @Override
117 public String getCode() {
118 return code;
119 }
120
121 @Override
122 public String getName() {
123 return name;
124 }
125
126 @Override
127 public String getComponentSetId() {
128 return componentSetId;
129 }
130
131 @Override
132 public boolean isActive() {
133 return active;
134 }
135
136 @Override
137 public Long getVersionNumber() {
138 return versionNumber;
139 }
140
141 @Override
142 public String getObjectId() {
143 return objectId;
144 }
145
146
147
148
149 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 private Builder(String namespaceCode, String code, String name) {
165 setNamespaceCode(namespaceCode);
166 setCode(code);
167 setName(name);
168 setActive(true);
169 }
170
171
172
173
174
175
176
177
178
179
180 public static Builder create(String namespaceCode, String code, String name) {
181 return new Builder(namespaceCode, code, name);
182 }
183
184
185
186
187
188
189
190 public static Builder create(ComponentContract contract) {
191 Builder builder = new Builder(contract.getNamespaceCode(), contract.getCode(), contract.getName());
192 builder.setComponentSetId(contract.getComponentSetId());
193 builder.setActive(contract.isActive());
194 builder.setVersionNumber(contract.getVersionNumber());
195 builder.setObjectId(contract.getObjectId());
196 return builder;
197 }
198
199
200
201
202
203
204
205 public void setNamespaceCode(String namespaceCode) {
206 if (StringUtils.isBlank(namespaceCode)) {
207 throw new IllegalArgumentException("namespaceCode is null");
208 }
209 this.namespaceCode = namespaceCode;
210 }
211
212
213
214
215
216
217
218 public void setCode(String code) {
219 if (StringUtils.isBlank(code)) {
220 throw new IllegalArgumentException("code is blank");
221 }
222 this.code = code;
223 }
224
225
226
227
228
229
230
231 public void setName(String name) {
232 if (StringUtils.isBlank(name)) {
233 throw new IllegalArgumentException("name is blank");
234 }
235 this.name = name;
236 }
237
238 @Override
239 public boolean isActive() {
240 return active;
241 }
242
243 public void setActive(boolean active) {
244 this.active = active;
245 }
246
247 @Override
248 public String getNamespaceCode() {
249 return namespaceCode;
250 }
251
252 @Override
253 public String getCode() {
254 return code;
255 }
256
257 @Override
258 public String getName() {
259 return name;
260 }
261
262 @Override
263 public String getComponentSetId() {
264 return componentSetId;
265 }
266
267 public void setComponentSetId(String componentSetId) {
268 if (componentSetId != null && StringUtils.isBlank(componentSetId)) {
269 throw new IllegalArgumentException("componentSetId should be either null or a non-blank value");
270 }
271 this.componentSetId = componentSetId;
272 }
273
274 @Override
275 public Long getVersionNumber() {
276 return versionNumber;
277 }
278
279 public void setVersionNumber(Long versionNumber) {
280 this.versionNumber = versionNumber;
281 }
282
283 @Override
284 public String getObjectId() {
285 return objectId;
286 }
287
288 public void setObjectId(String objectId) {
289 this.objectId = objectId;
290 }
291
292
293
294
295
296
297 @Override
298 public Component build() {
299 return new Component(this);
300 }
301
302 }
303
304
305
306
307 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 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 public static class Cache {
325 public static final String NAME = CoreConstants.Namespaces.CORE_NAMESPACE_2_0 + "/" + Component.Constants.TYPE_NAME;
326 }
327
328 }