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 public class SingleAttributeValueReader extends BaseAttributeValueReader {
36
37 private Object value;
38 private AttributeDefinition definition;
39
40 public SingleAttributeValueReader(Object value, String entryName, String attributeName,
41 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) ?
52 definition : null;
53 }
54
55 @Override
56 public List<Constrainable> getDefinitions() {
57 return null;
58 }
59
60
61
62
63 @Override
64 public Constrainable getEntry() {
65 return null;
66 }
67
68 @Override
69 public String getLabel(String attributeName) {
70 if (definition != null && definition.getName() != null && definition.getName().equals(attributeName)) {
71 return definition.getLabel();
72 }
73
74 return attributeName;
75 }
76
77 @Override
78 public Object getObject() {
79 return null;
80 }
81
82 @Override
83 public String getPath() {
84 return attributeName;
85 }
86
87 @Override
88 public Class<?> getType(String selectedAttributeName) {
89 Constrainable attributeDefinition = getDefinition(selectedAttributeName);
90
91 if (attributeDefinition != null && attributeDefinition instanceof DataTypeConstraint) {
92 DataTypeConstraint dataTypeConstraint = (DataTypeConstraint) attributeDefinition;
93 if (dataTypeConstraint.getDataType() != null) {
94 return dataTypeConstraint.getDataType().getType();
95 }
96 }
97
98
99 return value != null ? value.getClass() : null;
100 }
101
102 @Override
103 public boolean isReadable() {
104 return true;
105 }
106
107 @Override
108 public <X> X getValue() throws AttributeValidationException {
109 return (X) value;
110 }
111
112 @Override
113 public <X> X getValue(String attributeName) throws AttributeValidationException {
114 Constrainable attributeDefinition = getDefinition(attributeName);
115
116 if (attributeDefinition != null) {
117 return (X) value;
118 }
119
120 return null;
121 }
122
123 @Override
124 public AttributeValueReader clone() {
125 SingleAttributeValueReader clone = new SingleAttributeValueReader(this.value, this.entryName,
126 this.attributeName, this.definition);
127 clone.setAttributeName(this.attributeName);
128 return clone;
129 }
130
131 }