1 | |
package org.kuali.rice.core.api.uif; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.kuali.rice.core.api.CoreConstants; |
5 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
6 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
7 | |
import org.w3c.dom.Element; |
8 | |
|
9 | |
import javax.xml.bind.annotation.XmlAccessType; |
10 | |
import javax.xml.bind.annotation.XmlAccessorType; |
11 | |
import javax.xml.bind.annotation.XmlAnyElement; |
12 | |
import javax.xml.bind.annotation.XmlElement; |
13 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
14 | |
import javax.xml.bind.annotation.XmlElements; |
15 | |
import javax.xml.bind.annotation.XmlRootElement; |
16 | |
import javax.xml.bind.annotation.XmlType; |
17 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.List; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | @XmlRootElement(name = RemotableAttributeField.Constants.ROOT_ELEMENT_NAME) |
27 | |
@XmlAccessorType(XmlAccessType.NONE) |
28 | |
@XmlType(name = RemotableAttributeField.Constants.TYPE_NAME, propOrder = { |
29 | |
RemotableAttributeField.Elements.NAME, |
30 | |
RemotableAttributeField.Elements.DATA_TYPE, |
31 | |
RemotableAttributeField.Elements.SHORT_LABEL, |
32 | |
RemotableAttributeField.Elements.LONG_LABEL, |
33 | |
RemotableAttributeField.Elements.HELP_SUMMARY, |
34 | |
RemotableAttributeField.Elements.HELP_CONSTRAINT, |
35 | |
RemotableAttributeField.Elements.HELP_DESCRIPTION, |
36 | |
RemotableAttributeField.Elements.FORCE_UPPERCASE, |
37 | |
RemotableAttributeField.Elements.MIN_LENGTH, |
38 | |
RemotableAttributeField.Elements.MAX_LENGTH, |
39 | |
RemotableAttributeField.Elements.MIN_VALUE, |
40 | |
RemotableAttributeField.Elements.MAX_VALUE, |
41 | |
RemotableAttributeField.Elements.REGEX_CONSTRAINT, |
42 | |
RemotableAttributeField.Elements.REGEX_CONSTRAINT_MSG, |
43 | |
RemotableAttributeField.Elements.REQUIRED, |
44 | |
RemotableAttributeField.Elements.DEFAULT_VALUES, |
45 | |
RemotableAttributeField.Elements.CONTROL, |
46 | |
RemotableAttributeField.Elements.WIDGETS, |
47 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS }) |
48 | 6 | public final class RemotableAttributeField extends AbstractDataTransferObject implements AttributeField { |
49 | |
|
50 | |
@XmlElement(name = Elements.NAME, required = true) |
51 | |
private final String name; |
52 | |
|
53 | |
@XmlJavaTypeAdapter(DataType.Adapter.class) |
54 | |
@XmlElement(name = Elements.DATA_TYPE, required = false) |
55 | |
private final String dataType; |
56 | |
|
57 | |
@XmlElement(name = Elements.SHORT_LABEL, required = false) |
58 | |
private final String shortLabel; |
59 | |
|
60 | |
@XmlElement(name = Elements.LONG_LABEL, required = false) |
61 | |
private final String longLabel; |
62 | |
|
63 | |
@XmlElement(name = Elements.HELP_SUMMARY, required = false) |
64 | |
private final String helpSummary; |
65 | |
|
66 | |
@XmlElement(name = Elements.HELP_CONSTRAINT, required = false) |
67 | |
private final String helpConstraint; |
68 | |
|
69 | |
@XmlElement(name = Elements.HELP_DESCRIPTION, required = false) |
70 | |
private final String helpDescription; |
71 | |
|
72 | |
@XmlElement(name = Elements.FORCE_UPPERCASE, required = false) |
73 | |
private final boolean forceUpperCase; |
74 | |
|
75 | |
@XmlElement(name = Elements.MIN_LENGTH, required = false) |
76 | |
private final Integer minLength; |
77 | |
|
78 | |
@XmlElement(name = Elements.MAX_LENGTH, required = false) |
79 | |
private final Integer maxLength; |
80 | |
|
81 | |
@XmlElement(name = Elements.MIN_VALUE, required = false) |
82 | |
private final Integer minValue; |
83 | |
|
84 | |
@XmlElement(name = Elements.MAX_VALUE, required = false) |
85 | |
private final Integer maxValue; |
86 | |
|
87 | |
@XmlElement(name = Elements.REGEX_CONSTRAINT, required = false) |
88 | |
private final String regexConstraint; |
89 | |
|
90 | |
@XmlElement(name = Elements.REGEX_CONSTRAINT_MSG, required = false) |
91 | |
private final String regexContraintMsg; |
92 | |
|
93 | |
@XmlElement(name = Elements.REQUIRED, required = false) |
94 | |
private final boolean required; |
95 | |
|
96 | |
@XmlElementWrapper(name = Elements.DEFAULT_VALUES, required = false) |
97 | |
@XmlElement(name = Elements.DEFAULT_VALUE, required = false) |
98 | |
private final Collection<String> defaultValues; |
99 | |
|
100 | |
@XmlElements(value = { |
101 | |
@XmlElement(name = RemotableCheckboxGroup.Constants.ROOT_ELEMENT_NAME, type = RemotableCheckboxGroup.class, required = false), |
102 | |
@XmlElement(name = RemotableHiddenInput.Constants.ROOT_ELEMENT_NAME, type = RemotableHiddenInput.class, required = false), |
103 | |
@XmlElement(name = RemotablePasswordInput.Constants.ROOT_ELEMENT_NAME, type = RemotablePasswordInput.class, required = false), |
104 | |
@XmlElement(name = RemotableRadioButtonGroup.Constants.ROOT_ELEMENT_NAME, type = RemotableRadioButtonGroup.class, required = false), |
105 | |
@XmlElement(name = RemotableSelect.Constants.ROOT_ELEMENT_NAME, type = RemotableSelect.class, required = false), |
106 | |
@XmlElement(name = RemotableTextarea.Constants.ROOT_ELEMENT_NAME, type = RemotableTextarea.class, required = false), |
107 | |
@XmlElement(name = RemotableTextInput.Constants.ROOT_ELEMENT_NAME, type = RemotableTextInput.class, required = false) |
108 | |
}) |
109 | |
private final RemotableAbstractControl control; |
110 | |
|
111 | |
@XmlElementWrapper(name = Elements.WIDGETS, required = false) |
112 | |
@XmlElements(value = { |
113 | |
@XmlElement(name = RemotableDatepicker.Constants.ROOT_ELEMENT_NAME, type = RemotableDatepicker.class, required = false), |
114 | |
@XmlElement(name = RemotableQuickFinder.Constants.ROOT_ELEMENT_NAME, type = RemotableQuickFinder.class, required = false), |
115 | |
@XmlElement(name = RemotableTextExpand.Constants.ROOT_ELEMENT_NAME, type = RemotableTextExpand.class, required = false) |
116 | |
}) |
117 | |
private final Collection<? extends RemotableAbstractWidget> widgets; |
118 | |
|
119 | 10 | @SuppressWarnings("unused") |
120 | |
@XmlAnyElement |
121 | |
private final Collection<Element> _futureElements = null; |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@SuppressWarnings("unused") |
127 | 4 | private RemotableAttributeField() { |
128 | 4 | this.name = null; |
129 | 4 | this.dataType = null; |
130 | 4 | this.shortLabel = null; |
131 | 4 | this.longLabel = null; |
132 | 4 | this.helpSummary = null; |
133 | 4 | this.helpConstraint = null; |
134 | 4 | this.helpDescription = null; |
135 | 4 | this.forceUpperCase = false; |
136 | 4 | this.minLength = null; |
137 | 4 | this.maxLength = null; |
138 | 4 | this.minValue = null; |
139 | 4 | this.maxValue = null; |
140 | 4 | this.regexConstraint = null; |
141 | 4 | this.regexContraintMsg = null; |
142 | 4 | this.required = false; |
143 | 4 | this.defaultValues = null; |
144 | 4 | this.control = null; |
145 | 4 | this.widgets = null; |
146 | 4 | } |
147 | |
|
148 | 6 | private RemotableAttributeField(Builder b) { |
149 | 6 | this.name = b.name; |
150 | 6 | if (b.dataType == null) { |
151 | 4 | this.dataType = null; |
152 | |
} else { |
153 | 2 | this.dataType = b.dataType.name(); |
154 | |
} |
155 | 6 | this.shortLabel = b.shortLabel; |
156 | 6 | this.longLabel = b.longLabel; |
157 | 6 | this.helpSummary = b.helpSummary; |
158 | 6 | this.helpConstraint = b.helpConstraint; |
159 | 6 | this.helpDescription = b.helpDescription; |
160 | 6 | this.forceUpperCase = b.forceUpperCase; |
161 | 6 | this.minLength = b.minLength; |
162 | 6 | this.maxLength = b.maxLength; |
163 | 6 | this.minValue = b.minValue; |
164 | 6 | this.maxValue = b.maxValue; |
165 | 6 | this.regexConstraint = b.regexConstraint; |
166 | 6 | this.regexContraintMsg = b.regexContraintMsg; |
167 | 6 | this.required = b.required; |
168 | 6 | this.defaultValues = b.defaultValues; |
169 | 6 | if (b.control == null) { |
170 | 4 | this.control = null; |
171 | |
} else { |
172 | 2 | this.control = b.control.build(); |
173 | |
} |
174 | |
|
175 | 6 | final List<RemotableAbstractWidget> temp = new ArrayList<RemotableAbstractWidget>(); |
176 | 6 | if (b.widgets != null) { |
177 | 5 | for (RemotableAbstractWidget.Builder attr : b.widgets) { |
178 | 2 | temp.add(attr.build()); |
179 | |
} |
180 | |
} |
181 | 6 | this.widgets = Collections.unmodifiableList(temp); |
182 | 6 | } |
183 | |
|
184 | |
@Override |
185 | |
public String getName() { |
186 | 0 | return name; |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public DataType getDataType() { |
191 | 0 | if (dataType == null) { |
192 | 0 | return null; |
193 | |
} |
194 | 0 | return DataType.valueOf(dataType); |
195 | |
} |
196 | |
|
197 | |
@Override |
198 | |
public String getShortLabel() { |
199 | 0 | return shortLabel; |
200 | |
} |
201 | |
|
202 | |
@Override |
203 | |
public String getLongLabel() { |
204 | 0 | return longLabel; |
205 | |
} |
206 | |
|
207 | |
@Override |
208 | |
public String getHelpSummary() { |
209 | 0 | return helpSummary; |
210 | |
} |
211 | |
|
212 | |
@Override |
213 | |
public String getHelpConstraint() { |
214 | 0 | return helpConstraint; |
215 | |
} |
216 | |
|
217 | |
@Override |
218 | |
public String getHelpDescription() { |
219 | 0 | return helpDescription; |
220 | |
} |
221 | |
|
222 | |
@Override |
223 | |
public boolean isForceUpperCase() { |
224 | 0 | return forceUpperCase; |
225 | |
} |
226 | |
|
227 | |
@Override |
228 | |
public Integer getMinLength() { |
229 | 0 | return minLength; |
230 | |
} |
231 | |
|
232 | |
@Override |
233 | |
public Integer getMaxLength() { |
234 | 0 | return maxLength; |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public Integer getMinValue() { |
239 | 0 | return minValue; |
240 | |
} |
241 | |
|
242 | |
@Override |
243 | |
public Integer getMaxValue() { |
244 | 0 | return maxValue; |
245 | |
} |
246 | |
|
247 | |
@Override |
248 | |
public String getRegexConstraint() { |
249 | 0 | return regexConstraint; |
250 | |
} |
251 | |
|
252 | |
@Override |
253 | |
public String getRegexContraintMsg() { |
254 | 0 | return regexContraintMsg; |
255 | |
} |
256 | |
|
257 | |
@Override |
258 | |
public boolean isRequired() { |
259 | 0 | return required; |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
public Collection<String> getDefaultValues() { |
264 | 0 | return defaultValues; |
265 | |
} |
266 | |
|
267 | |
@Override |
268 | |
public RemotableAbstractControl getControl() { |
269 | 0 | return control; |
270 | |
} |
271 | |
|
272 | |
@Override |
273 | |
public Collection<? extends RemotableAbstractWidget> getWidgets() { |
274 | 0 | return widgets; |
275 | |
} |
276 | |
|
277 | 123 | public static final class Builder implements AttributeField, ModelBuilder { |
278 | |
private String name; |
279 | |
private DataType dataType; |
280 | |
private String shortLabel; |
281 | |
private String longLabel; |
282 | |
|
283 | |
private String helpSummary; |
284 | |
private String helpConstraint; |
285 | |
private String helpDescription; |
286 | |
|
287 | |
private boolean forceUpperCase; |
288 | |
|
289 | |
private Integer minLength; |
290 | |
private Integer maxLength; |
291 | |
|
292 | |
private Integer minValue; |
293 | |
private Integer maxValue; |
294 | |
|
295 | |
private String regexConstraint; |
296 | |
private String regexContraintMsg; |
297 | |
|
298 | |
private boolean required; |
299 | |
|
300 | 8 | private Collection<String> defaultValues = Collections.emptyList(); |
301 | |
private RemotableAbstractControl.Builder control; |
302 | |
|
303 | 8 | private Collection<RemotableAbstractWidget.Builder> widgets = Collections.emptyList(); |
304 | |
|
305 | 8 | private Builder(String name) { |
306 | 8 | setName(name); |
307 | 6 | } |
308 | |
|
309 | |
public static Builder create(String name) { |
310 | 8 | return new Builder(name); |
311 | |
} |
312 | |
|
313 | |
@Override |
314 | |
public String getName() { |
315 | 0 | return name; |
316 | |
} |
317 | |
|
318 | |
public void setName(String name) { |
319 | 8 | if (StringUtils.isBlank(name)) { |
320 | 2 | throw new IllegalArgumentException("name is blank"); |
321 | |
} |
322 | |
|
323 | 6 | this.name = name; |
324 | 6 | } |
325 | |
|
326 | |
@Override |
327 | |
public DataType getDataType() { |
328 | 0 | return dataType; |
329 | |
} |
330 | |
|
331 | |
public void setDataType(DataType dataType) { |
332 | 3 | this.dataType = dataType; |
333 | 3 | } |
334 | |
|
335 | |
@Override |
336 | |
public String getShortLabel() { |
337 | 0 | return shortLabel; |
338 | |
} |
339 | |
|
340 | |
public void setShortLabel(String shortLabel) { |
341 | 3 | this.shortLabel = shortLabel; |
342 | 3 | } |
343 | |
|
344 | |
@Override |
345 | |
public String getLongLabel() { |
346 | 0 | return longLabel; |
347 | |
} |
348 | |
|
349 | |
public void setLongLabel(String longLabel) { |
350 | 2 | this.longLabel = longLabel; |
351 | 2 | } |
352 | |
|
353 | |
@Override |
354 | |
public String getHelpSummary() { |
355 | 0 | return helpSummary; |
356 | |
} |
357 | |
|
358 | |
public void setHelpSummary(String helpSummary) { |
359 | 3 | this.helpSummary = helpSummary; |
360 | 3 | } |
361 | |
|
362 | |
@Override |
363 | |
public String getHelpConstraint() { |
364 | 0 | return helpConstraint; |
365 | |
} |
366 | |
|
367 | |
public void setHelpConstraint(String helpConstraint) { |
368 | 3 | this.helpConstraint = helpConstraint; |
369 | 3 | } |
370 | |
|
371 | |
@Override |
372 | |
public String getHelpDescription() { |
373 | 0 | return helpDescription; |
374 | |
} |
375 | |
|
376 | |
public void setHelpDescription(String helpDescription) { |
377 | 3 | this.helpDescription = helpDescription; |
378 | 3 | } |
379 | |
|
380 | |
@Override |
381 | |
public boolean isForceUpperCase() { |
382 | 0 | return forceUpperCase; |
383 | |
} |
384 | |
|
385 | |
public void setForceUpperCase(boolean forceUpperCase) { |
386 | 2 | this.forceUpperCase = forceUpperCase; |
387 | 2 | } |
388 | |
|
389 | |
@Override |
390 | |
public Integer getMinLength() { |
391 | 0 | return minLength; |
392 | |
} |
393 | |
|
394 | |
public void setMinLength(Integer minLength) { |
395 | 3 | if (minLength != null && minLength < 1) { |
396 | 0 | throw new IllegalArgumentException("minLength was < 1"); |
397 | |
} |
398 | |
|
399 | 3 | this.minLength = minLength; |
400 | 3 | } |
401 | |
|
402 | |
@Override |
403 | |
public Integer getMaxLength() { |
404 | 0 | return maxLength; |
405 | |
} |
406 | |
|
407 | |
public void setMaxLength(Integer maxLength) { |
408 | 3 | if (maxLength != null && maxLength < 1) { |
409 | 0 | throw new IllegalArgumentException("maxLength was < 1"); |
410 | |
} |
411 | |
|
412 | 3 | this.maxLength = maxLength; |
413 | 3 | } |
414 | |
|
415 | |
@Override |
416 | |
public Integer getMinValue() { |
417 | 0 | return minValue; |
418 | |
} |
419 | |
|
420 | |
public void setMinValue(Integer minValue) { |
421 | 3 | this.minValue = minValue; |
422 | 3 | } |
423 | |
|
424 | |
@Override |
425 | |
public Integer getMaxValue() { |
426 | 0 | return maxValue; |
427 | |
} |
428 | |
|
429 | |
public void setMaxValue(Integer maxValue) { |
430 | 3 | this.maxValue = maxValue; |
431 | 3 | } |
432 | |
|
433 | |
@Override |
434 | |
public String getRegexConstraint() { |
435 | 0 | return regexConstraint; |
436 | |
} |
437 | |
|
438 | |
public void setRegexConstraint(String regexConstraint) { |
439 | 3 | this.regexConstraint = regexConstraint; |
440 | 3 | } |
441 | |
|
442 | |
@Override |
443 | |
public String getRegexContraintMsg() { |
444 | 0 | return regexContraintMsg; |
445 | |
} |
446 | |
|
447 | |
public void setRegexContraintMsg(String regexContraintMsg) { |
448 | 3 | this.regexContraintMsg = regexContraintMsg; |
449 | 3 | } |
450 | |
|
451 | |
@Override |
452 | |
public boolean isRequired() { |
453 | 0 | return required; |
454 | |
} |
455 | |
|
456 | |
public void setRequired(boolean required) { |
457 | 2 | this.required = required; |
458 | 2 | } |
459 | |
|
460 | |
@Override |
461 | |
public Collection<String> getDefaultValues() { |
462 | 0 | return defaultValues; |
463 | |
} |
464 | |
|
465 | |
public void setDefaultValues(Collection<String> defaultValues) { |
466 | 4 | this.defaultValues = defaultValues; |
467 | 4 | } |
468 | |
|
469 | |
@Override |
470 | |
public RemotableAbstractControl.Builder getControl() { |
471 | 0 | return control; |
472 | |
} |
473 | |
|
474 | |
public void setControl(RemotableAbstractControl.Builder control) { |
475 | 3 | this.control = control; |
476 | 3 | } |
477 | |
|
478 | |
@Override |
479 | |
public Collection<RemotableAbstractWidget.Builder> getWidgets() { |
480 | 0 | return widgets; |
481 | |
} |
482 | |
|
483 | |
public void setWidgets(Collection<RemotableAbstractWidget.Builder> widgets) { |
484 | 4 | this.widgets = widgets; |
485 | 4 | } |
486 | |
|
487 | |
@Override |
488 | |
public RemotableAttributeField build() { |
489 | 6 | return new RemotableAttributeField(this); |
490 | |
} |
491 | |
} |
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | 0 | static final class Constants { |
497 | |
static final String TYPE_NAME = "AttributeFieldType"; |
498 | |
final static String ROOT_ELEMENT_NAME = "attributeField"; |
499 | |
} |
500 | |
|
501 | 0 | static final class Elements { |
502 | |
static final String NAME = "name"; |
503 | |
static final String DATA_TYPE = "dataType"; |
504 | |
static final String SHORT_LABEL = "shortLabel"; |
505 | |
static final String LONG_LABEL = "longLabel"; |
506 | |
static final String HELP_SUMMARY = "helpSummary"; |
507 | |
static final String HELP_CONSTRAINT = "helpConstraint"; |
508 | |
static final String HELP_DESCRIPTION = "helpDescription"; |
509 | |
static final String FORCE_UPPERCASE = "forceUpperCase"; |
510 | |
static final String MIN_LENGTH = "minLength"; |
511 | |
static final String MAX_LENGTH = "maxLength"; |
512 | |
static final String MIN_VALUE = "minValue"; |
513 | |
static final String MAX_VALUE = "maxValue"; |
514 | |
static final String REGEX_CONSTRAINT = "regexConstraint"; |
515 | |
static final String REGEX_CONSTRAINT_MSG = "regexContraintMsg"; |
516 | |
static final String REQUIRED = "required"; |
517 | |
static final String DEFAULT_VALUES = "defaultValues"; |
518 | |
static final String DEFAULT_VALUE = "defaultValue"; |
519 | |
static final String CONTROL = "control"; |
520 | |
static final String WIDGETS = "widgets"; |
521 | |
} |
522 | |
} |