| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.datadictionary; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 20 | |
import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class ReferenceDefinition extends DataDictionaryDefinitionBase { |
| 39 | |
private static final long serialVersionUID = 1737968024207302931L; |
| 40 | |
|
| 41 | |
protected String attributeName; |
| 42 | |
protected String attributeToHighlightOnFail; |
| 43 | |
protected String displayFieldName; |
| 44 | |
protected String collection; |
| 45 | |
protected Class<? extends BusinessObject> collectionBusinessObjectClass; |
| 46 | |
protected Class<? extends BusinessObject> businessObjectClass; |
| 47 | |
|
| 48 | 0 | public ReferenceDefinition() {} |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public String getAttributeName() { |
| 54 | 0 | return attributeName; |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public void setAttributeName(String attributeName) { |
| 66 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 67 | 0 | throw new IllegalArgumentException("invalid (blank) attributeName"); |
| 68 | |
} |
| 69 | 0 | this.attributeName = attributeName; |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
public String getAttributeToHighlightOnFail() { |
| 78 | 0 | return attributeToHighlightOnFail; |
| 79 | |
} |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
public void setAttributeToHighlightOnFail(String attributeToHighlightOnFail) { |
| 87 | 0 | if (StringUtils.isBlank(attributeToHighlightOnFail)) { |
| 88 | 0 | throw new IllegalArgumentException("invalid (blank) attributeToHighlightOnFail"); |
| 89 | |
} |
| 90 | 0 | this.attributeToHighlightOnFail = attributeToHighlightOnFail; |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public String getDisplayFieldName() { |
| 99 | 0 | return displayFieldName; |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
public void setDisplayFieldName(String displayFieldName) { |
| 107 | 0 | this.displayFieldName = displayFieldName; |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public boolean isDisplayFieldNameSet() { |
| 117 | 0 | return StringUtils.isNotBlank(displayFieldName); |
| 118 | |
} |
| 119 | |
|
| 120 | |
public String getCollection() { |
| 121 | 0 | return collection; |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
public void setCollection(String collection) { |
| 128 | 0 | this.collection = collection; |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
public boolean isCollectionReference() { |
| 132 | 0 | return StringUtils.isNotBlank(getCollection()); |
| 133 | |
} |
| 134 | |
|
| 135 | |
public Class<? extends BusinessObject> getCollectionBusinessObjectClass() { |
| 136 | 0 | if( collectionBusinessObjectClass == null && isCollectionReference() ){ |
| 137 | 0 | collectionBusinessObjectClass=DataDictionary.getCollectionElementClass(businessObjectClass, collection); |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | return collectionBusinessObjectClass; |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public void setCollectionBusinessObjectClass(Class<? extends BusinessObject> collectionBusinessObjectClass) { |
| 147 | 0 | this.collectionBusinessObjectClass = collectionBusinessObjectClass; |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | 0 | String tmpAttributeName = isCollectionReference() ? collection : attributeName; |
| 160 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, tmpAttributeName)) { |
| 161 | 0 | throw new AttributeValidationException("unable to find attribute '" + tmpAttributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 162 | |
} |
| 163 | |
|
| 164 | 0 | if (isCollectionReference()) { |
| 165 | 0 | getCollectionBusinessObjectClass(); |
| 166 | 0 | if ( collectionBusinessObjectClass == null ) { |
| 167 | 0 | throw new AttributeValidationException("Unable to determine collectionBusinessObjectClass for collection '" + businessObjectClass.getName() + "." + collection + "'"); |
| 168 | |
} |
| 169 | |
|
| 170 | 0 | if (!DataDictionary.isPropertyOf(collectionBusinessObjectClass, attributeToHighlightOnFail)) { |
| 171 | 0 | throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in collectionBusinessObjectClass '" + collectionBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 172 | |
} |
| 173 | |
} |
| 174 | |
else { |
| 175 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeToHighlightOnFail)) { |
| 176 | 0 | throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 177 | |
} |
| 178 | |
} |
| 179 | |
|
| 180 | 0 | } |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
public String toString() { |
| 187 | 0 | return "ReferenceDefinition for attribute " + getAttributeName(); |
| 188 | |
} |
| 189 | |
|
| 190 | |
public Class<? extends BusinessObject> getBusinessObjectClass() { |
| 191 | 0 | return businessObjectClass; |
| 192 | |
} |
| 193 | |
|
| 194 | |
public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) { |
| 195 | 0 | this.businessObjectClass = businessObjectClass; |
| 196 | 0 | } |
| 197 | |
} |