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 java.io.Serializable;
19 import java.util.Collection;
20 import java.util.List;
21
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAnyElement;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlElementWrapper;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import javax.xml.bind.annotation.XmlType;
29
30 import org.apache.commons.lang.StringUtils;
31 import org.jdom.IllegalAddException;
32 import org.kuali.rice.core.api.CoreConstants;
33 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
34 import org.kuali.rice.core.api.mo.ModelBuilder;
35 import org.kuali.rice.krms.api.KrmsConstants;
36 import org.kuali.rice.krms.api.repository.BuilderUtils;
37
38
39
40
41
42
43
44 @XmlRootElement(name = TermDefinition.Constants.ROOT_ELEMENT_NAME)
45 @XmlAccessorType(XmlAccessType.NONE)
46 @XmlType(name = TermDefinition.Constants.TYPE_NAME, propOrder = {
47 TermDefinition.Elements.ID,
48 TermDefinition.Elements.SPECIFICATION,
49 TermDefinition.Elements.DESCRIPTION,
50 TermDefinition.Elements.PARAMETERS,
51 CoreConstants.CommonElements.VERSION_NUMBER,
52 CoreConstants.CommonElements.FUTURE_ELEMENTS
53 })
54 public final class TermDefinition extends AbstractDataTransferObject implements TermDefinitionContract {
55
56 private static final long serialVersionUID = 1L;
57
58 @XmlElement(name = Elements.ID, required=false)
59 private final String id;
60 @XmlElement(name = Elements.SPECIFICATION, required=true)
61 private final TermSpecificationDefinition specification;
62 @XmlElement(name = Elements.DESCRIPTION, required=false)
63 private final String description;
64 @XmlElementWrapper(name = Elements.PARAMETERS, required=false)
65 @XmlElement(name = "parameter", required=false)
66 private final List<TermParameterDefinition> parameters;
67 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
68 private final Long versionNumber;
69
70 @SuppressWarnings("unused")
71 @XmlAnyElement
72 private final Collection<org.w3c.dom.Element> _futureElements = null;
73
74
75
76
77 private TermDefinition() {
78 id = null;
79 specification = null;
80 description = null;
81 parameters = null;
82 versionNumber = null;
83 }
84
85 private TermDefinition(Builder builder) {
86 id = builder.getId();
87 specification = builder.getSpecification().build();
88 description = builder.getDescription();
89 parameters = BuilderUtils.convertFromBuilderList(builder.getParameters());
90 versionNumber = builder.getVersionNumber();
91 }
92
93
94
95
96
97
98
99 public static class Builder implements TermDefinitionContract, ModelBuilder, Serializable {
100
101 private static final long serialVersionUID = 1L;
102
103 private String id;
104 private String description;
105 private TermSpecificationDefinition.Builder specification;
106 private List<TermParameterDefinition.Builder> parameters;
107 private Long versionNumber;
108
109 private Builder(String id, TermSpecificationDefinition.Builder termSpecificationDefinition,
110 List<TermParameterDefinition.Builder> termParameters) {
111 setId(id);
112 setSpecification(termSpecificationDefinition);
113 setParameters(termParameters);
114 }
115
116
117
118
119
120
121
122
123 public static Builder create(String id, TermSpecificationDefinition.Builder termSpecification,
124 List<TermParameterDefinition.Builder> termParameters) {
125 return new Builder(id, termSpecification, termParameters);
126 }
127
128
129
130
131
132
133 public static Builder create(TermDefinitionContract term) {
134 if (term == null) throw new IllegalAddException("term may not be null");
135
136
137 List<TermParameterDefinition.Builder> outParams =
138 BuilderUtils.transform(term.getParameters(), TermParameterDefinition.Builder.toBuilder);
139
140 Builder builder = create(term.getId(),
141
142 TermSpecificationDefinition.Builder.create(term.getSpecification()),
143
144 outParams
145 );
146 builder.setDescription(term.getDescription());
147 builder.setVersionNumber(term.getVersionNumber());
148 return builder;
149 }
150
151 public void setDescription(String description) {
152 this.description = description;
153 }
154
155
156
157
158
159
160
161 public void setId(String id) {
162 if (id != null && StringUtils.isBlank(id)) {
163 throw new IllegalArgumentException("id must contain non-whitespace chars");
164 }
165 this.id = id;
166 }
167
168
169
170
171
172 public void setSpecification(TermSpecificationDefinition.Builder termSpecification) {
173 if (termSpecification == null) {
174 throw new IllegalArgumentException("termSpecification must not be null");
175 }
176 this.specification = termSpecification;
177 }
178
179
180
181
182 public void setParameters(List<TermParameterDefinition.Builder> parameters) {
183 this.parameters = parameters;
184 }
185
186
187
188
189 public void setVersionNumber(Long versionNumber){
190 this.versionNumber = versionNumber;
191 }
192
193
194
195
196
197
198 @Override
199 public String getId() {
200 return id;
201 }
202
203
204
205
206 @Override
207 public TermSpecificationDefinition.Builder getSpecification() {
208 return specification;
209 }
210
211 @Override
212 public String getDescription() {
213 return description;
214 }
215
216
217
218
219 @Override
220 public List<TermParameterDefinition.Builder> getParameters() {
221 return parameters;
222 }
223
224
225
226
227 @Override
228 public Long getVersionNumber() {
229 return this.versionNumber;
230 }
231
232
233
234
235
236
237
238 @Override
239 public TermDefinition build() {
240 return new TermDefinition(this);
241 }
242 }
243
244
245
246
247 @Override
248 public String getId() {
249 return this.id;
250 }
251
252
253
254 @Override
255 public TermSpecificationDefinition getSpecification() {
256 return this.specification;
257 }
258
259 @Override
260 public String getDescription() {
261 return description;
262 }
263
264
265
266
267 @Override
268 public List<TermParameterDefinition> getParameters() {
269 return this.parameters;
270 }
271
272
273
274
275 @Override
276 public Long getVersionNumber() {
277 return versionNumber;
278 }
279
280 static class Constants {
281 public static final String ROOT_ELEMENT_NAME = "termDefinition";
282 public static final String TYPE_NAME = "termDefinitionType";
283 }
284
285 static class Elements {
286 public static final String ID = "id";
287 public static final String SPECIFICATION = "specification";
288 public static final String PARAMETERS = "parameters";
289 public static final String DESCRIPTION = "description";
290 }
291
292 public static class Cache {
293 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + TermDefinition.Constants.TYPE_NAME;
294 }
295 }