1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation;
17
18 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
19 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20 import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
21 import org.kuali.rice.krad.datadictionary.validation.constraint.DataTypeConstraint;
22
23 import java.util.List;
24
25
26
27
28
29
30
31
32
33
34
35
36 public class SingleAttributeValueReader extends BaseAttributeValueReader {
37
38 private Object value;
39 private AttributeDefinition definition;
40
41 public SingleAttributeValueReader(Object value, String entryName, String attributeName, AttributeDefinition definition) {
42 this.value = value;
43 this.entryName = entryName;
44 this.attributeName = attributeName;
45 this.definition = definition;
46 }
47
48 @Override
49 public Constrainable getDefinition(String attributeName) {
50
51 return definition != null && definition.getName() != null && definition.getName().equals(attributeName) ? definition : null;
52 }
53
54 @Override
55 public List<Constrainable> getDefinitions() {
56 return null;
57 }
58
59
60
61
62 @Override
63 public Constrainable getEntry() {
64 return null;
65 }
66
67 @Override
68 public String getLabel(String attributeName) {
69 if (definition != null && definition.getName() != null && definition.getName().equals(attributeName))
70 return definition.getLabel();
71
72 return attributeName;
73 }
74
75 @Override
76 public Object getObject() {
77 return null;
78 }
79
80 @Override
81 public String getPath() {
82 return attributeName;
83 }
84
85 @Override
86 public Class<?> getType(String selectedAttributeName) {
87 Constrainable attributeDefinition = getDefinition(selectedAttributeName);
88
89 if (attributeDefinition != null && attributeDefinition instanceof DataTypeConstraint) {
90 DataTypeConstraint dataTypeConstraint = (DataTypeConstraint)attributeDefinition;
91 if (dataTypeConstraint.getDataType() != null)
92 return dataTypeConstraint.getDataType().getType();
93 }
94
95
96 return value != null ? value.getClass() : null;
97 }
98
99 @Override
100 public <X> X getValue() throws AttributeValidationException {
101 return (X) value;
102 }
103
104 @Override
105 public <X> X getValue(String attributeName) throws AttributeValidationException {
106 Constrainable attributeDefinition = getDefinition(attributeName);
107
108 if (attributeDefinition != null)
109 return (X) value;
110
111 return null;
112 }
113
114 }