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.validation.capability.ExistenceConstrainable;
20
21 /**
22 * Common class for attribute definitions in the DataDictionary, which contains
23 * information relating to the display, validation, and general maintenance of a
24 * specific attribute of an entry. An attribute can be a simple or complex attribute.
25 *
26 */
27 public abstract class AttributeDefinitionBase extends DataDictionaryDefinitionBase implements ExistenceConstrainable{
28
29 protected String name;
30
31 protected String label;
32 protected String shortLabel;
33 protected String displayLabelAttribute;
34
35 protected String messageKey;
36 protected String constraintText;
37 protected String summary;
38 protected String description;
39
40 protected Boolean required = Boolean.FALSE;
41
42 public String getName() {
43 return name;
44 }
45
46 /*
47 * name = name of attribute
48 */
49 public void setName(String name) {
50 if (StringUtils.isBlank(name)) {
51 throw new IllegalArgumentException("invalid (blank) name");
52 }
53 this.name = name;
54 }
55
56 public String getLabel() {
57 return label;
58 }
59
60 /**
61 * The label element is the field or collection name that will be shown on
62 * inquiry and maintenance screens. This will be overridden by presence of
63 * displayLabelAttribute element.
64 */
65 public void setLabel(String label) {
66 if (StringUtils.isBlank(label)) {
67 throw new IllegalArgumentException("invalid (blank) label");
68 }
69 this.label = label;
70 }
71
72 /**
73 * @return the shortLabel, or the label if no shortLabel has been set
74 */
75 public String getShortLabel() {
76 return (shortLabel != null) ? shortLabel : getLabel();
77 }
78
79 /**
80 * @return the shortLabel directly, without substituting in the label
81 */
82 protected String getDirectShortLabel() {
83 return shortLabel;
84 }
85
86 /**
87 * The shortLabel element is the field or collection name that will be used
88 * in applications when a shorter name (than the label element) is required.
89 * This will be overridden by presence of displayLabelAttribute element.
90 */
91 public void setShortLabel(String shortLabel) {
92 if (StringUtils.isBlank(shortLabel)) {
93 throw new IllegalArgumentException("invalid (blank) shortLabel");
94 }
95 this.shortLabel = shortLabel;
96 }
97
98 /**
99 * 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 }