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