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