1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.api.namespace; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
import java.util.Collection; |
21 | |
|
22 | |
import javax.xml.bind.annotation.XmlAccessType; |
23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
24 | |
import javax.xml.bind.annotation.XmlAnyElement; |
25 | |
import javax.xml.bind.annotation.XmlElement; |
26 | |
import javax.xml.bind.annotation.XmlRootElement; |
27 | |
import javax.xml.bind.annotation.XmlType; |
28 | |
|
29 | |
import org.apache.commons.lang.StringUtils; |
30 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
31 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
32 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
33 | |
import org.kuali.rice.core.api.CoreConstants; |
34 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
35 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
36 | |
import org.w3c.dom.Element; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@XmlRootElement(name = Namespace.Constants.ROOT_ELEMENT_NAME) |
46 | |
@XmlAccessorType(XmlAccessType.NONE) |
47 | |
@XmlType(name = Namespace.Constants.TYPE_NAME, propOrder = { |
48 | |
Namespace.Elements.CODE, |
49 | |
Namespace.Elements.APPLICATION_ID, |
50 | |
Namespace.Elements.NAME, |
51 | |
Namespace.Elements.ACTIVE, |
52 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
53 | |
CoreConstants.CommonElements.OBJECT_ID, |
54 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
55 | |
}) |
56 | 1 | public final class Namespace implements NamespaceContract, ModelObjectComplete { |
57 | |
|
58 | |
private static final long serialVersionUID = -5206398776503106883L; |
59 | |
|
60 | |
@XmlElement(name = Elements.CODE, required=true) |
61 | |
private final String code; |
62 | |
|
63 | |
@XmlElement(name = Elements.APPLICATION_ID, required=true) |
64 | |
private final String applicationId; |
65 | |
|
66 | |
@XmlElement(name = Elements.NAME, required=false) |
67 | |
private final String name; |
68 | |
|
69 | |
@XmlElement(name = Elements.ACTIVE, required=false) |
70 | |
private final boolean active; |
71 | |
|
72 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
73 | |
private final Long versionNumber; |
74 | |
|
75 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
76 | |
private final String objectId; |
77 | |
|
78 | 3 | @SuppressWarnings("unused") |
79 | |
@XmlAnyElement |
80 | |
private final Collection<Element> _futureElements = null; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | 2 | private Namespace() { |
86 | 2 | this.code = null; |
87 | 2 | this.applicationId = null; |
88 | 2 | this.name = null; |
89 | 2 | this.active = true; |
90 | 2 | this.versionNumber = null; |
91 | 2 | this.objectId = null; |
92 | 2 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 1 | private Namespace(Builder builder) { |
101 | 1 | code = builder.getCode(); |
102 | 1 | applicationId = builder.getApplicationId(); |
103 | 1 | name = builder.getName(); |
104 | 1 | active = builder.isActive(); |
105 | 1 | versionNumber = builder.getVersionNumber(); |
106 | 1 | objectId = builder.getObjectId(); |
107 | 1 | } |
108 | |
|
109 | |
@Override |
110 | |
public String getCode() { |
111 | 0 | return code; |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public String getApplicationId() { |
116 | 0 | return applicationId; |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public String getName() { |
121 | 0 | return name; |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public boolean isActive() { |
126 | 0 | return active; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public Long getVersionNumber() { |
131 | 0 | return versionNumber; |
132 | |
} |
133 | |
|
134 | |
@Override |
135 | |
public String getObjectId() { |
136 | 0 | return objectId; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 1 | public static final class Builder implements NamespaceContract, ModelBuilder, Serializable { |
143 | |
|
144 | |
private static final long serialVersionUID = -70194982373806749L; |
145 | |
|
146 | |
private String code; |
147 | |
private String applicationId; |
148 | |
private String name; |
149 | |
private boolean active; |
150 | |
private Long versionNumber; |
151 | |
private String objectId; |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | 9 | private Builder(String code, String applicationId) { |
161 | 9 | setCode(code); |
162 | 5 | setApplicationId(applicationId); |
163 | 2 | setActive(true); |
164 | 2 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public static Builder create(String code, String applicationId) { |
175 | 8 | return new Builder(code, applicationId); |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public static Builder create(NamespaceContract contract) { |
185 | 1 | Builder builder = new Builder(contract.getCode(), contract.getApplicationId()); |
186 | 1 | builder.setName(contract.getName()); |
187 | 1 | builder.setActive(contract.isActive()); |
188 | 1 | builder.setVersionNumber(contract.getVersionNumber()); |
189 | 1 | builder.setObjectId(contract.getObjectId()); |
190 | 1 | return builder; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
public void setCode(String code) { |
200 | 9 | if (StringUtils.isBlank(code)) { |
201 | 4 | throw new IllegalArgumentException("code is blank"); |
202 | |
} |
203 | 5 | this.code = code; |
204 | 5 | } |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public void setApplicationId(String applicationId) { |
213 | 5 | if (StringUtils.isBlank(applicationId)) { |
214 | 3 | throw new IllegalArgumentException("applicationId is blank"); |
215 | |
} |
216 | 2 | this.applicationId = applicationId; |
217 | 2 | } |
218 | |
|
219 | |
public void setVersionNumber(Long versionNumber) { |
220 | 1 | this.versionNumber = versionNumber; |
221 | 1 | } |
222 | |
|
223 | |
public void setObjectId(String objectId) { |
224 | 1 | this.objectId = objectId; |
225 | 1 | } |
226 | |
|
227 | |
@Override |
228 | |
public String getName() { |
229 | 1 | return name; |
230 | |
} |
231 | |
|
232 | |
public void setName(String name) { |
233 | 1 | this.name = name; |
234 | 1 | } |
235 | |
|
236 | |
@Override |
237 | |
public boolean isActive() { |
238 | 1 | return active; |
239 | |
} |
240 | |
|
241 | |
public void setActive(boolean active) { |
242 | 3 | this.active = active; |
243 | 3 | } |
244 | |
|
245 | |
@Override |
246 | |
public String getCode() { |
247 | 1 | return code; |
248 | |
} |
249 | |
|
250 | |
@Override |
251 | |
public String getApplicationId() { |
252 | 1 | return applicationId; |
253 | |
} |
254 | |
|
255 | |
@Override |
256 | |
public Long getVersionNumber() { |
257 | 1 | return versionNumber; |
258 | |
} |
259 | |
|
260 | |
@Override |
261 | |
public String getObjectId() { |
262 | 1 | return objectId; |
263 | |
} |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
@Override |
271 | |
public Namespace build() { |
272 | 1 | return new Namespace(this); |
273 | |
} |
274 | |
|
275 | |
} |
276 | |
|
277 | |
@Override |
278 | |
public int hashCode() { |
279 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
280 | |
} |
281 | |
|
282 | |
@Override |
283 | |
public boolean equals(Object obj) { |
284 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
285 | |
} |
286 | |
|
287 | |
@Override |
288 | |
public String toString() { |
289 | 0 | return ToStringBuilder.reflectionToString(this); |
290 | |
} |
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | 0 | static class Constants { |
296 | |
final static String ROOT_ELEMENT_NAME = "namespace"; |
297 | |
final static String TYPE_NAME = "NamespaceType"; |
298 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
299 | |
} |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | 0 | static class Elements { |
306 | |
final static String CODE = "code"; |
307 | |
final static String APPLICATION_ID = "applicationId"; |
308 | |
final static String NAME = "name"; |
309 | |
final static String ACTIVE = "active"; |
310 | |
} |
311 | |
|
312 | |
} |