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.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
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<?> collectionBusinessObjectClass;
47 protected Class<?> 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 public boolean isDisplayFieldNameSet() {
121 return StringUtils.isNotBlank(displayFieldName);
122 }
123
124 @BeanTagAttribute(name = "collection")
125 public String getCollection() {
126 return collection;
127 }
128
129
130
131
132 public void setCollection(String collection) {
133 this.collection = collection;
134 }
135
136 public boolean isCollectionReference() {
137 return StringUtils.isNotBlank(getCollection());
138 }
139
140 @BeanTagAttribute(name = "collectionBusinessObjectClass")
141 public Class<?> getCollectionBusinessObjectClass() {
142 return collectionBusinessObjectClass;
143 }
144
145
146
147
148
149 public void setCollectionBusinessObjectClass(Class<?> collectionBusinessObjectClass) {
150 this.collectionBusinessObjectClass = collectionBusinessObjectClass;
151 }
152
153 @Override
154 public void dataDictionaryPostProcessing() {
155 super.dataDictionaryPostProcessing();
156 if (collectionBusinessObjectClass == null && isCollectionReference()) {
157 collectionBusinessObjectClass = DataDictionary.getCollectionElementClass(businessObjectClass, collection);
158 }
159 }
160
161 @Override
162 public void completeValidation(Class<?> rootBusinessObjectClass, Class<?> otherBusinessObjectClass, ValidationTrace tracer) {
163 String tmpAttributeName = isCollectionReference() ? collection : attributeName;
164
165 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, tmpAttributeName)) {
166 String currentValues[] = {"rootBusinessObjectClass = " + rootBusinessObjectClass.getName(),
167 "attribute = " + tmpAttributeName};
168 tracer.createError("ReferenceDefinition attribute does not exist on parent object",
169 currentValues);
170 }
171
172 if (isCollectionReference()) {
173 if (collectionBusinessObjectClass == null) {
174 String currentValues[] = {"rootBusinessObjectClass = " + rootBusinessObjectClass.getName(),
175 "attribute = " + tmpAttributeName};
176 tracer.createError("ReferenceDefinition: Unable to determine BO class for collection",
177 currentValues);
178 } else {
179 if (!DataDictionary.isPropertyOf(collectionBusinessObjectClass, attributeToHighlightOnFail)) {
180 String currentValues[] = {"collectionBusinessObjectClass = " + collectionBusinessObjectClass.getName(),
181 "attributeToHighlightOnFail = " + attributeToHighlightOnFail};
182 tracer.createError("ReferenceDefinition: attributeToHighlightOnFail does not exist on collection class",
183 currentValues);
184 }
185 }
186 } else {
187 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeToHighlightOnFail)) {
188 String currentValues[] = {"rootBusinessObjectClass = " + rootBusinessObjectClass.getName(),
189 "attributeToHighlightOnFail = " + attributeToHighlightOnFail};
190 tracer.createError("ReferenceDefinition: attributeToHighlightOnFail does not exist on parent class",
191 currentValues);
192 }
193 }
194 }
195
196
197 @BeanTagAttribute(name = "businessObjectClass")
198 public Class<?> getBusinessObjectClass() {
199 return businessObjectClass;
200 }
201
202 public void setBusinessObjectClass(Class<?> businessObjectClass) {
203 this.businessObjectClass = businessObjectClass;
204 }
205 }