1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.function;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.List;
23
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAnyElement;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlElementWrapper;
29 import javax.xml.bind.annotation.XmlRootElement;
30 import javax.xml.bind.annotation.XmlType;
31
32 import org.apache.commons.lang.StringUtils;
33 import org.apache.commons.lang.builder.EqualsBuilder;
34 import org.apache.commons.lang.builder.HashCodeBuilder;
35 import org.apache.commons.lang.builder.ToStringBuilder;
36 import org.kuali.rice.core.api.CoreConstants;
37 import org.kuali.rice.core.api.mo.ModelBuilder;
38 import org.kuali.rice.core.api.mo.ModelObjectComplete;
39 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
40 import org.w3c.dom.Element;
41
42
43
44
45
46
47
48
49
50 @XmlRootElement(name = FunctionDefinition.Constants.ROOT_ELEMENT_NAME)
51 @XmlAccessorType(XmlAccessType.NONE)
52 @XmlType(name = FunctionDefinition.Constants.TYPE_NAME, propOrder = {
53 FunctionDefinition.Elements.ID,
54 FunctionDefinition.Elements.NAMESPACE,
55 FunctionDefinition.Elements.NAME,
56 FunctionParameterDefinition.Elements.DESCRIPTION,
57 FunctionDefinition.Elements.RETURN_TYPE,
58 FunctionDefinition.Elements.TYPE_ID,
59 FunctionDefinition.Elements.ACTIVE,
60 CoreConstants.CommonElements.VERSION_NUMBER,
61 FunctionDefinition.Elements.PARAMETERS,
62 CoreConstants.CommonElements.FUTURE_ELEMENTS
63 })
64 public class FunctionDefinition implements FunctionDefinitionContract, ModelObjectComplete {
65
66 private static final long serialVersionUID = 1391030685309770560L;
67
68 @XmlElement(name = Elements.ID, required = false)
69 private final String id;
70
71 @XmlElement(name = Elements.NAMESPACE, required = true)
72 private final String namespace;
73
74 @XmlElement(name = Elements.NAME, required = true)
75 private final String name;
76
77 @XmlElement(name = Elements.DESCRIPTION, required = false)
78 private final String description;
79
80 @XmlElement(name = Elements.RETURN_TYPE, required = true)
81 private final String returnType;
82
83 @XmlElement(name = Elements.TYPE_ID, required = true)
84 private final String typeId;
85
86 @XmlElement(name = Elements.ACTIVE, required = true)
87 private final boolean active;
88
89 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
90 private final Long versionNumber;
91
92 @XmlElementWrapper(name = Elements.PARAMETERS, required = false)
93 @XmlElement(name = Elements.PARAMETER, required = false)
94 private final List<FunctionParameterDefinition> parameters;
95
96 @SuppressWarnings("unused")
97 @XmlAnyElement
98 private final Collection<Element> _futureElements = null;
99
100
101
102
103 private FunctionDefinition() {
104 this.id = null;
105 this.namespace = null;
106 this.name = null;
107 this.description = null;
108 this.returnType = null;
109 this.typeId = null;
110 this.active = false;
111 this.versionNumber = null;
112 this.parameters = null;
113 }
114
115 private FunctionDefinition(Builder builder) {
116 this.id = builder.getId();
117 this.namespace = builder.getNamespace();
118 this.name = builder.getName();
119 this.description = builder.getDescription();
120 this.returnType = builder.getReturnType();
121 this.typeId = builder.getTypeId();
122 this.active = builder.isActive();
123 this.versionNumber = builder.getVersionNumber();
124 this.parameters = new ArrayList<FunctionParameterDefinition>();
125 for (FunctionParameterDefinition.Builder parameter : builder.getParameters()) {
126 this.parameters.add(parameter.build());
127 }
128 }
129
130 @Override
131 public String getId() {
132 return id;
133 }
134
135 @Override
136 public String getNamespace() {
137 return namespace;
138 }
139
140 @Override
141 public String getName() {
142 return name;
143 }
144
145 @Override
146 public String getDescription() {
147 return description;
148 }
149
150 @Override
151 public String getReturnType() {
152 return returnType;
153 }
154
155 @Override
156 public String getTypeId() {
157 return typeId;
158 }
159
160 @Override
161 public boolean isActive() {
162 return active;
163 }
164
165 @Override
166 public Long getVersionNumber() {
167 return versionNumber;
168 }
169
170 @Override
171 public List<FunctionParameterDefinition> getParameters() {
172 return Collections.unmodifiableList(parameters);
173 }
174
175
176
177
178
179
180
181
182 public static final class Builder implements FunctionDefinitionContract, ModelBuilder, Serializable {
183
184 private static final long serialVersionUID = -4470376239998290245L;
185
186 private String id;
187 private String namespace;
188 private String name;
189 private String description;
190 private String returnType;
191 private String typeId;
192 private boolean active;
193 private Long versionNumber;
194 private List<FunctionParameterDefinition.Builder> parameters;
195
196 private Builder(String namespace, String name, String returnType, String typeId) {
197 setNamespace(namespace);
198 setName(name);
199 setReturnType(returnType);
200 setTypeId(typeId);
201 setActive(true);
202 setParameters(new ArrayList<FunctionParameterDefinition.Builder>());
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 public static Builder create(String namespace, String name, String returnType, String typeId) {
221 return new Builder(namespace, name, returnType, typeId);
222 }
223
224
225
226
227
228
229
230
231
232
233
234
235 public static Builder create(FunctionDefinitionContract contract) {
236 if (contract == null) {
237 throw new IllegalArgumentException("contract was null");
238 }
239 Builder builder = create(contract.getNamespace(), contract.getName(), contract.getReturnType(), contract.getTypeId());
240 builder.setId(contract.getId());
241 builder.setDescription(contract.getDescription());
242 builder.setActive(contract.isActive());
243 builder.setVersionNumber(contract.getVersionNumber());
244 for (FunctionParameterDefinitionContract parameter : contract.getParameters()) {
245 builder.getParameters().add(FunctionParameterDefinition.Builder.create(parameter));
246 }
247 return builder;
248 }
249
250 @Override
251 public FunctionDefinition build() {
252 return new FunctionDefinition(this);
253 }
254
255 @Override
256 public String getId() {
257 return this.id;
258 }
259
260
261
262
263
264
265 public void setId(String id) {
266 this.id = id;
267 }
268
269 @Override
270 public String getNamespace() {
271 return this.namespace;
272 }
273
274
275
276
277
278
279
280
281
282 public void setNamespace(String namespace) {
283 if (StringUtils.isBlank(namespace)) {
284 throw new IllegalArgumentException("namespace was blank");
285 }
286 this.namespace = namespace;
287 }
288
289 @Override
290 public String getName() {
291 return this.name;
292 }
293
294
295
296
297
298
299
300
301
302 public void setName(String name) {
303 if (StringUtils.isBlank(name)) {
304 throw new IllegalArgumentException("name was blank");
305 }
306 this.name = name;
307 }
308
309 @Override
310 public String getDescription() {
311 return this.description;
312 }
313
314
315
316
317
318
319 public void setDescription(String description) {
320 this.description = description;
321 }
322
323 @Override
324 public String getReturnType() {
325 return this.returnType;
326 }
327
328
329
330
331
332
333
334
335
336
337
338 public void setReturnType(String returnType) {
339 if (StringUtils.isBlank(returnType)) {
340 throw new IllegalArgumentException("returnType was blank");
341 }
342 this.returnType = returnType;
343 }
344
345 @Override
346 public String getTypeId() {
347 return this.typeId;
348 }
349
350
351
352
353
354
355
356
357
358
359 public void setTypeId(String typeId) {
360 if (StringUtils.isBlank(typeId)) {
361 throw new IllegalArgumentException("typeId was blank");
362 }
363 this.typeId = typeId;
364 }
365
366 @Override
367 public boolean isActive() {
368 return this.active;
369 }
370
371
372
373
374
375
376
377 public void setActive(boolean active) {
378 this.active = active;
379 }
380
381 @Override
382 public Long getVersionNumber() {
383 return this.versionNumber;
384 }
385
386
387
388
389
390
391
392
393
394
395
396 public void setVersionNumber(Long versionNumber) {
397 this.versionNumber = versionNumber;
398 }
399
400 @Override
401 public List<FunctionParameterDefinition.Builder> getParameters() {
402 return this.parameters;
403 }
404
405
406
407
408
409
410
411
412
413
414
415 public void setParameters(List<FunctionParameterDefinition.Builder> parameters) {
416 if (parameters == null) {
417 throw new IllegalArgumentException("parameters was null");
418 }
419 this.parameters = parameters;
420 }
421
422 }
423
424 @Override
425 public int hashCode() {
426 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
427 }
428
429 @Override
430 public boolean equals(Object obj) {
431 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
432 }
433
434 @Override
435 public String toString() {
436 return ToStringBuilder.reflectionToString(this);
437 }
438
439
440
441
442 static class Constants {
443 final static String ROOT_ELEMENT_NAME = "function";
444 final static String TYPE_NAME = "FunctionType";
445 final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
446 }
447
448
449
450
451
452 static class Elements {
453 final static String ID = "id";
454 final static String NAMESPACE = "namespace";
455 final static String NAME = "name";
456 final static String DESCRIPTION = "description";
457 final static String RETURN_TYPE = "returnType";
458 final static String TYPE_ID = "typeId";
459 final static String ACTIVE = "active";
460 final static String PARAMETERS = "parameters";
461 final static String PARAMETER = "parameter";
462 }
463
464 }