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