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