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