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