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