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