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