1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.validator.old; |
17 |
|
|
18 |
|
import java.beans.BeanInfo; |
19 |
|
import java.beans.IntrospectionException; |
20 |
|
import java.beans.Introspector; |
21 |
|
import java.beans.PropertyDescriptor; |
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 11 |
Complexity Density: 0.52 |
|
25 |
|
public class BeanConstraintDataProvider implements ConstraintDataProvider { |
26 |
|
|
27 |
|
Map<String, Object> dataMap = null; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
33 |
0
|
protected BeanConstraintDataProvider() {... |
34 |
|
|
35 |
|
} |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
0
|
public String getPath(){... |
38 |
0
|
return ""; |
39 |
|
} |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
40 |
0
|
@Override... |
41 |
|
public void initialize(Object o) { |
42 |
|
|
43 |
0
|
dataMap = new HashMap<String, Object>(); |
44 |
|
|
45 |
0
|
Map<String, PropertyDescriptor> beanInfo = getBeanInfo(o.getClass()); |
46 |
|
|
47 |
0
|
for (String propName : beanInfo.keySet()) { |
48 |
0
|
PropertyDescriptor pd = beanInfo.get(propName); |
49 |
0
|
Object value = null; |
50 |
0
|
try { |
51 |
0
|
value = pd.getReadMethod().invoke(o); |
52 |
|
} catch (Exception e) { |
53 |
|
|
54 |
|
} |
55 |
|
|
56 |
0
|
dataMap.put(propName, value); |
57 |
|
} |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
60 |
0
|
@Override... |
61 |
|
public String getObjectId() { |
62 |
0
|
return (dataMap.containsKey("id") && null != dataMap.get("id")) ? dataMap.get("id").toString() : null; |
63 |
|
} |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
0
|
@Override... |
66 |
|
public Object getValue(String fieldKey) { |
67 |
0
|
return dataMap.get(fieldKey); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0
|
@Override... |
71 |
|
public Boolean hasField(String fieldKey) { |
72 |
0
|
return dataMap.containsKey(fieldKey); |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
75 |
0
|
private Map<String, PropertyDescriptor> getBeanInfo(Class<?> clazz) {... |
76 |
0
|
Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>(); |
77 |
0
|
BeanInfo beanInfo = null; |
78 |
0
|
try { |
79 |
0
|
beanInfo = Introspector.getBeanInfo(clazz); |
80 |
|
} catch (IntrospectionException e) { |
81 |
0
|
throw new RuntimeException(e); |
82 |
|
} |
83 |
0
|
PropertyDescriptor[] propertyDescriptors = beanInfo |
84 |
|
.getPropertyDescriptors(); |
85 |
0
|
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { |
86 |
0
|
properties.put(propertyDescriptor.getName(), propertyDescriptor); |
87 |
|
} |
88 |
0
|
return properties; |
89 |
|
} |
90 |
|
} |