1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.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, 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 public ParameterKey getParameterKey() {
177 return ParameterKey.create(this.applicationId, this.namespaceCode, this.componentCode, this.name);
178 }
179
180
181
182
183 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 private Builder(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) {
199 setApplicationId(applicationId);
200 setNamespaceCode(namespaceCode);
201 setComponentCode(componentCode);
202 setName(name);
203 setParameterType(parameterType);
204 }
205
206
207
208
209 public static Builder create(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) {
210 return new Builder(applicationId, namespaceCode, componentCode, name, parameterType);
211 }
212
213
214
215
216 public static Builder create(ParameterContract contract) {
217 Builder builder = new Builder(contract.getApplicationId(), contract.getNamespaceCode(), contract.getComponentCode(), contract.getName(), ParameterType.Builder.create(contract.getParameterType()));
218 builder.setValue(contract.getValue());
219 builder.setDescription(contract.getDescription());
220 builder.setEvaluationOperator(contract.getEvaluationOperator());
221 builder.setVersionNumber(contract.getVersionNumber());
222 builder.setObjectId(contract.getObjectId());
223 return builder;
224 }
225
226 public void setApplicationId(String applicationId) {
227 if (StringUtils.isBlank(applicationId)) {
228 throw new IllegalArgumentException("applicationId is blank");
229 }
230 this.applicationId = applicationId;
231 }
232
233 public void setNamespaceCode(String namespaceCode) {
234 if (StringUtils.isBlank(namespaceCode)) {
235 throw new IllegalArgumentException("namespaceCode is blank");
236 }
237 this.namespaceCode = namespaceCode;
238 }
239
240 public void setComponentCode(String componentCode) {
241 if (StringUtils.isBlank(componentCode)) {
242 throw new IllegalArgumentException("componentCode is blank");
243 }
244 this.componentCode = componentCode;
245 }
246
247 public void setName(String name) {
248 if (StringUtils.isBlank(name)) {
249 throw new IllegalArgumentException("name is blank");
250 }
251 this.name = name;
252 }
253
254 public void setParameterType(ParameterType.Builder parameterType) {
255 if (parameterType == null) {
256 throw new IllegalArgumentException("parameterType is null");
257 }
258 this.parameterType = parameterType;
259 }
260
261 public void setValue(String value) {
262 this.value = value;
263 }
264
265 public void setDescription(String description) {
266 this.description = description;
267 }
268
269 public void setEvaluationOperator(EvaluationOperator evaluationOperator) {
270 this.evaluationOperator = evaluationOperator;
271 }
272
273 public void setVersionNumber(Long versionNumber) {
274 this.versionNumber = versionNumber;
275 }
276
277 public void setObjectId(String objectId) {
278 this.objectId = objectId;
279 }
280
281 @Override
282 public String getApplicationId() {
283 return applicationId;
284 }
285
286 @Override
287 public String getNamespaceCode() {
288 return namespaceCode;
289 }
290
291 @Override
292 public String getComponentCode() {
293 return componentCode;
294 }
295
296 @Override
297 public String getName() {
298 return name;
299 }
300
301 @Override
302 public String getValue() {
303 return value;
304 }
305
306 @Override
307 public String getDescription() {
308 return description;
309 }
310
311 @Override
312 public EvaluationOperator getEvaluationOperator() {
313 return evaluationOperator;
314 }
315
316 @Override
317 public Parameter build() {
318 return new Parameter(this);
319 }
320
321 @Override
322 public ParameterType.Builder getParameterType() {
323 return parameterType;
324 }
325
326 @Override
327 public Long getVersionNumber() {
328 return versionNumber;
329 }
330
331 @Override
332 public String getObjectId() {
333 return objectId;
334 }
335
336 }
337
338
339
340
341 static class Constants {
342 final static String ROOT_ELEMENT_NAME = "parameter";
343 final static String TYPE_NAME = "ParameterType";
344 }
345
346
347
348
349
350 static class Elements {
351 final static String APPLICATION_ID = "applicationId";
352 final static String NAMESPACE_CODE = "namespaceCode";
353 final static String COMPONENT_CODE = "componentCode";
354 final static String NAME = "name";
355 final static String VALUE = "value";
356 final static String DESCRIPTION = "description";
357 final static String PARAMETER_TYPE = "parameterType";
358 final static String EVALUATION_OPERATOR = "evaluationOperator";
359 }
360
361 public static class Cache {
362 public static final String NAME = CoreConstants.Namespaces.CORE_NAMESPACE_2_0 + "/" + Parameter.Constants.TYPE_NAME;
363 }
364
365 }