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.validation.capability.ExistenceConstrainable;
020    
021    /**
022     * Common class for attribute definitions in the DataDictionary, which contains
023     * information relating to the display, validation, and general maintenance of a
024     * specific attribute of an entry. An attribute can be a simple or complex attribute.
025     *  
026     */
027    public abstract class AttributeDefinitionBase extends DataDictionaryDefinitionBase implements ExistenceConstrainable{
028    
029            protected String name;
030    
031            protected String label;
032            protected String shortLabel;
033            protected String displayLabelAttribute;
034    
035            protected String messageKey;
036        protected String constraintText;
037            protected String summary;
038            protected String description;
039            
040            protected Boolean required = Boolean.FALSE;
041            
042            public String getName() {
043                    return name;
044            }
045    
046            /*
047             * name = name of attribute
048             */
049            public void setName(String name) {
050                    if (StringUtils.isBlank(name)) {
051                            throw new IllegalArgumentException("invalid (blank) name");
052                    }
053                    this.name = name;
054            }
055    
056            public String getLabel() {
057                    return label;
058            }
059    
060            /**
061             * The label element is the field or collection name that will be shown on
062             * inquiry and maintenance screens. This will be overridden by presence of
063             * displayLabelAttribute element.
064             */
065            public void setLabel(String label) {
066                    if (StringUtils.isBlank(label)) {
067                            throw new IllegalArgumentException("invalid (blank) label");
068                    }
069                    this.label = label;
070            }
071    
072            /**
073             * @return the shortLabel, or the label if no shortLabel has been set
074             */
075            public String getShortLabel() {
076                    return (shortLabel != null) ? shortLabel : getLabel();
077            }
078    
079            /**
080             * @return the shortLabel directly, without substituting in the label
081             */
082            protected String getDirectShortLabel() {
083                    return shortLabel;
084            }
085    
086            /**
087             * The shortLabel element is the field or collection name that will be used
088             * in applications when a shorter name (than the label element) is required.
089             * This will be overridden by presence of displayLabelAttribute element.
090             */
091            public void setShortLabel(String shortLabel) {
092                    if (StringUtils.isBlank(shortLabel)) {
093                            throw new IllegalArgumentException("invalid (blank) shortLabel");
094                    }
095                    this.shortLabel = shortLabel;
096            }
097            
098            /**
099             * The required element allows values of "true" or "false". A value of
100             * "true" indicates that a value must be entered for this business object
101             * when creating or editing a new business object.
102             */
103            public void setRequired(Boolean required) {
104                    this.required = required;
105            }
106    
107            @Override
108            public Boolean isRequired() {
109                    return this.required;
110            }
111    
112        /**
113         * Text that display a restriction on the value a field can hold
114         *
115         * <p>
116         * For example when the value must be a valid format (phone number, email), certain length, min/max value and
117         * so on this text can be used to indicate the constraint to the user. Generally displays with the control so
118         * it is visible when the user tabs to the field
119         * </p>
120         *
121         * @return String text to display for the constraint message
122         */
123        public String getConstraintText() {
124            return this.constraintText;
125        }
126    
127        /**
128         * Setter for the constraint message text
129         *
130         * @param constraintText
131         */
132        public void setConstraintText(String constraintText) {
133            this.constraintText = constraintText;
134        }
135            
136            public String getSummary() {
137                    return summary;
138            }
139    
140            /**
141             * The summary element is used to provide a short description of the
142             * attribute or collection. This is designed to be used for help purposes.
143             */
144            public void setSummary(String summary) {
145                    this.summary = summary;
146            }
147    
148            public String getDescription() {
149                    return description;
150            }
151    
152            /**
153             * The description element is used to provide a long description of the
154             * attribute or collection. This is designed to be used for help purposes.
155             */
156            public void setDescription(String description) {
157                    this.description = description;
158            }
159            
160            public String getDisplayLabelAttribute() {
161                    return displayLabelAttribute;
162            }
163    
164            /**
165             * The displayLabelAttribute element is used to indicate that the label and
166             * short label should be obtained from another attribute.
167             * 
168             * The label element and short label element defined for this attribute will
169             * be overridden. Instead, the label and short label values will be obtained
170             * by referencing the corresponding values from the attribute indicated by
171             * this element.
172             */
173            public void setDisplayLabelAttribute(String displayLabelAttribute) {
174                    this.displayLabelAttribute = displayLabelAttribute;
175            }
176    
177    }