1 /** 2 * Copyright 2005-2013 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.parse.BeanTagAttribute; 20 import org.kuali.rice.krad.datadictionary.validation.capability.ExistenceConstrainable; 21 import org.kuali.rice.krad.datadictionary.validation.capability.SimpleConstrainable; 22 import org.kuali.rice.krad.datadictionary.validation.constraint.SimpleConstraint; 23 24 /** 25 * Common class for attribute definitions in the DataDictionary, which contains 26 * information relating to the display, validation, and general maintenance of a 27 * specific attribute of an entry. An attribute can be a simple or complex attribute 28 * 29 * @author Kuali Rice Team (rice.collab@kuali.org) 30 */ 31 public abstract class AttributeDefinitionBase extends DataDictionaryDefinitionBase implements ExistenceConstrainable, 32 SimpleConstrainable { 33 34 protected String name; 35 36 protected String label; 37 protected String shortLabel; 38 protected String displayLabelAttribute; 39 40 protected String constraintText; 41 protected String summary; 42 protected String description; 43 44 protected SimpleConstraint simpleConstraint; 45 46 public AttributeDefinitionBase() { 47 super(); 48 simpleConstraint = new SimpleConstraint(); 49 } 50 51 /** 52 * Name of the attribute 53 * 54 * @return the name 55 */ 56 @BeanTagAttribute(name="name") 57 public String getName() { 58 return name; 59 } 60 61 /** 62 * Name of the attribute 63 * 64 * @param name 65 */ 66 public void setName(String name) { 67 if (StringUtils.isBlank(name)) { 68 throw new IllegalArgumentException("invalid (blank) name"); 69 } 70 this.name = name; 71 } 72 73 /** 74 * The label element is the field or collection name that will be shown on 75 * inquiry and maintenance screens. This will be overridden by presence of 76 * displayLabelAttribute element. 77 * 78 * @return the label 79 */ 80 @BeanTagAttribute(name="label") 81 public String getLabel() { 82 return label; 83 } 84 85 /** 86 * The label element is the field or collection name that will be shown on 87 * inquiry and maintenance screens. This will be overridden by presence of 88 * displayLabelAttribute element. 89 */ 90 public void setLabel(String label) { 91 if (StringUtils.isBlank(label)) { 92 throw new IllegalArgumentException("invalid (blank) label"); 93 } 94 this.label = label; 95 } 96 97 /** 98 * @return the shortLabel, or the label if no shortLabel has been set 99 */ 100 @BeanTagAttribute(name="shortLabel") 101 public String getShortLabel() { 102 return (shortLabel != null) ? shortLabel : getLabel(); 103 } 104 105 /** 106 * @return the shortLabel directly, without substituting in the label 107 */ 108 protected String getDirectShortLabel() { 109 return shortLabel; 110 } 111 112 /** 113 * The shortLabel element is the field or collection name that will be used 114 * in applications when a shorter name (than the label element) is required. 115 * This will be overridden by presence of displayLabelAttribute element. 116 */ 117 public void setShortLabel(String shortLabel) { 118 if (StringUtils.isBlank(shortLabel)) { 119 throw new IllegalArgumentException("invalid (blank) shortLabel"); 120 } 121 this.shortLabel = shortLabel; 122 } 123 124 /** 125 * Text that display a restriction on the value a field can hold 126 * 127 * <p> 128 * For example when the value must be a valid format (phone number, email), certain length, min/max value and 129 * so on this text can be used to indicate the constraint to the user. Generally displays with the control so 130 * it is visible when the user tabs to the field 131 * </p> 132 * 133 * @return String text to display for the constraint message 134 */ 135 @BeanTagAttribute(name="constraintText") 136 public String getConstraintText() { 137 return this.constraintText; 138 } 139 140 /** 141 * Setter for the constraint message text 142 * 143 * @param constraintText 144 */ 145 public void setConstraintText(String constraintText) { 146 this.constraintText = constraintText; 147 } 148 149 /** 150 * The summary element is used to provide a short description of the 151 * attribute or collection. This is designed to be used for help purposes. 152 * 153 * @return the summary 154 */ 155 @BeanTagAttribute(name="summary") 156 public String getSummary() { 157 return summary; 158 } 159 160 /** 161 * The summary element is used to provide a short description of the 162 * attribute or collection. This is designed to be used for help purposes. 163 */ 164 public void setSummary(String summary) { 165 this.summary = summary; 166 } 167 168 /** 169 * The description element is used to provide a long description of the 170 * attribute or collection. This is designed to be used for help purposes. 171 * 172 * @return the description 173 */ 174 @BeanTagAttribute(name="description") 175 public String getDescription() { 176 return description; 177 } 178 179 /** 180 * The description element is used to provide a long description of the 181 * attribute or collection. This is designed to be used for help purposes. 182 */ 183 public void setDescription(String description) { 184 this.description = description; 185 } 186 187 public String getDisplayLabelAttribute() { 188 return displayLabelAttribute; 189 } 190 191 /** 192 * The displayLabelAttribute element is used to indicate that the label and 193 * short label should be obtained from another attribute. 194 * 195 * The label element and short label element defined for this attribute will 196 * be overridden. Instead, the label and short label values will be obtained 197 * by referencing the corresponding values from the attribute indicated by 198 * this element. 199 */ 200 public void setDisplayLabelAttribute(String displayLabelAttribute) { 201 this.displayLabelAttribute = displayLabelAttribute; 202 } 203 204 /** 205 * Gets the SimpleConstraint which contains settings for required, min, max, minLength, and maxLength. 206 * 207 * @return SimpleConstraint object 208 */ 209 public SimpleConstraint getSimpleConstraint() { 210 return simpleConstraint; 211 } 212 213 /** 214 * Sets the SimpleConstraint which contains settings for required, min, max, minLength, and maxLength. 215 * 216 * @param simpleConstraint 217 */ 218 public void setSimpleConstraint(SimpleConstraint simpleConstraint) { 219 this.simpleConstraint = simpleConstraint; 220 } 221 222 /** 223 * Sets if this attribute is required 224 * 225 * @param required true when required, false otherwise 226 */ 227 public void setRequired(Boolean required) { 228 this.simpleConstraint.setRequired(required); 229 } 230 231 /** 232 * The required element allows values of "true" or "false". A value of 233 * "true" indicates that a value must be entered for this business object 234 * when creating or editing a new business object. 235 */ 236 @BeanTagAttribute(name="required") 237 public Boolean isRequired() { 238 return this.simpleConstraint.isRequired(); 239 } 240 241 }