1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.datadictionary;
18
19 import org.apache.commons.lang.ClassUtils;
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.log4j.Logger;
22 import org.kuali.rice.core.api.uif.DataType;
23 import org.kuali.rice.core.api.util.ClassLoaderUtils;
24 import org.kuali.rice.core.web.format.Formatter;
25 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
26 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
27 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
28 import org.kuali.rice.krad.datadictionary.validation.ValidationPattern;
29 import org.kuali.rice.krad.datadictionary.validation.capability.CaseConstrainable;
30 import org.kuali.rice.krad.datadictionary.validation.capability.Formatable;
31 import org.kuali.rice.krad.datadictionary.validation.capability.HierarchicallyConstrainable;
32 import org.kuali.rice.krad.datadictionary.validation.capability.LengthConstrainable;
33 import org.kuali.rice.krad.datadictionary.validation.capability.MustOccurConstrainable;
34 import org.kuali.rice.krad.datadictionary.validation.capability.PrerequisiteConstrainable;
35 import org.kuali.rice.krad.datadictionary.validation.capability.RangeConstrainable;
36 import org.kuali.rice.krad.datadictionary.validation.capability.ValidCharactersConstrainable;
37 import org.kuali.rice.krad.datadictionary.validation.constraint.CaseConstraint;
38 import org.kuali.rice.krad.datadictionary.validation.constraint.LookupConstraint;
39 import org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint;
40 import org.kuali.rice.krad.datadictionary.validation.constraint.PrerequisiteConstraint;
41 import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint;
42 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
43 import org.kuali.rice.krad.uif.control.Control;
44 import org.kuali.rice.krad.util.ObjectUtils;
45
46 import java.util.List;
47
48
49
50
51
52
53
54
55 public class AttributeDefinition extends AttributeDefinitionBase implements CaseConstrainable, PrerequisiteConstrainable, Formatable, HierarchicallyConstrainable, MustOccurConstrainable, LengthConstrainable, RangeConstrainable, ValidCharactersConstrainable {
56 private static final long serialVersionUID = -2490613377818442742L;
57
58 protected Boolean forceUppercase = Boolean.FALSE;
59
60 protected DataType dataType;
61
62 protected Integer minLength;
63 protected Integer maxLength;
64 protected Boolean unique;
65
66 protected String exclusiveMin;
67 protected String inclusiveMax;
68
69 @Deprecated
70 protected ValidationPattern validationPattern;
71
72 protected ControlDefinition control;
73
74
75 protected Control controlField;
76
77 protected String formatterClass;
78
79 protected AttributeSecurity attributeSecurity;
80
81 protected Boolean dynamic;
82
83
84 protected String customValidatorClass;
85 protected ValidCharactersConstraint validCharactersConstraint;
86 protected CaseConstraint caseConstraint;
87 protected List<PrerequisiteConstraint> dependencyConstraints;
88 protected List<MustOccurConstraint> mustOccurConstraints;
89 protected LookupConstraint lookupDefinition;
90
91 protected String lookupContextPath;
92
93
94 protected String childEntryName;
95
96 private KeyValuesFinder optionsFinder;
97
98 protected String alternateDisplayAttributeName;
99 protected String additionalDisplayAttributeName;
100
101
102 public AttributeDefinition() {
103
104 }
105
106
107
108
109
110 public void setForceUppercase(Boolean forceUppercase) {
111 this.forceUppercase = forceUppercase;
112 }
113
114 public Boolean getForceUppercase() {
115 return this.forceUppercase;
116 }
117
118 @Override
119 public Integer getMaxLength() {
120 return maxLength;
121 }
122
123
124
125
126
127 public void setMaxLength(Integer maxLength) {
128 this.maxLength = maxLength;
129 }
130
131 @Override
132 public String getExclusiveMin() {
133 return exclusiveMin;
134 }
135
136
137
138
139
140
141 public void setExclusiveMin(String exclusiveMin) {
142 this.exclusiveMin = exclusiveMin;
143 }
144
145
146
147
148
149
150
151
152 @Override
153 public String getInclusiveMax() {
154 return inclusiveMax;
155 }
156
157
158
159
160
161
162
163
164 public void setInclusiveMax(String inclusiveMax) {
165 this.inclusiveMax = inclusiveMax;
166 }
167
168
169
170
171 public boolean hasValidationPattern() {
172 return (validationPattern != null);
173 }
174
175 public ValidationPattern getValidationPattern() {
176 return this.validationPattern;
177 }
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216 public void setValidationPattern(ValidationPattern validationPattern) {
217 this.validationPattern = validationPattern;
218
219
220 }
221
222
223
224
225
226 public ControlDefinition getControl() {
227 return control;
228 }
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270 public void setControl(ControlDefinition control) {
271 if (control == null) {
272 throw new IllegalArgumentException("invalid (null) control");
273 }
274 this.control = control;
275 }
276
277 public boolean hasFormatterClass() {
278 return (formatterClass != null);
279 }
280
281 @Override
282 public String getFormatterClass() {
283 return formatterClass;
284 }
285
286
287
288
289
290
291
292
293 public void setFormatterClass(String formatterClass) {
294 if (formatterClass == null) {
295 throw new IllegalArgumentException("invalid (null) formatterClass");
296 }
297 this.formatterClass = formatterClass;
298 }
299
300
301
302
303
304
305
306 @Override
307 public void completeValidation(Class<?> rootObjectClass, Class<?> otherObjectClass) {
308 try {
309 if (!DataDictionary.isPropertyOf(rootObjectClass, getName())) {
310 throw new AttributeValidationException("property '" + getName() + "' is not a property of class '"
311 + rootObjectClass.getName() + "' (" + "" + ")");
312 }
313
314
315 if (getControl() == null && getControlField() == null) {
316 throw new AttributeValidationException("property '" + getName() + "' in class '"
317 + rootObjectClass.getName() + " does not have a control defined");
318 }
319
320 if(getControl() != null) {
321 getControl().completeValidation(rootObjectClass, otherObjectClass);
322 }
323
324 if (attributeSecurity != null) {
325 attributeSecurity.completeValidation(rootObjectClass, otherObjectClass);
326 }
327
328 if (validationPattern != null) {
329 validationPattern.completeValidation();
330 }
331
332 if (formatterClass != null) {
333 try {
334 Class formatterClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(),
335 getFormatterClass());
336 if (!Formatter.class.isAssignableFrom(formatterClassObject)) {
337 throw new ClassValidationException("formatterClass is not a valid instance of "
338 + Formatter.class.getName() + " instead was: " + formatterClassObject.getName());
339 }
340 }
341 catch (ClassNotFoundException e) {
342 throw new ClassValidationException("formatterClass could not be found: " + getFormatterClass(), e);
343 }
344 }
345 }
346 catch (RuntimeException ex) {
347 Logger.getLogger(getClass()).error(
348 "Unable to validate attribute " + rootObjectClass + "." + getName() + ": " + ex.getMessage(), ex);
349 throw ex;
350 }
351 }
352
353
354
355
356 @Override
357 public String toString() {
358 return "AttributeDefinition for attribute " + getName();
359 }
360
361
362
363
364 public AttributeSecurity getAttributeSecurity() {
365 return this.attributeSecurity;
366 }
367
368
369
370
371
372 public void setAttributeSecurity(AttributeSecurity attributeSecurity) {
373 this.attributeSecurity = attributeSecurity;
374 }
375
376 public boolean hasAttributeSecurity() {
377 return (attributeSecurity != null);
378 }
379
380
381
382
383
384
385 @Override
386 public void afterPropertiesSet() throws Exception {
387 if (StringUtils.isEmpty(name)) {
388 throw new RuntimeException("blank name for bean: " + id);
389 }
390 }
391
392
393
394
395 public Boolean getUnique() {
396 return this.unique;
397 }
398
399
400
401
402
403 public void setUnique(Boolean unique) {
404 this.unique = unique;
405 }
406
407
408
409
410
411
412
413
414 public Control getControlField() {
415 return this.controlField;
416 }
417
418
419
420
421
422
423 public void setControlField(Control controlField) {
424 this.controlField = controlField;
425 }
426
427
428
429
430 public Integer getMinLength() {
431 return this.minLength;
432 }
433
434
435
436
437 public void setMinLength(Integer minLength) {
438 this.minLength = minLength;
439 }
440
441
442
443
444 @Override
445 public DataType getDataType() {
446 return this.dataType;
447 }
448
449
450
451
452 public void setDataType(DataType dataType) {
453 this.dataType = dataType;
454 }
455
456 public void setDataType(String dataType) {
457 this.dataType = DataType.valueOf(dataType);
458 }
459
460
461
462
463 public String getCustomValidatorClass() {
464 return this.customValidatorClass;
465 }
466
467
468
469
470 public void setCustomValidatorClass(String customValidatorClass) {
471 this.customValidatorClass = customValidatorClass;
472 }
473
474
475
476
477 @Override
478 public ValidCharactersConstraint getValidCharactersConstraint() {
479 return this.validCharactersConstraint;
480 }
481
482
483
484
485 public void setValidCharactersConstraint(ValidCharactersConstraint validCharactersConstraint) {
486 this.validCharactersConstraint = validCharactersConstraint;
487 }
488
489
490
491
492 @Override
493 public CaseConstraint getCaseConstraint() {
494 return this.caseConstraint;
495 }
496
497
498
499
500 public void setCaseConstraint(CaseConstraint caseConstraint) {
501 this.caseConstraint = caseConstraint;
502 }
503
504
505
506
507 @Override
508 public List<PrerequisiteConstraint> getPrerequisiteConstraints() {
509 return this.dependencyConstraints;
510 }
511
512
513
514
515 public void setPrerequisiteConstraints(List<PrerequisiteConstraint> dependencyConstraints) {
516 this.dependencyConstraints = dependencyConstraints;
517 }
518
519
520
521
522 @Override
523 public List<MustOccurConstraint> getMustOccurConstraints() {
524 return this.mustOccurConstraints;
525 }
526
527
528
529
530 public void setMustOccurConstraints(List<MustOccurConstraint> mustOccurConstraints) {
531 this.mustOccurConstraints = mustOccurConstraints;
532 }
533
534
535
536
537 public LookupConstraint getLookupDefinition() {
538 return this.lookupDefinition;
539 }
540
541
542
543
544 public void setLookupDefinition(LookupConstraint lookupDefinition) {
545 this.lookupDefinition = lookupDefinition;
546 }
547
548
549
550
551 public String getLookupContextPath() {
552 return this.lookupContextPath;
553 }
554
555
556
557
558 public void setLookupContextPath(String lookupContextPath) {
559 this.lookupContextPath = lookupContextPath;
560 }
561
562
563
564
565 public String getChildEntryName() {
566 return this.childEntryName;
567 }
568
569
570
571
572 public void setChildEntryName(String childEntryName) {
573 this.childEntryName = childEntryName;
574 }
575
576
577
578
579 public String getConstraint() {
580 return this.constraint;
581 }
582
583
584
585
586 public void setConstraint(String constraint) {
587 this.constraint = constraint;
588 }
589
590
591
592
593
594
595
596
597
598 public KeyValuesFinder getOptionsFinder() {
599 return this.optionsFinder;
600 }
601
602
603
604
605
606
607 public void setOptionsFinder(KeyValuesFinder optionsFinder) {
608 this.optionsFinder = optionsFinder;
609 }
610
611
612
613
614
615
616
617 public void setOptionsFinderClass(Class<? extends KeyValuesFinder> optionsFinderClass) {
618 this.optionsFinder = ObjectUtils.newInstance(optionsFinderClass);
619 }
620
621 public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) {
622 this.additionalDisplayAttributeName = additionalDisplayAttributeName;
623 }
624
625 public String getAdditionalDisplayAttributeName() {
626 return this.additionalDisplayAttributeName;
627 }
628
629 public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) {
630 this.alternateDisplayAttributeName = alternateDisplayAttributeName;
631 }
632
633 public String getAlternateDisplayAttributeName() {
634 return this.alternateDisplayAttributeName;
635 }
636
637 }