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.data.metadata.DataObjectCollection;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.validation.capability.CollectionSizeConstrainable;
22 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23
24
25
26
27
28
29
30
31
32
33
34
35
36 @BeanTag(name = "collectionDefinition")
37 public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable {
38 private static final long serialVersionUID = -2644072136271281041L;
39
40 protected DataObjectCollection dataObjectCollection;
41
42 protected String dataObjectClass;
43 protected String name;
44 protected String label;
45 protected String shortLabel;
46 protected String elementLabel;
47 protected String summary;
48 protected String description;
49 protected Integer minOccurs;
50 protected Integer maxOccurs;
51
52
53
54
55 public CollectionDefinition() {
56
57 }
58
59
60
61
62
63
64 @Override
65 public String getName() {
66 return name;
67 }
68
69
70
71
72
73
74
75 public void setName(String name) {
76 if (StringUtils.isBlank(name)) {
77 throw new IllegalArgumentException("invalid (blank) name");
78 }
79 this.name = name;
80 }
81
82
83
84
85
86
87 public String getLabel() {
88 if ( label != null ) {
89 return label;
90 }
91
92 if ( getDataObjectCollection() != null ) {
93 return getDataObjectCollection().getLabel();
94 }
95 return "";
96 }
97
98
99
100
101
102
103 public void setLabel(String label) {
104 if (StringUtils.isBlank(label)) {
105 throw new IllegalArgumentException("invalid (blank) label");
106 }
107 this.label = label;
108 }
109
110
111
112
113
114
115 public String getShortLabel() {
116 if ( shortLabel != null ) {
117 return shortLabel;
118 }
119 if ( getDataObjectCollection() != null ) {
120
121 if ( StringUtils.equals(getDataObjectCollection().getLabel(), getDataObjectCollection().getShortLabel())
122 && label != null ) {
123 return getLabel();
124 }
125 return getDataObjectCollection().getShortLabel();
126 }
127 return getLabel();
128 }
129
130
131
132
133
134
135
136 public void setShortLabel(String shortLabel) {
137 if (StringUtils.isBlank(shortLabel)) {
138 throw new IllegalArgumentException("invalid (blank) shortLabel");
139 }
140 this.shortLabel = shortLabel;
141 }
142
143
144
145
146
147
148 public String getElementLabel() {
149 if ( elementLabel != null ) {
150 return elementLabel;
151 }
152
153 if ( getDataObjectCollection() != null ) {
154 return getDataObjectCollection().getElementLabel();
155 }
156 return dataObjectClass;
157 }
158
159
160
161
162
163
164
165
166 public void setElementLabel(String elementLabel) {
167 this.elementLabel = elementLabel;
168 }
169
170
171
172
173
174
175
176
177
178 public String getSummary() {
179 if ( summary != null ) {
180 return summary;
181 }
182 return "";
183 }
184
185
186
187
188 public void setSummary(String summary) {
189 this.summary = summary;
190 }
191
192
193
194
195
196
197
198
199
200 public String getDescription() {
201 if ( description != null ) {
202 return description;
203 }
204 if ( getDataObjectCollection() != null ) {
205 return getDataObjectCollection().getDescription();
206 }
207 return "";
208 }
209
210
211
212
213
214
215 public void setDescription(String description) {
216 this.description = description;
217 }
218
219
220
221
222
223
224
225
226 public String getDataObjectClass() {
227
228
229
230 if ( dataObjectClass == null ) {
231 if ( getDataObjectCollection() != null ) {
232 dataObjectClass = getDataObjectCollection().getRelatedType().getName();
233 }
234 }
235 return dataObjectClass;
236 }
237
238
239
240
241
242
243 public void setDataObjectClass(String dataObjectClass) {
244 this.dataObjectClass = dataObjectClass;
245 }
246
247
248
249
250
251
252 @Override
253 @Deprecated
254 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
255 completeValidation(rootBusinessObjectClass, otherBusinessObjectClass, new ValidationTrace());
256 }
257
258
259
260
261
262
263
264 @Override
265 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
266 ValidationTrace tracer) {
267 tracer.addBean(this.getClass().getSimpleName(), "Attribute: " + getName());
268 if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
269 String currentValues[] = {"property = " + getName(), "Class =" + rootBusinessObjectClass};
270 tracer.createError("Property is not collection property of the class", currentValues);
271 }
272 }
273
274
275
276
277 @Override
278 public Integer getMaximumNumberOfElements() {
279 return this.maxOccurs;
280 }
281
282
283
284
285 @Override
286 public Integer getMinimumNumberOfElements() {
287 if ( minOccurs != null ) {
288 return minOccurs;
289 }
290 if ( getDataObjectCollection() != null ) {
291 return getDataObjectCollection().getMinItems().intValue();
292 }
293 return null;
294 }
295
296
297
298
299
300
301 public Integer getMinOccurs() {
302 return this.minOccurs;
303 }
304
305
306
307
308
309
310 public void setMinOccurs(Integer minOccurs) {
311 this.minOccurs = minOccurs;
312 }
313
314
315
316
317
318
319 public Integer getMaxOccurs() {
320 if ( maxOccurs != null ) {
321 return maxOccurs;
322 }
323 if ( getDataObjectCollection() != null ) {
324 return getDataObjectCollection().getMaxItems().intValue();
325 }
326 return null;
327 }
328
329
330
331
332
333
334 public void setMaxOccurs(Integer maxOccurs) {
335 this.maxOccurs = maxOccurs;
336 }
337
338 public DataObjectCollection getDataObjectCollection() {
339 return this.dataObjectCollection;
340 }
341
342 public void setDataObjectCollection(DataObjectCollection dataObjectCollection) {
343 this.dataObjectCollection = dataObjectCollection;
344 }
345
346 }