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 | 12 | 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 | 19 | @SuppressWarnings("unused") |
85 | |
@XmlAnyElement |
86 | |
private final Collection<Element> _futureElements = null; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | 7 | private KimAttribute() { |
92 | 7 | this.id = null; |
93 | 7 | this.componentName = null; |
94 | 7 | this.attributeName = null; |
95 | 7 | this.namespaceCode = null; |
96 | 7 | this.attributeLabel = null; |
97 | 7 | this.active = false; |
98 | 7 | this.versionNumber = Long.valueOf(1L); |
99 | 7 | this.objectId = null; |
100 | 7 | } |
101 | |
|
102 | 12 | private KimAttribute(Builder builder) { |
103 | 12 | this.id = builder.getId(); |
104 | 12 | this.componentName = builder.getComponentName(); |
105 | 12 | this.attributeName = builder.getAttributeName(); |
106 | 12 | this.namespaceCode = builder.getNamespaceCode(); |
107 | 12 | this.attributeLabel = builder.getAttributeLabel(); |
108 | 12 | this.active = builder.isActive(); |
109 | 12 | this.versionNumber = builder.getVersionNumber(); |
110 | 12 | this.objectId = builder.getObjectId(); |
111 | 12 | } |
112 | |
|
113 | |
@Override |
114 | |
public String getId() { |
115 | 6 | return id; |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public String getComponentName() { |
120 | 6 | return componentName; |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public String getAttributeName() { |
125 | 6 | return attributeName; |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
public String getNamespaceCode() { |
130 | 6 | return namespaceCode; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public String getAttributeLabel() { |
135 | 5 | return attributeLabel; |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public Long getVersionNumber() { |
140 | 5 | return versionNumber; |
141 | |
} |
142 | |
|
143 | |
@Override |
144 | |
public boolean isActive() { |
145 | 5 | return active; |
146 | |
} |
147 | |
|
148 | |
@Override |
149 | |
public String getObjectId() { |
150 | 5 | 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 | 5 | 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 | 25 | private Long versionNumber = 1L; |
179 | |
private String objectId; |
180 | |
|
181 | 25 | private Builder(String componentName, String attributeName, String namespaceCode) { |
182 | 25 | setComponentName(componentName); |
183 | 21 | setAttributeName(attributeName); |
184 | 18 | setNamespaceCode(namespaceCode); |
185 | 15 | } |
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 | 6 | Builder builder = new Builder(contract.getComponentName(), contract.getAttributeName(), contract.getNamespaceCode()); |
199 | 6 | builder.setId(contract.getId()); |
200 | 6 | builder.setAttributeLabel(contract.getAttributeLabel()); |
201 | 6 | builder.setActive(contract.isActive()); |
202 | 6 | builder.setVersionNumber(contract.getVersionNumber()); |
203 | 6 | builder.setObjectId(contract.getObjectId()); |
204 | 6 | return builder; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
@Override |
209 | |
public String getId() { |
210 | 12 | return id; |
211 | |
} |
212 | |
|
213 | |
public void setId(final String id) { |
214 | 11 | this.id = id; |
215 | 11 | } |
216 | |
|
217 | |
@Override |
218 | |
public String getComponentName() { |
219 | 12 | return componentName; |
220 | |
} |
221 | |
|
222 | |
public void setComponentName(final String componentName) { |
223 | 25 | if (StringUtils.isBlank(componentName)) { |
224 | 4 | throw new IllegalArgumentException("componentName is blank"); |
225 | |
} |
226 | |
|
227 | 21 | this.componentName = componentName; |
228 | 21 | } |
229 | |
|
230 | |
@Override |
231 | |
public String getAttributeName() { |
232 | 12 | return attributeName; |
233 | |
} |
234 | |
|
235 | |
public void setAttributeName(final String attributeName) { |
236 | 21 | if (StringUtils.isBlank(attributeName)) { |
237 | 3 | throw new IllegalArgumentException("attributeName is blank"); |
238 | |
} |
239 | |
|
240 | 18 | this.attributeName = attributeName; |
241 | 18 | } |
242 | |
|
243 | |
@Override |
244 | |
public String getNamespaceCode() { |
245 | 12 | return namespaceCode; |
246 | |
} |
247 | |
|
248 | |
public void setNamespaceCode(final String namespaceCode) { |
249 | 18 | if (StringUtils.isBlank(namespaceCode)) { |
250 | 3 | throw new IllegalArgumentException("namespaceCode is blank"); |
251 | |
} |
252 | |
|
253 | 15 | this.namespaceCode = namespaceCode; |
254 | 15 | } |
255 | |
|
256 | |
@Override |
257 | |
public String getAttributeLabel() { |
258 | 12 | return attributeLabel; |
259 | |
} |
260 | |
|
261 | |
public void setAttributeLabel(final String attributeLabel) { |
262 | 6 | this.attributeLabel = attributeLabel; |
263 | 6 | } |
264 | |
|
265 | |
@Override |
266 | |
public boolean isActive() { |
267 | 12 | return active; |
268 | |
} |
269 | |
|
270 | |
public void setActive(final boolean active) { |
271 | 6 | this.active = active; |
272 | 6 | } |
273 | |
|
274 | |
@Override |
275 | |
public Long getVersionNumber() { |
276 | 12 | return versionNumber; |
277 | |
} |
278 | |
|
279 | |
public void setVersionNumber(final Long versionNumber) { |
280 | 8 | if (versionNumber == null || versionNumber <= 0) { |
281 | 2 | throw new IllegalArgumentException("versionNumber is invalid"); |
282 | |
} |
283 | |
|
284 | 6 | this.versionNumber = versionNumber; |
285 | 6 | } |
286 | |
|
287 | |
@Override |
288 | |
public String getObjectId() { |
289 | 12 | return objectId; |
290 | |
} |
291 | |
|
292 | |
public void setObjectId(final String objectId) { |
293 | 6 | this.objectId = objectId; |
294 | 6 | } |
295 | |
|
296 | |
@Override |
297 | |
public KimAttribute build() { |
298 | 12 | 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 | |
} |