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