View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20  import org.kuali.rice.krad.datadictionary.validation.capability.CollectionSizeConstrainable;
21  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22  
23  /**
24   * CollectionDefinition defines a single Collection attribute definition in the DataDictionary
25   *
26   * <p>It contains information relating to the display, validation,
27   * and general maintenance of a specific Collection attribute of an entry. It helps to provide meaningful labels for
28   * collections on a business or data object.
29   * It can be used to define collections that are generated at runtime and marked using @{@code Transient} in the
30   * containing
31   * business or data object class.</p>
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  
36  public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable {
37      private static final long serialVersionUID = -2644072136271281041L;
38  
39      protected String dataObjectClass;
40  
41      protected String name;
42  
43      protected String label;
44  
45      protected String shortLabel;
46  
47      protected String elementLabel;
48  
49      protected String summary;
50  
51      protected String description;
52  
53      protected Integer minOccurs;
54  
55      protected Integer maxOccurs;
56  
57      /**
58       * default constructor
59       */
60      public CollectionDefinition() {
61          //empty
62      }
63  
64      /**
65       * gets the name of the collection
66       *
67       * @return the collection name
68       */
69      public String getName() {
70          return name;
71      }
72  
73      /**
74       * sets the name of the collection
75       *
76       * @param name - the collection name
77       * @throws IllegalArgumentException if the name is blank
78       */
79      public void setName(String name) {
80          if (StringUtils.isBlank(name)) {
81              throw new IllegalArgumentException("invalid (blank) name");
82          }
83          this.name = name;
84      }
85  
86      /**
87       * gets the label
88       *
89       * @return the label
90       */
91      public String getLabel() {
92          return label;
93      }
94  
95      /**
96       * sets the label
97       *
98       * @param label - a descriptive string to use for a label
99       */
100     public void setLabel(String label) {
101         if (StringUtils.isBlank(label)) {
102             throw new IllegalArgumentException("invalid (blank) label");
103         }
104         this.label = label;
105     }
106 
107     /**
108      * gets the short label
109      *
110      * @return the shortLabel, or the label if no shortLabel has been set
111      */
112     public String getShortLabel() {
113         return (shortLabel != null) ? shortLabel : label;
114     }
115 
116     /**
117      * sets the short label
118      *
119      * @param shortLabel - the short label
120      * @throws IllegalArgumentException when {@code shortLabel} is blank
121      */
122     public void setShortLabel(String shortLabel) {
123         if (StringUtils.isBlank(shortLabel)) {
124             throw new IllegalArgumentException("invalid (blank) shortLabel");
125         }
126         this.shortLabel = shortLabel;
127     }
128 
129     /**
130      * Gets the elementLabel attribute
131      *
132      * @return the element Label
133      */
134     public String getElementLabel() {
135         return elementLabel;
136     }
137 
138     /**
139      * gets the element label
140      *
141      * <p>The elementLabel defines the name to be used for a single object within the collection.
142      * For example: "Address" may be the name
143      * of one object within the "Addresses" collection.</p>
144      */
145     public void setElementLabel(String elementLabel) {
146         this.elementLabel = elementLabel;
147     }
148 
149     /**
150      * gets the summary
151      *
152      * <p>summary element is used to provide a short description of the
153      * attribute or collection. This is designed to be used for help purposes.</p>
154      *
155      * @return the summary
156      */
157     public String getSummary() {
158         return summary;
159     }
160 
161     /**
162      * gets the summary
163      */
164     public void setSummary(String summary) {
165         this.summary = summary;
166     }
167 
168     /**
169      * gets the description
170      *
171      * <p>The description element is used to provide a long description of the
172      * attribute or collection.  This is designed to be used for help purposes.</p>
173      *
174      * @return the description
175      */
176     public String getDescription() {
177         return description;
178     }
179 
180     /**
181      * sets the description
182      *
183      * @param description - the description to set
184      */
185     public void setDescription(String description) {
186         this.description = description;
187     }
188 
189     /**
190      * gets the data object class
191      *
192      * <p>This is the Java class type of the object contained in this collection</p>
193      *
194      * @return the dataObjectClass
195      */
196     public String getDataObjectClass() {
197         return this.dataObjectClass;
198     }
199 
200     /**
201      * sets the data object class
202      *
203      * @param dataObjectClass the dataObjectClass to set
204      */
205     public void setDataObjectClass(String dataObjectClass) {
206         this.dataObjectClass = dataObjectClass;
207     }
208 
209     /**
210      * Directly validate simple fields, call completeValidation on Definition fields
211      *
212      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation()
213      */
214     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
215         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
216             throw new AttributeValidationException("property '"
217                     + name
218                     + "' is not a collection property of class '"
219                     + rootBusinessObjectClass
220                     + "' ("
221                     + ""
222                     + ")");
223         }
224     }
225 
226     /**
227      * Directly validate simple fields, call completeValidation on Definition
228      * fields.
229      *
230      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
231      */
232     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
233             ValidationTrace tracer) {
234         tracer.addBean(this.getClass().getSimpleName(), "Attribute: " + getName());
235         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
236             String currentValues[] = {"property = " + getName(), "Class =" + rootBusinessObjectClass};
237             tracer.createError("Property is not collection property of the class", currentValues);
238         }
239     }
240 
241     /**
242      * @return a descriptive string with the collection name
243      * @see java.lang.Object#toString()
244      */
245     @Override
246     public String toString() {
247         return "CollectionDefinition for collection " + getName();
248     }
249 
250     /**
251      * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMaximumNumberOfElements()
252      */
253     @Override
254     public Integer getMaximumNumberOfElements() {
255         return this.maxOccurs;
256     }
257 
258     /**
259      * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMinimumNumberOfElements()
260      */
261     @Override
262     public Integer getMinimumNumberOfElements() {
263         return this.minOccurs;
264     }
265 
266     /**
267      * gets the minimum amount of items in this collection
268      *
269      * @return the minOccurs
270      */
271     public Integer getMinOccurs() {
272         return this.minOccurs;
273     }
274 
275     /**
276      * gets the minimum amount of items in this collection
277      *
278      * @param minOccurs the minOccurs to set
279      */
280     public void setMinOccurs(Integer minOccurs) {
281         this.minOccurs = minOccurs;
282     }
283 
284     /**
285      * gets maximum amount of items in this collection
286      *
287      * @return the maxOccurs
288      */
289     public Integer getMaxOccurs() {
290         return this.maxOccurs;
291     }
292 
293     /**
294      * sets maximum amount of items in this collection
295      *
296      * @param maxOccurs the maxOccurs to set
297      */
298     public void setMaxOccurs(Integer maxOccurs) {
299         this.maxOccurs = maxOccurs;
300     }
301 
302 }