1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.api.repository.context; |
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.agenda.AgendaDefinition; |
24 | |
import org.kuali.rice.krms.api.repository.agenda.AgendaDefinitionContract; |
25 | |
|
26 | |
import javax.xml.bind.annotation.XmlAccessType; |
27 | |
import javax.xml.bind.annotation.XmlAccessorType; |
28 | |
import javax.xml.bind.annotation.XmlAnyElement; |
29 | |
import javax.xml.bind.annotation.XmlElement; |
30 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
31 | |
import javax.xml.bind.annotation.XmlRootElement; |
32 | |
import javax.xml.bind.annotation.XmlType; |
33 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
34 | |
import java.io.Serializable; |
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collection; |
37 | |
import java.util.Collections; |
38 | |
import java.util.HashMap; |
39 | |
import java.util.List; |
40 | |
import java.util.Map; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@XmlRootElement(name = ContextDefinition.Constants.ROOT_ELEMENT_NAME) |
55 | |
@XmlAccessorType(XmlAccessType.NONE) |
56 | |
@XmlType(name = ContextDefinition.Constants.TYPE_NAME, propOrder = { |
57 | |
ContextDefinition.Elements.ID, |
58 | |
ContextDefinition.Elements.NAMESPACE, |
59 | |
ContextDefinition.Elements.NAME, |
60 | |
ContextDefinition.Elements.TYPE_ID, |
61 | |
ContextDefinition.Elements.DESCRIPTION, |
62 | |
ContextDefinition.Elements.AGENDAS, |
63 | |
ContextDefinition.Elements.ATTRIBUTES, |
64 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
65 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
66 | |
}) |
67 | 0 | public final class ContextDefinition extends AbstractDataTransferObject implements ContextDefinitionContract { |
68 | |
|
69 | |
private static final long serialVersionUID = -6639428234851623868L; |
70 | |
|
71 | |
@XmlElement(name = Elements.ID, required = false) |
72 | |
private final String id; |
73 | |
|
74 | |
@XmlElement(name = Elements.NAME, required = true) |
75 | |
private final String name; |
76 | |
|
77 | |
@XmlElement(name = Elements.NAMESPACE, required = true) |
78 | |
private final String namespace; |
79 | |
|
80 | |
@XmlElement(name = Elements.TYPE_ID, required = false) |
81 | |
private final String typeId; |
82 | |
|
83 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
84 | |
private final String description; |
85 | |
|
86 | |
@XmlElementWrapper(name = Elements.AGENDAS) |
87 | |
@XmlElement(name = Elements.AGENDA, required = false) |
88 | |
private final List<AgendaDefinition> agendas; |
89 | |
|
90 | |
@XmlElement(name = Elements.ATTRIBUTES, required = false) |
91 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
92 | |
private final Map<String, String> attributes; |
93 | |
|
94 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
95 | |
private final Long versionNumber; |
96 | |
|
97 | 0 | @SuppressWarnings("unused") |
98 | |
@XmlAnyElement |
99 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | 0 | private ContextDefinition() { |
105 | 0 | this.id = null; |
106 | 0 | this.name = null; |
107 | 0 | this.namespace = null; |
108 | 0 | this.typeId = null; |
109 | 0 | this.description = null; |
110 | 0 | this.agendas = null; |
111 | 0 | this.versionNumber = null; |
112 | 0 | this.attributes = null; |
113 | 0 | } |
114 | |
|
115 | 0 | private ContextDefinition(Builder builder) { |
116 | 0 | this.id = builder.getId(); |
117 | 0 | this.name = builder.getName(); |
118 | 0 | this.namespace = builder.getNamespace(); |
119 | |
|
120 | 0 | this.description = builder.getDescription(); |
121 | |
|
122 | 0 | this.typeId = builder.getTypeId(); |
123 | 0 | this.agendas = constructAgendas(builder.getAgendas()); |
124 | 0 | this.versionNumber = builder.getVersionNumber(); |
125 | 0 | if (builder.getAttributes() != null){ |
126 | 0 | this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(builder.getAttributes())); |
127 | |
} else { |
128 | 0 | this.attributes = null; |
129 | |
} |
130 | 0 | } |
131 | |
|
132 | |
private static List<AgendaDefinition> constructAgendas(List<AgendaDefinition.Builder> agendaBuilders) { |
133 | 0 | List<AgendaDefinition> agendas = new ArrayList<AgendaDefinition>(); |
134 | 0 | if (agendaBuilders != null) { |
135 | 0 | for (AgendaDefinition.Builder agendaBuilder : agendaBuilders) { |
136 | 0 | agendas.add(agendaBuilder.build()); |
137 | |
} |
138 | |
} |
139 | 0 | return agendas; |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
public String getId() { |
144 | 0 | return id; |
145 | |
} |
146 | |
|
147 | |
@Override |
148 | |
public String getNamespace() { |
149 | 0 | return namespace; |
150 | |
} |
151 | |
|
152 | |
@Override |
153 | |
public String getName() { |
154 | 0 | return name; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public String getTypeId() { |
159 | 0 | return typeId; |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public String getDescription() { |
164 | 0 | return description; |
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
public List<AgendaDefinition> getAgendas() { |
169 | 0 | return Collections.unmodifiableList(this.agendas); |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public Map<String, String> getAttributes() { |
174 | 0 | return this.attributes; |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public Long getVersionNumber() { |
179 | 0 | return versionNumber; |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | 0 | public static final class Builder implements ContextDefinitionContract, ModelBuilder, Serializable { |
191 | |
|
192 | |
private static final long serialVersionUID = -219369603932108436L; |
193 | |
|
194 | |
private String id; |
195 | |
private String namespace; |
196 | |
private String name; |
197 | |
private String typeId; |
198 | |
private String description; |
199 | |
private List<AgendaDefinition.Builder> agendas; |
200 | |
private Map<String, String> attributes; |
201 | |
private Long versionNumber; |
202 | |
|
203 | 0 | private Builder(String namespace, String name) { |
204 | 0 | setNamespace(namespace); |
205 | 0 | setName(name); |
206 | 0 | setAgendas(new ArrayList<AgendaDefinition.Builder>()); |
207 | 0 | setAttributes(new HashMap<String, String>()); |
208 | 0 | } |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public static Builder create(String namespace, String name) { |
222 | 0 | return new Builder(namespace, name); |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public static Builder create(ContextDefinitionContract contract) { |
237 | 0 | if (contract == null) { |
238 | 0 | throw new IllegalArgumentException("contract was null"); |
239 | |
} |
240 | 0 | Builder builder = create(contract.getNamespace(), contract.getName()); |
241 | 0 | builder.setId(contract.getId()); |
242 | 0 | builder.setTypeId(contract.getTypeId()); |
243 | 0 | builder.setDescription(contract.getDescription()); |
244 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
245 | 0 | builder.setAgendas(contract.getAgendas()); |
246 | 0 | if (contract.getAttributes() != null) { |
247 | 0 | builder.setAttributes(new HashMap<String, String>(contract.getAttributes())); |
248 | |
} |
249 | 0 | return builder; |
250 | |
} |
251 | |
|
252 | |
@Override |
253 | |
public ContextDefinition build() { |
254 | 0 | return new ContextDefinition(this); |
255 | |
} |
256 | |
|
257 | |
@Override |
258 | |
public Long getVersionNumber() { |
259 | 0 | return this.versionNumber; |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
public String getId() { |
264 | 0 | return this.id; |
265 | |
} |
266 | |
|
267 | |
@Override |
268 | |
public String getNamespace() { |
269 | 0 | return this.namespace; |
270 | |
} |
271 | |
|
272 | |
@Override |
273 | |
public String getName() { |
274 | 0 | return this.name; |
275 | |
} |
276 | |
|
277 | |
@Override |
278 | |
public String getTypeId() { |
279 | 0 | return this.typeId; |
280 | |
} |
281 | |
|
282 | |
@Override |
283 | |
public String getDescription() { |
284 | 0 | return description; |
285 | |
} |
286 | |
|
287 | |
@Override |
288 | |
public List<AgendaDefinition.Builder> getAgendas() { |
289 | 0 | return agendas; |
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public Map<String, String> getAttributes() { |
294 | 0 | return attributes; |
295 | |
} |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
public void setId(String id) { |
303 | 0 | if (id != null){ |
304 | 0 | if (StringUtils.isBlank(id)){ |
305 | 0 | throw new IllegalArgumentException("context id is blank"); |
306 | |
} |
307 | |
} |
308 | 0 | this.id = id; |
309 | 0 | } |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
public void setNamespace(String namespace) { |
321 | 0 | if (StringUtils.isBlank(namespace)) { |
322 | 0 | throw new IllegalArgumentException("namespace is blank"); |
323 | |
} |
324 | 0 | this.namespace = namespace; |
325 | 0 | } |
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
public void setName(String name) { |
337 | 0 | if (StringUtils.isBlank(name)) { |
338 | 0 | throw new IllegalArgumentException("name is blank"); |
339 | |
} |
340 | 0 | this.name = name; |
341 | 0 | } |
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
public void setTypeId(String typeId) { |
349 | 0 | this.typeId = typeId; |
350 | 0 | } |
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
public void setDescription(String description) { |
358 | 0 | this.description = description; |
359 | 0 | } |
360 | |
|
361 | |
public void setAgendas(List<? extends AgendaDefinitionContract> agendaContracts) { |
362 | 0 | this.agendas = new ArrayList<AgendaDefinition.Builder>(); |
363 | 0 | if (agendaContracts != null) for (AgendaDefinitionContract agendaContract : agendaContracts) { |
364 | 0 | this.agendas.add(AgendaDefinition.Builder.create(agendaContract)); |
365 | |
} |
366 | 0 | } |
367 | |
|
368 | |
public void setAttributes(Map<String, String> attributes){ |
369 | 0 | if (attributes == null){ |
370 | 0 | this.attributes = Collections.emptyMap(); |
371 | |
} |
372 | 0 | this.attributes = Collections.unmodifiableMap(attributes); |
373 | 0 | } |
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
public void setVersionNumber(Long versionNumber) { |
386 | 0 | this.versionNumber = versionNumber; |
387 | 0 | } |
388 | |
|
389 | |
} |
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | 0 | public static class Constants { |
395 | |
final static String ROOT_ELEMENT_NAME = "context"; |
396 | |
final static String TYPE_NAME = "ContextDefinitionType"; |
397 | |
} |
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | 0 | public static class Elements { |
404 | |
final static String ID = "id"; |
405 | |
final static String NAMESPACE = "namespace"; |
406 | |
final static String NAME = "name"; |
407 | |
final static String TYPE_ID = "typeId"; |
408 | |
final static String DESCRIPTION = "description"; |
409 | |
final static String AGENDA = "agenda"; |
410 | |
final static String AGENDAS = "agendas"; |
411 | |
final static String ATTRIBUTES = "attributes"; |
412 | |
} |
413 | |
|
414 | |
|
415 | |
|
416 | |
} |