1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.util.List;
20
21 import org.apache.commons.beanutils.PropertyUtils;
22 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23 import org.kuali.rice.core.web.format.FormatException;
24 import org.kuali.rice.krad.util.ObjectUtils;
25
26
27
28
29 public abstract class ParameterizedValidation {
30 private List<ValidationFieldConvertible> parameterProperties;
31
32
33
34
35
36 protected List<ValidationFieldConvertible> getParameterProperties() {
37 return parameterProperties;
38 }
39
40
41
42
43
44 public void setParameterProperties(List<ValidationFieldConvertible> parameterProperties) {
45 this.parameterProperties = parameterProperties;
46 }
47
48
49
50
51
52
53 public void populateParametersFromEvent(AttributedDocumentEvent event) {
54 if (getParameterProperties() != null) {
55 for (ValidationFieldConvertible property: getParameterProperties()) {
56 populateParameterFromEvent(event, property);
57 }
58 }
59 }
60
61
62
63
64
65
66
67 protected void populateParameterFromEvent(AttributedDocumentEvent event, ValidationFieldConvertible conversion) {
68 try {
69 Class propertyClass = PropertyUtils.getPropertyType(event, conversion.getSourceEventProperty());
70 Object propertyValue = ObjectUtils.getPropertyValue(event, conversion.getSourceEventProperty());
71 if (propertyValue != null) {
72 ObjectUtils.setObjectProperty(this, conversion.getTargetValidationProperty(), propertyClass, propertyValue);
73 }
74 }
75 catch (FormatException fe) {
76 throw new RuntimeException(fe);
77 }
78 catch (IllegalAccessException iae) {
79 throw new RuntimeException(iae);
80 }
81 catch (InvocationTargetException ite) {
82 throw new RuntimeException(ite);
83 }
84 catch (NoSuchMethodException nsme) {
85 throw new RuntimeException(nsme);
86 }
87 }
88 }