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