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