1 | |
package org.kuali.rice.kim.api.identity; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
import javax.xml.bind.annotation.XmlAccessType; |
6 | |
import javax.xml.bind.annotation.XmlAccessorType; |
7 | |
import javax.xml.bind.annotation.XmlAnyElement; |
8 | |
import javax.xml.bind.annotation.XmlElement; |
9 | |
import javax.xml.bind.annotation.XmlRootElement; |
10 | |
import javax.xml.bind.annotation.XmlType; |
11 | |
|
12 | |
import org.apache.commons.lang.StringUtils; |
13 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
14 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
15 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
16 | |
import org.kuali.rice.core.api.CoreConstants; |
17 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
18 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
19 | |
import org.w3c.dom.Element; |
20 | |
|
21 | |
@XmlRootElement(name = Type.Constants.ROOT_ELEMENT_NAME) |
22 | |
@XmlAccessorType(XmlAccessType.NONE) |
23 | |
@XmlType(name = Type.Constants.TYPE_NAME, propOrder = { |
24 | |
Type.Elements.CODE, |
25 | |
Type.Elements.NAME, |
26 | |
Type.Elements.SORT_CODE, |
27 | |
Type.Elements.ACTIVE, |
28 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
29 | |
CoreConstants.CommonElements.OBJECT_ID, |
30 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
31 | |
}) |
32 | 37 | public final class Type |
33 | |
implements ModelObjectComplete, TypeContract |
34 | |
{ |
35 | |
@XmlElement(name = Elements.CODE, required = true) |
36 | |
private final String code; |
37 | |
@XmlElement(name = Elements.NAME, required = false) |
38 | |
private final String name; |
39 | |
@XmlElement(name = Elements.SORT_CODE, required = false) |
40 | |
private final String sortCode; |
41 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
42 | |
private final Long versionNumber; |
43 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
44 | |
private final String objectId; |
45 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
46 | |
private final boolean active; |
47 | 63 | @SuppressWarnings("unused") |
48 | |
@XmlAnyElement |
49 | |
private final Collection<Element> _futureElements = null; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 26 | private Type() { |
56 | 26 | this.name = null; |
57 | 26 | this.code = null; |
58 | 26 | this.sortCode = null; |
59 | 26 | this.versionNumber = null; |
60 | 26 | this.objectId = null; |
61 | 26 | this.active = false; |
62 | 26 | } |
63 | |
|
64 | 37 | private Type(Builder builder) { |
65 | 37 | this.name = builder.getName(); |
66 | 37 | this.code = builder.getCode(); |
67 | 37 | this.sortCode = builder.getSortCode(); |
68 | 37 | this.versionNumber = builder.getVersionNumber(); |
69 | 37 | this.objectId = builder.getObjectId(); |
70 | 37 | this.active = builder.isActive(); |
71 | 37 | } |
72 | |
|
73 | |
@Override |
74 | |
public String getName() { |
75 | 13 | return this.name; |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public String getCode() { |
80 | 13 | return this.code; |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public String getSortCode() { |
85 | 13 | return this.sortCode; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public Long getVersionNumber() { |
90 | 13 | return this.versionNumber; |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public String getObjectId() { |
95 | 13 | return this.objectId; |
96 | |
} |
97 | |
|
98 | |
@Override |
99 | |
public boolean isActive() { |
100 | 13 | return this.active; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public int hashCode() { |
105 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public boolean equals(Object object) { |
110 | 27 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public String toString() { |
115 | 0 | return ToStringBuilder.reflectionToString(this); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | 20 | public final static class Builder |
124 | |
implements Serializable, ModelBuilder, TypeContract |
125 | |
{ |
126 | |
|
127 | |
private String name; |
128 | |
private String code; |
129 | |
private String sortCode; |
130 | |
private Long versionNumber; |
131 | |
private String objectId; |
132 | |
private boolean active; |
133 | |
|
134 | 41 | private Builder(String code) { |
135 | 41 | setCode(code); |
136 | 39 | } |
137 | |
|
138 | |
public static Builder create(String code) { |
139 | 41 | return new Builder(code); |
140 | |
} |
141 | |
|
142 | |
public static Builder create(TypeContract contract) { |
143 | 33 | if (contract == null) { |
144 | 0 | throw new IllegalArgumentException("contract was null"); |
145 | |
} |
146 | |
|
147 | 33 | Builder builder = create(contract.getCode()); |
148 | 33 | builder.setName(contract.getName()); |
149 | 33 | builder.setSortCode(contract.getSortCode()); |
150 | 33 | builder.setVersionNumber(contract.getVersionNumber()); |
151 | 33 | builder.setObjectId(contract.getObjectId()); |
152 | 33 | builder.setActive(contract.isActive()); |
153 | 33 | return builder; |
154 | |
} |
155 | |
|
156 | |
public Type build() { |
157 | 37 | return new Type(this); |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public String getName() { |
162 | 38 | return this.name; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public String getCode() { |
167 | 38 | return this.code; |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public String getSortCode() { |
172 | 38 | return this.sortCode; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public Long getVersionNumber() { |
177 | 38 | return this.versionNumber; |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public String getObjectId() { |
182 | 38 | return this.objectId; |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public boolean isActive() { |
187 | 38 | return this.active; |
188 | |
} |
189 | |
|
190 | |
public void setName(String name) { |
191 | 33 | this.name = name; |
192 | 33 | } |
193 | |
|
194 | |
public void setCode(String code) { |
195 | 41 | if (StringUtils.isWhitespace(code)) { |
196 | 2 | throw new IllegalArgumentException("code is empty"); |
197 | |
} |
198 | 39 | this.code = code; |
199 | 39 | } |
200 | |
|
201 | |
public void setSortCode(String sortCode) { |
202 | 33 | this.sortCode = sortCode; |
203 | 33 | } |
204 | |
|
205 | |
public void setVersionNumber(Long versionNumber) { |
206 | 33 | this.versionNumber = versionNumber; |
207 | 33 | } |
208 | |
|
209 | |
public void setObjectId(String objectId) { |
210 | 33 | this.objectId = objectId; |
211 | 33 | } |
212 | |
|
213 | |
public void setActive(boolean active) { |
214 | 33 | this.active = active; |
215 | 33 | } |
216 | |
|
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | 0 | static class Constants { |
225 | |
|
226 | |
final static String ROOT_ELEMENT_NAME = "type"; |
227 | |
final static String TYPE_NAME = "typeType"; |
228 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
229 | |
|
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | 0 | static class Elements { |
238 | |
|
239 | |
final static String NAME = "name"; |
240 | |
final static String CODE = "code"; |
241 | |
final static String SORT_CODE = "sortCode"; |
242 | |
final static String ACTIVE = "active"; |
243 | |
|
244 | |
} |
245 | |
|
246 | |
} |