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