001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.datadictionary;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
020    import org.kuali.rice.krad.datadictionary.validation.capability.CollectionSizeConstrainable;
021    
022    /**
023     * A single Collection attribute definition in the DataDictionary, which contains information relating to the display, validation,
024     * and general maintenance of a specific Collection attribute of an entry.
025     * 
026     * 
027     */
028    public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable{
029        private static final long serialVersionUID = -2644072136271281041L;
030        
031        protected String dataObjectClass;
032        protected String name;
033        protected String label;
034        protected String shortLabel;
035        protected String elementLabel;
036        
037        protected String summary;
038    
039            protected String description;
040        
041            protected Integer minOccurs;
042            protected Integer maxOccurs;
043    
044        public CollectionDefinition() {
045            //empty
046        }
047    
048        public String getName() {
049            return name;
050        }
051    
052        public void setName(String name) {
053            if (StringUtils.isBlank(name)) {
054                throw new IllegalArgumentException("invalid (blank) name");
055            }
056            this.name = name;
057        }
058    
059        public String getLabel() {
060            return label;
061        }
062    
063        public void setLabel(String label) {
064            if (StringUtils.isBlank(label)) {
065                throw new IllegalArgumentException("invalid (blank) label");
066            }
067            this.label = label;
068        }
069    
070        /**
071         * @return the shortLabel, or the label if no shortLabel has been set
072         */
073        public String getShortLabel() {
074            return (shortLabel != null) ? shortLabel : label;
075        }
076    
077        public void setShortLabel(String shortLabel) {
078            if (StringUtils.isBlank(shortLabel)) {
079                throw new IllegalArgumentException("invalid (blank) shortLabel");
080            }
081            this.shortLabel = shortLabel;
082        }
083    
084        /**
085         * Gets the elementLabel attribute. 
086         * @return Returns the elementLabel.
087         */
088        public String getElementLabel() {
089            return elementLabel;
090        }
091    
092        /**
093             * The elementLabel defines the name to be used for a single object
094         * within the collection.  For example: "Address" may be the name
095         * of one object within the "Addresses" collection.
096         */
097        public void setElementLabel(String elementLabel) {
098            this.elementLabel = elementLabel;
099        }
100    
101        public String getSummary() {
102            return summary;
103        }
104    
105        /**
106             * The summary element is used to provide a short description of the
107         * attribute or collection.  This is designed to be used for help purposes.
108         */
109        public void setSummary(String summary) {
110            this.summary = summary;
111        }
112    
113        public String getDescription() {
114            return description;
115        }
116    
117        /**
118             * The description element is used to provide a long description of the
119             * attribute or collection.  This is designed to be used for help purposes.
120         */
121        public void setDescription(String description) {
122            this.description = description;
123        }
124        
125               
126        /**
127             * @return the dataObjectClass
128             */
129            public String getDataObjectClass() {
130                    return this.dataObjectClass;
131            }
132    
133            /**
134             * @param objectClass the dataObjectClass to set
135             */
136            public void setDataObjectClass(String dataObjectClass) {
137                    this.dataObjectClass = dataObjectClass;
138            }
139    
140            /**
141         * Directly validate simple fields, call completeValidation on Definition fields.
142         * 
143         * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation()
144         */
145        public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
146            if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
147                throw new AttributeValidationException("property '" + name + "' is not a collection property of class '" + rootBusinessObjectClass + "' (" + "" + ")");
148            }
149        }
150    
151    
152        /**
153         * @see java.lang.Object#toString()
154         */
155        @Override
156        public String toString() {
157            return "CollectionDefinition for collection " + getName();
158        }
159    
160            /**
161             * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMaximumNumberOfElements()
162             */
163            @Override
164            public Integer getMaximumNumberOfElements() {
165                    return this.maxOccurs;
166            }
167    
168            /**
169             * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMinimumNumberOfElements()
170             */
171            @Override
172            public Integer getMinimumNumberOfElements() {
173                    return this.minOccurs;
174            }
175    
176        /**
177             * @return the minOccurs
178             */
179            public Integer getMinOccurs() {
180                    return this.minOccurs;
181            }
182    
183            /**
184             * @param minOccurs the minOccurs to set
185             */
186            public void setMinOccurs(Integer minOccurs) {
187                    this.minOccurs = minOccurs;
188            }
189    
190            /**
191             * @return the maxOccurs
192             */
193            public Integer getMaxOccurs() {
194                    return this.maxOccurs;
195            }
196    
197            /**
198             * @param maxOccurs the maxOccurs to set
199             */
200            public void setMaxOccurs(Integer maxOccurs) {
201                    this.maxOccurs = maxOccurs;
202            }
203    
204    }