1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.api.parameter; |
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 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
29 | |
|
30 | |
import org.apache.commons.lang.StringUtils; |
31 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
32 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
33 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
34 | |
import org.kuali.rice.core.api.CoreConstants; |
35 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
36 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
37 | |
import org.w3c.dom.Element; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 1 | @XmlRootElement(name = Parameter.Constants.ROOT_ELEMENT_NAME) |
47 | |
@XmlAccessorType(XmlAccessType.NONE) |
48 | |
@XmlType(name = Parameter.Constants.TYPE_NAME, propOrder = { |
49 | |
Parameter.Elements.APPLICATION_ID, |
50 | |
Parameter.Elements.NAMESPACE_CODE, |
51 | |
Parameter.Elements.COMPONENT_CODE, |
52 | |
Parameter.Elements.NAME, |
53 | |
Parameter.Elements.VALUE, |
54 | |
Parameter.Elements.DESCRIPTION, |
55 | |
Parameter.Elements.PARAMETER_TYPE, |
56 | |
Parameter.Elements.EVALUATION_OPERATOR, |
57 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
58 | |
CoreConstants.CommonElements.OBJECT_ID, |
59 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
60 | |
}) |
61 | 3 | public final class Parameter implements ParameterContract, ModelObjectComplete { |
62 | |
|
63 | |
private static final long serialVersionUID = 6097498602725305353L; |
64 | |
|
65 | |
@XmlElement(name = Elements.APPLICATION_ID, required = true) |
66 | |
private final String applicationId; |
67 | |
|
68 | |
@XmlElement(name = Elements.NAMESPACE_CODE, required = true) |
69 | |
private final String namespaceCode; |
70 | |
|
71 | |
@XmlElement(name = Elements.COMPONENT_CODE, required = true) |
72 | |
private final String componentCode; |
73 | |
|
74 | |
@XmlElement(name = Elements.NAME, required = true) |
75 | |
private final String name; |
76 | |
|
77 | |
@XmlElement(name = Elements.VALUE, nillable = true, required = false) |
78 | |
private final String value; |
79 | |
|
80 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
81 | |
private final String description; |
82 | |
|
83 | |
@XmlElement(name = Elements.PARAMETER_TYPE, required = true) |
84 | |
private final ParameterType parameterType; |
85 | |
|
86 | |
@XmlJavaTypeAdapter(EvaluationOperator.Adapter.class) |
87 | |
@XmlElement(name = Elements.EVALUATION_OPERATOR, required = false) |
88 | |
private final String evaluationOperator; |
89 | |
|
90 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
91 | |
private final Long versionNumber; |
92 | |
|
93 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
94 | |
private final String objectId; |
95 | |
|
96 | 5 | @SuppressWarnings("unused") |
97 | |
@XmlAnyElement |
98 | |
private final Collection<Element> _futureElements = null; |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 2 | private Parameter() { |
104 | 2 | this.applicationId = null; |
105 | 2 | this.namespaceCode = null; |
106 | 2 | this.componentCode = null; |
107 | 2 | this.name = null; |
108 | 2 | this.value = null; |
109 | 2 | this.description = null; |
110 | 2 | this.parameterType = null; |
111 | 2 | this.evaluationOperator = null; |
112 | 2 | this.versionNumber = null; |
113 | 2 | this.objectId = null; |
114 | 2 | } |
115 | |
|
116 | 3 | private Parameter(Builder builder) { |
117 | 3 | applicationId = builder.getApplicationId(); |
118 | 3 | namespaceCode = builder.getNamespaceCode(); |
119 | 3 | componentCode = builder.getComponentCode(); |
120 | 3 | name = builder.getName(); |
121 | 3 | value = builder.getValue(); |
122 | 3 | description = builder.getDescription(); |
123 | 3 | parameterType = builder.parameterType.build(); |
124 | 3 | EvaluationOperator evaluationOperatorEnum = builder.getEvaluationOperator(); |
125 | 3 | evaluationOperator = evaluationOperatorEnum == null ? null : evaluationOperatorEnum.getCode(); |
126 | 3 | versionNumber = builder.getVersionNumber(); |
127 | 3 | objectId = builder.getObjectId(); |
128 | 3 | } |
129 | |
|
130 | |
@Override |
131 | |
public String getApplicationId() { |
132 | 1 | return applicationId; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public String getNamespaceCode() { |
137 | 1 | return namespaceCode; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public String getComponentCode() { |
142 | 1 | return componentCode; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public String getName() { |
147 | 1 | return name; |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public String getValue() { |
152 | 1 | return value; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public String getDescription() { |
157 | 1 | return description; |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public ParameterType getParameterType() { |
162 | 1 | return parameterType; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public EvaluationOperator getEvaluationOperator() { |
167 | 1 | return EvaluationOperator.fromCode(evaluationOperator); |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public Long getVersionNumber() { |
172 | 1 | return versionNumber; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public String getObjectId() { |
177 | 1 | return objectId; |
178 | |
} |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | 6 | public static final class Builder implements ParameterContract, ModelBuilder, Serializable { |
184 | |
|
185 | |
private static final long serialVersionUID = 7077484401017765844L; |
186 | |
|
187 | |
private String applicationId; |
188 | |
private String namespaceCode; |
189 | |
private String componentCode; |
190 | |
private String name; |
191 | |
private String value; |
192 | |
private String description; |
193 | |
private ParameterType.Builder parameterType; |
194 | |
private EvaluationOperator evaluationOperator; |
195 | |
private Long versionNumber; |
196 | |
private String objectId; |
197 | |
|
198 | 18 | private Builder(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) { |
199 | 18 | setApplicationId(applicationId); |
200 | 14 | setNamespaceCode(namespaceCode); |
201 | 11 | setComponentCode(componentCode); |
202 | 8 | setName(name); |
203 | 5 | setParameterType(parameterType); |
204 | 4 | } |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public static Builder create(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) { |
210 | 16 | return new Builder(applicationId, namespaceCode, componentCode, name, parameterType); |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
public static Builder create(ParameterContract contract) { |
217 | 2 | Builder builder = new Builder(contract.getApplicationId(), contract.getNamespaceCode(), contract.getComponentCode(), contract.getName(), ParameterType.Builder.create(contract.getParameterType())); |
218 | 2 | builder.setValue(contract.getValue()); |
219 | 2 | builder.setDescription(contract.getDescription()); |
220 | 2 | builder.setEvaluationOperator(contract.getEvaluationOperator()); |
221 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
222 | 2 | builder.setObjectId(contract.getObjectId()); |
223 | 2 | return builder; |
224 | |
} |
225 | |
|
226 | |
public void setApplicationId(String applicationId) { |
227 | 18 | if (StringUtils.isBlank(applicationId)) { |
228 | 4 | throw new IllegalArgumentException("applicationId is blank"); |
229 | |
} |
230 | 14 | this.applicationId = applicationId; |
231 | 14 | } |
232 | |
|
233 | |
public void setNamespaceCode(String namespaceCode) { |
234 | 14 | if (StringUtils.isBlank(namespaceCode)) { |
235 | 3 | throw new IllegalArgumentException("namespaceCode is blank"); |
236 | |
} |
237 | 11 | this.namespaceCode = namespaceCode; |
238 | 11 | } |
239 | |
|
240 | |
public void setComponentCode(String componentCode) { |
241 | 11 | if (StringUtils.isBlank(componentCode)) { |
242 | 3 | throw new IllegalArgumentException("componentCode is blank"); |
243 | |
} |
244 | 8 | this.componentCode = componentCode; |
245 | 8 | } |
246 | |
|
247 | |
public void setName(String name) { |
248 | 8 | if (StringUtils.isBlank(name)) { |
249 | 3 | throw new IllegalArgumentException("name is blank"); |
250 | |
} |
251 | 5 | this.name = name; |
252 | 5 | } |
253 | |
|
254 | |
public void setParameterType(ParameterType.Builder parameterType) { |
255 | 5 | if (parameterType == null) { |
256 | 1 | throw new IllegalArgumentException("parameterType is null"); |
257 | |
} |
258 | 4 | this.parameterType = parameterType; |
259 | 4 | } |
260 | |
|
261 | |
public void setValue(String value) { |
262 | 2 | this.value = value; |
263 | 2 | } |
264 | |
|
265 | |
public void setDescription(String description) { |
266 | 2 | this.description = description; |
267 | 2 | } |
268 | |
|
269 | |
public void setEvaluationOperator(EvaluationOperator evaluationOperator) { |
270 | 2 | this.evaluationOperator = evaluationOperator; |
271 | 2 | } |
272 | |
|
273 | |
public void setVersionNumber(Long versionNumber) { |
274 | 2 | this.versionNumber = versionNumber; |
275 | 2 | } |
276 | |
|
277 | |
public void setObjectId(String objectId) { |
278 | 2 | this.objectId = objectId; |
279 | 2 | } |
280 | |
|
281 | |
@Override |
282 | |
public String getApplicationId() { |
283 | 3 | return applicationId; |
284 | |
} |
285 | |
|
286 | |
@Override |
287 | |
public String getNamespaceCode() { |
288 | 3 | return namespaceCode; |
289 | |
} |
290 | |
|
291 | |
@Override |
292 | |
public String getComponentCode() { |
293 | 3 | return componentCode; |
294 | |
} |
295 | |
|
296 | |
@Override |
297 | |
public String getName() { |
298 | 3 | return name; |
299 | |
} |
300 | |
|
301 | |
@Override |
302 | |
public String getValue() { |
303 | 3 | return value; |
304 | |
} |
305 | |
|
306 | |
@Override |
307 | |
public String getDescription() { |
308 | 3 | return description; |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
public EvaluationOperator getEvaluationOperator() { |
313 | 3 | return evaluationOperator; |
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
public Parameter build() { |
318 | 3 | return new Parameter(this); |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
public ParameterType.Builder getParameterType() { |
323 | 0 | return parameterType; |
324 | |
} |
325 | |
|
326 | |
@Override |
327 | |
public Long getVersionNumber() { |
328 | 3 | return versionNumber; |
329 | |
} |
330 | |
|
331 | |
@Override |
332 | |
public String getObjectId() { |
333 | 3 | return objectId; |
334 | |
} |
335 | |
|
336 | |
} |
337 | |
|
338 | |
@Override |
339 | |
public int hashCode() { |
340 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
341 | |
} |
342 | |
|
343 | |
@Override |
344 | |
public boolean equals(Object obj) { |
345 | 3 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
346 | |
} |
347 | |
|
348 | |
@Override |
349 | |
public String toString() { |
350 | 0 | return ToStringBuilder.reflectionToString(this); |
351 | |
} |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | 0 | static class Constants { |
357 | |
final static String ROOT_ELEMENT_NAME = "parameter"; |
358 | |
final static String TYPE_NAME = "ParameterType"; |
359 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
360 | |
} |
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | 0 | static class Elements { |
367 | |
final static String APPLICATION_ID = "applicationId"; |
368 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
369 | |
final static String COMPONENT_CODE = "componentCode"; |
370 | |
final static String NAME = "name"; |
371 | |
final static String VALUE = "value"; |
372 | |
final static String DESCRIPTION = "description"; |
373 | |
final static String PARAMETER_TYPE = "parameterType"; |
374 | |
final static String EVALUATION_OPERATOR = "evaluationOperator"; |
375 | |
} |
376 | |
|
377 | |
} |