1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.common.attribute;
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 = KimAttribute.Constants.ROOT_ELEMENT_NAME)
41 @XmlAccessorType(XmlAccessType.NONE)
42 @XmlType(name = KimAttribute.Constants.TYPE_NAME, propOrder = {
43 KimAttribute.Elements.ID,
44 KimAttribute.Elements.COMPONENT_NAME,
45 KimAttribute.Elements.ATTRIBUTE_NAME,
46 KimAttribute.Elements.NAMESPACE_CODE,
47 KimAttribute.Elements.ATTRIBUTE_LABEL,
48 KimAttribute.Elements.ACTIVE,
49 CoreConstants.CommonElements.VERSION_NUMBER,
50 CoreConstants.CommonElements.OBJECT_ID,
51 CoreConstants.CommonElements.FUTURE_ELEMENTS
52 })
53 public final class KimAttribute extends AbstractDataTransferObject implements KimAttributeContract {
54 private static final long serialVersionUID = 1L;
55
56 @XmlElement(name = KimAttribute.Elements.ID, required = false)
57 private final String id;
58
59 @XmlElement(name = KimAttribute.Elements.COMPONENT_NAME, required = false)
60 private final String componentName;
61
62 @XmlElement(name = KimAttribute.Elements.ATTRIBUTE_NAME, required = true)
63 private final String attributeName;
64
65 @XmlElement(name = KimAttribute.Elements.NAMESPACE_CODE, required = true)
66 private final String namespaceCode;
67
68 @XmlElement(name = KimAttribute.Elements.ATTRIBUTE_LABEL, required = false)
69 private final String attributeLabel;
70
71 @XmlElement(name = KimAttribute.Elements.ACTIVE, required = false)
72 private final boolean active;
73
74 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
75 private final Long versionNumber;
76
77 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
78 private final String objectId;
79
80 @SuppressWarnings("unused")
81 @XmlAnyElement
82 private final Collection<Element> _futureElements = null;
83
84
85
86
87 private KimAttribute() {
88 this.id = null;
89 this.componentName = null;
90 this.attributeName = null;
91 this.namespaceCode = null;
92 this.attributeLabel = null;
93 this.active = false;
94 this.versionNumber = Long.valueOf(1L);
95 this.objectId = null;
96 }
97
98 private KimAttribute(Builder builder) {
99 this.id = builder.getId();
100 this.componentName = builder.getComponentName();
101 this.attributeName = builder.getAttributeName();
102 this.namespaceCode = builder.getNamespaceCode();
103 this.attributeLabel = builder.getAttributeLabel();
104 this.active = builder.isActive();
105 this.versionNumber = builder.getVersionNumber();
106 this.objectId = builder.getObjectId();
107 }
108
109 @Override
110 public String getId() {
111 return id;
112 }
113
114 @Override
115 public String getComponentName() {
116 return componentName;
117 }
118
119 @Override
120 public String getAttributeName() {
121 return attributeName;
122 }
123
124 @Override
125 public String getNamespaceCode() {
126 return namespaceCode;
127 }
128
129 @Override
130 public String getAttributeLabel() {
131 return attributeLabel;
132 }
133
134 @Override
135 public Long getVersionNumber() {
136 return versionNumber;
137 }
138
139 @Override
140 public boolean isActive() {
141 return active;
142 }
143
144 @Override
145 public String getObjectId() {
146 return objectId;
147 }
148
149
150
151
152 public static final class Builder implements KimAttributeContract, ModelBuilder, Serializable {
153 private String id;
154 private String componentName;
155 private String attributeName;
156 private String namespaceCode;
157 private String attributeLabel;
158 private boolean active;
159 private Long versionNumber = 1L;
160 private String objectId;
161
162 private Builder(String componentName, String attributeName, String namespaceCode) {
163 setComponentName(componentName);
164 setAttributeName(attributeName);
165 setNamespaceCode(namespaceCode);
166 }
167
168
169
170
171 public static Builder create(String componentName, String attributeName, String namespaceCode) {
172 return new Builder(componentName, attributeName, namespaceCode);
173 }
174
175
176
177
178 public static Builder create(KimAttributeContract contract) {
179 Builder builder = new Builder(contract.getComponentName(), contract.getAttributeName(), contract.getNamespaceCode());
180 builder.setId(contract.getId());
181 builder.setAttributeLabel(contract.getAttributeLabel());
182 builder.setActive(contract.isActive());
183 builder.setVersionNumber(contract.getVersionNumber());
184 builder.setObjectId(contract.getObjectId());
185 return builder;
186 }
187
188
189 @Override
190 public String getId() {
191 return id;
192 }
193
194 public void setId(final String id) {
195 this.id = id;
196 }
197
198 @Override
199 public String getComponentName() {
200 return componentName;
201 }
202
203 public void setComponentName(final String componentName) {
204 this.componentName = componentName;
205 }
206
207 @Override
208 public String getAttributeName() {
209 return attributeName;
210 }
211
212 public void setAttributeName(final String attributeName) {
213 if (StringUtils.isBlank(attributeName)) {
214 throw new IllegalArgumentException("attributeName is blank");
215 }
216
217 this.attributeName = attributeName;
218 }
219
220 @Override
221 public String getNamespaceCode() {
222 return namespaceCode;
223 }
224
225 public void setNamespaceCode(final String namespaceCode) {
226 if (StringUtils.isBlank(namespaceCode)) {
227 throw new IllegalArgumentException("namespaceCode is blank");
228 }
229
230 this.namespaceCode = namespaceCode;
231 }
232
233 @Override
234 public String getAttributeLabel() {
235 return attributeLabel;
236 }
237
238 public void setAttributeLabel(final String attributeLabel) {
239 this.attributeLabel = attributeLabel;
240 }
241
242 @Override
243 public boolean isActive() {
244 return active;
245 }
246
247 public void setActive(final boolean active) {
248 this.active = active;
249 }
250
251 @Override
252 public Long getVersionNumber() {
253 return versionNumber;
254 }
255
256 public void setVersionNumber(final Long versionNumber) {
257 if (versionNumber <= 0) {
258 throw new IllegalArgumentException("versionNumber is invalid");
259 }
260
261 this.versionNumber = versionNumber;
262 }
263
264 @Override
265 public String getObjectId() {
266 return objectId;
267 }
268
269 public void setObjectId(final String objectId) {
270 this.objectId = objectId;
271 }
272
273 @Override
274 public KimAttribute build() {
275 return new KimAttribute(this);
276 }
277 }
278
279
280
281
282
283 static class Constants {
284 static final String ROOT_ELEMENT_NAME = "kimAttribute";
285 static final String TYPE_NAME = "KimAttributeType";
286 }
287
288
289
290
291
292 static class Elements {
293 static final String ID = "id";
294 static final String COMPONENT_NAME = "componentName";
295 static final String ATTRIBUTE_NAME = "attributeName";
296 static final String NAMESPACE_CODE = "namespaceCode";
297 static final String ATTRIBUTE_LABEL = "attributeLabel";
298 static final String ACTIVE = "active";
299 }
300
301 }