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