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
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class RelationshipDefinition extends DataDictionaryDefinitionBase {
48 private static final long serialVersionUID = 2946722646095412576L;
49
50 protected String objectAttributeName;
51 protected Class<?> sourceClass;
52
53
54
55
56
57 protected Class<?> targetClass;
58
59 protected List<PrimitiveAttributeDefinition> primitiveAttributes = new ArrayList<PrimitiveAttributeDefinition>();
60 protected List<SupportAttributeDefinition> supportAttributes = new ArrayList<SupportAttributeDefinition>();
61
62
63 public RelationshipDefinition() {}
64
65 public String getObjectAttributeName() {
66 return objectAttributeName;
67 }
68
69 public Class<?> getSourceClass() {
70 return sourceClass;
71 }
72
73
74
75
76 public Class<?> getTargetClass() {
77 if (targetClass == null) {
78 Class propertyClass = DataDictionary.getAttributeClass(sourceClass, objectAttributeName);
79 if (propertyClass == null) {
80 throw new AttributeValidationException("cannot get valid class for property '" + objectAttributeName + "' as an attribute of '" + sourceClass + "'");
81 }
82
83 targetClass = propertyClass;
84 }
85 return targetClass;
86 }
87
88
89
90
91
92
93 public void setTargetClass(Class<?> targetClass) {
94 this.targetClass = targetClass;
95 }
96
97
98
99
100
101 public void setObjectAttributeName(String objectAttributeName) {
102 if (StringUtils.isBlank(objectAttributeName)) {
103 throw new IllegalArgumentException("invalid (blank) objectAttributeName");
104 }
105
106 this.objectAttributeName = objectAttributeName;
107 }
108
109 public List<PrimitiveAttributeDefinition> getPrimitiveAttributes() {
110 return primitiveAttributes;
111 }
112
113 public List<SupportAttributeDefinition> getSupportAttributes() {
114 return supportAttributes;
115 }
116
117 public boolean hasIdentifier() {
118 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
119 if ( supportAttributeDefinition.isIdentifier() ) {
120 return true;
121 }
122 }
123 return false;
124 }
125
126 public SupportAttributeDefinition getIdentifier() {
127 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
128 if ( supportAttributeDefinition.isIdentifier() ) {
129 return supportAttributeDefinition;
130 }
131 }
132 return null;
133 }
134
135
136
137
138
139
140 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
141 String propertyName = objectAttributeName;
142 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, propertyName)) {
143 throw new AttributeValidationException("property '" + propertyName + "' is not an attribute of class '" + rootBusinessObjectClass + "' (" + "" + ")");
144 }
145
146 getTargetClass();
147
148 for (PrimitiveAttributeDefinition primitiveAttributeDefinition : primitiveAttributes) {
149 primitiveAttributeDefinition.completeValidation(rootBusinessObjectClass, targetClass);
150 }
151 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
152 supportAttributeDefinition.completeValidation(rootBusinessObjectClass, targetClass);
153 }
154 }
155
156
157
158
159
160 @Override
161 public String toString() {
162 return "RelationshipDefinition for relationship " + getObjectAttributeName();
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 public void setPrimitiveAttributes(List<PrimitiveAttributeDefinition> primitiveAttributes) {
182 this.primitiveAttributes = primitiveAttributes;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 public void setSupportAttributes(List<SupportAttributeDefinition> supportAttributes) {
200 this.supportAttributes = supportAttributes;
201 }
202
203
204
205
206 public void setSourceClass(Class<?> sourceClass) {
207 this.sourceClass = sourceClass;
208 }
209 }
210