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 * CollectionDefinition defines a single Collection attribute definition in the DataDictionary 024 * 025 * <p>It contains information relating to the display, validation, 026 * and general maintenance of a specific Collection attribute of an entry. It helps to provide meaningful labels for 027 * collections on a business or data object. 028 * It can be used to define collections that are generated at runtime and marked using @{@code Transient} in the containing 029 * business or data object class.</p> 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable{ 034 private static final long serialVersionUID = -2644072136271281041L; 035 036 protected String dataObjectClass; 037 protected String name; 038 protected String label; 039 protected String shortLabel; 040 protected String elementLabel; 041 042 protected String summary; 043 044 protected String description; 045 046 protected Integer minOccurs; 047 protected Integer maxOccurs; 048 049 /** 050 * default constructor 051 */ 052 public CollectionDefinition() { 053 //empty 054 } 055 056 /** 057 * gets the name of the collection 058 * 059 * @return the collection name 060 */ 061 public String getName() { 062 return name; 063 } 064 065 /** 066 * sets the name of the collection 067 * 068 * @param name - the collection name 069 * @throws IllegalArgumentException if the name is blank 070 */ 071 public void setName(String name) { 072 if (StringUtils.isBlank(name)) { 073 throw new IllegalArgumentException("invalid (blank) name"); 074 } 075 this.name = name; 076 } 077 078 /** 079 * gets the label 080 * 081 * @return the label 082 */ 083 public String getLabel() { 084 return label; 085 } 086 087 /** 088 * sets the label 089 * 090 * @param label - a descriptive string to use for a label 091 */ 092 public void setLabel(String label) { 093 if (StringUtils.isBlank(label)) { 094 throw new IllegalArgumentException("invalid (blank) label"); 095 } 096 this.label = label; 097 } 098 099 /** 100 * gets the short label 101 * 102 * @return the shortLabel, or the label if no shortLabel has been set 103 */ 104 public String getShortLabel() { 105 return (shortLabel != null) ? shortLabel : label; 106 } 107 108 /** 109 * sets the short label 110 * 111 * @param shortLabel - the short label 112 * @throws IllegalArgumentException when {@code shortLabel} is blank 113 */ 114 public void setShortLabel(String shortLabel) { 115 if (StringUtils.isBlank(shortLabel)) { 116 throw new IllegalArgumentException("invalid (blank) shortLabel"); 117 } 118 this.shortLabel = shortLabel; 119 } 120 121 /** 122 * Gets the elementLabel attribute 123 * 124 * @return the element Label 125 */ 126 public String getElementLabel() { 127 return elementLabel; 128 } 129 130 /** 131 * gets the element label 132 * 133 * <p>The elementLabel defines the name to be used for a single object within the collection. 134 * For example: "Address" may be the name 135 * of one object within the "Addresses" collection.</p> 136 */ 137 public void setElementLabel(String elementLabel) { 138 this.elementLabel = elementLabel; 139 } 140 141 /** 142 * gets the summary 143 * 144 * <p>summary element is used to provide a short description of the 145 * attribute or collection. This is designed to be used for help purposes.</p> 146 * 147 * @return the summary 148 */ 149 public String getSummary() { 150 return summary; 151 } 152 153 /** 154 * gets the summary 155 */ 156 public void setSummary(String summary) { 157 this.summary = summary; 158 } 159 160 /** 161 * gets the description 162 * 163 * <p>The description element is used to provide a long description of the 164 * attribute or collection. This is designed to be used for help purposes.</p> 165 * 166 * @return the description 167 */ 168 public String getDescription() { 169 return description; 170 } 171 172 /** 173 * sets the description 174 * 175 * @param description - the description to set 176 */ 177 public void setDescription(String description) { 178 this.description = description; 179 } 180 181 182 /** 183 * gets the data object class 184 * 185 * <p>This is the Java class type of the object contained in this collection</p> 186 * 187 * @return the dataObjectClass 188 */ 189 public String getDataObjectClass() { 190 return this.dataObjectClass; 191 } 192 193 /** 194 * sets the data object class 195 * @param dataObjectClass the dataObjectClass to set 196 */ 197 public void setDataObjectClass(String dataObjectClass) { 198 this.dataObjectClass = dataObjectClass; 199 } 200 201 /** 202 * Directly validate simple fields, call completeValidation on Definition fields 203 * 204 * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation() 205 */ 206 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 207 if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) { 208 throw new AttributeValidationException("property '" + name + "' is not a collection property of class '" + rootBusinessObjectClass + "' (" + "" + ")"); 209 } 210 } 211 212 /** 213 * @see java.lang.Object#toString() 214 * @return a descriptive string with the collection name 215 */ 216 @Override 217 public String toString() { 218 return "CollectionDefinition for collection " + getName(); 219 } 220 221 /** 222 * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMaximumNumberOfElements() 223 */ 224 @Override 225 public Integer getMaximumNumberOfElements() { 226 return this.maxOccurs; 227 } 228 229 /** 230 * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMinimumNumberOfElements() 231 */ 232 @Override 233 public Integer getMinimumNumberOfElements() { 234 return this.minOccurs; 235 } 236 237 /** 238 * gets the minimum amount of items in this collection 239 * 240 * @return the minOccurs 241 */ 242 public Integer getMinOccurs() { 243 return this.minOccurs; 244 } 245 246 /** 247 * gets the minimum amount of items in this collection 248 * 249 * @param minOccurs the minOccurs to set 250 */ 251 public void setMinOccurs(Integer minOccurs) { 252 this.minOccurs = minOccurs; 253 } 254 255 /** 256 * gets maximum amount of items in this collection 257 * 258 * @return the maxOccurs 259 */ 260 public Integer getMaxOccurs() { 261 return this.maxOccurs; 262 } 263 264 /** 265 * sets maximum amount of items in this collection 266 * 267 * @param maxOccurs the maxOccurs to set 268 */ 269 public void setMaxOccurs(Integer maxOccurs) { 270 this.maxOccurs = maxOccurs; 271 } 272 273 }