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 public ReferenceDefinition() {}
49
50
51
52
53 public String getAttributeName() {
54 return attributeName;
55 }
56
57
58
59
60
61
62
63
64
65 public void setAttributeName(String attributeName) {
66 if (StringUtils.isBlank(attributeName)) {
67 throw new IllegalArgumentException("invalid (blank) attributeName");
68 }
69 this.attributeName = attributeName;
70 }
71
72
73
74
75
76
77 public String getAttributeToHighlightOnFail() {
78 return attributeToHighlightOnFail;
79 }
80
81
82
83
84
85
86 public void setAttributeToHighlightOnFail(String attributeToHighlightOnFail) {
87 if (StringUtils.isBlank(attributeToHighlightOnFail)) {
88 throw new IllegalArgumentException("invalid (blank) attributeToHighlightOnFail");
89 }
90 this.attributeToHighlightOnFail = attributeToHighlightOnFail;
91 }
92
93
94
95
96
97
98 public String getDisplayFieldName() {
99 return displayFieldName;
100 }
101
102
103
104
105
106 public void setDisplayFieldName(String displayFieldName) {
107 this.displayFieldName = displayFieldName;
108 }
109
110
111
112
113
114
115
116 public boolean isDisplayFieldNameSet() {
117 return StringUtils.isNotBlank(displayFieldName);
118 }
119
120 public String getCollection() {
121 return collection;
122 }
123
124
125
126
127 public void setCollection(String collection) {
128 this.collection = collection;
129 }
130
131 public boolean isCollectionReference() {
132 return StringUtils.isNotBlank(getCollection());
133 }
134
135 public Class<? extends BusinessObject> getCollectionBusinessObjectClass() {
136 if( collectionBusinessObjectClass == null && isCollectionReference() ){
137 collectionBusinessObjectClass=DataDictionary.getCollectionElementClass(businessObjectClass, collection);
138 }
139
140 return collectionBusinessObjectClass;
141 }
142
143
144
145
146 public void setCollectionBusinessObjectClass(Class<? extends BusinessObject> collectionBusinessObjectClass) {
147 this.collectionBusinessObjectClass = collectionBusinessObjectClass;
148 }
149
150
151
152
153
154
155 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
156
157
158
159 String tmpAttributeName = isCollectionReference() ? collection : attributeName;
160 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, tmpAttributeName)) {
161 throw new AttributeValidationException("unable to find attribute '" + tmpAttributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
162 }
163
164 if (isCollectionReference()) {
165 getCollectionBusinessObjectClass();
166 if ( collectionBusinessObjectClass == null ) {
167 throw new AttributeValidationException("Unable to determine collectionBusinessObjectClass for collection '" + businessObjectClass.getName() + "." + collection + "'");
168 }
169
170 if (!DataDictionary.isPropertyOf(collectionBusinessObjectClass, attributeToHighlightOnFail)) {
171 throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in collectionBusinessObjectClass '" + collectionBusinessObjectClass.getName() + "' (" + "" + ")");
172 }
173 }
174 else {
175 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeToHighlightOnFail)) {
176 throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
177 }
178 }
179
180 }
181
182
183
184
185
186 public String toString() {
187 return "ReferenceDefinition for attribute " + getAttributeName();
188 }
189
190 public Class<? extends BusinessObject> getBusinessObjectClass() {
191 return businessObjectClass;
192 }
193
194 public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
195 this.businessObjectClass = businessObjectClass;
196 }
197 }