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