1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.data.DataType;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.krad.data.metadata.DataObjectAttribute;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.datadictionary.validation.capability.ExistenceConstrainable;
24 import org.kuali.rice.krad.datadictionary.validation.capability.SimpleConstrainable;
25 import org.kuali.rice.krad.datadictionary.validation.constraint.SimpleConstraint;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27
28
29
30
31
32
33
34
35 public abstract class AttributeDefinitionBase extends DataDictionaryDefinitionBase implements ExistenceConstrainable,
36 SimpleConstrainable {
37
38 private static final long serialVersionUID = 1L;
39
40 protected String name;
41
42 protected String label;
43 protected String shortLabel;
44 protected String displayLabelAttribute;
45
46 protected String constraintText;
47 protected String summary;
48 protected String description;
49
50 protected SimpleConstraint simpleConstraint;
51
52 protected DataObjectAttribute dataObjectAttribute;
53
54 public AttributeDefinitionBase() {
55 super();
56 simpleConstraint = new SimpleConstraint();
57 }
58
59
60
61
62
63
64 @Override
65 @BeanTagAttribute(name="name")
66 public String getName() {
67 return name;
68 }
69
70
71
72
73
74
75 public void setName(String name) {
76 if (StringUtils.isBlank(name)) {
77 throw new IllegalArgumentException("invalid (blank) name");
78 }
79 this.name = name;
80 }
81
82
83
84
85
86
87
88
89 @BeanTagAttribute(name="label")
90 public String getLabel() {
91 if ( label != null ) {
92 return label;
93 }
94 if ( getDataObjectAttribute() != null ) {
95 return getDataObjectAttribute().getLabel();
96 }
97 if ( GlobalResourceLoader.isInitialized() && KRADServiceLocatorWeb.getUifDefaultingService() != null ) {
98 return KRADServiceLocatorWeb.getUifDefaultingService().deriveHumanFriendlyNameFromPropertyName( getName() );
99 }
100 return getName();
101 }
102
103
104
105
106
107
108 public void setLabel(String label) {
109 if (StringUtils.isBlank(label)) {
110 throw new IllegalArgumentException("invalid (blank) label");
111 }
112 this.label = label;
113 }
114
115
116
117
118 @BeanTagAttribute(name="shortLabel")
119 public String getShortLabel() {
120 if ( shortLabel != null ) {
121 return shortLabel;
122 }
123 if ( getDataObjectAttribute() != null ) {
124
125 if ( StringUtils.equals(getDataObjectAttribute().getLabel(), getDataObjectAttribute().getShortLabel())
126 && label != null ) {
127 return getLabel();
128 }
129 return getDataObjectAttribute().getShortLabel();
130 }
131 return getLabel();
132 }
133
134
135
136
137 protected String getDirectShortLabel() {
138 if ( shortLabel != null ) {
139 return shortLabel;
140 }
141 if ( getDataObjectAttribute() != null ) {
142 return getDataObjectAttribute().getShortLabel();
143 }
144 return "";
145 }
146
147
148
149
150
151
152 public void setShortLabel(String shortLabel) {
153 if (StringUtils.isBlank(shortLabel)) {
154 throw new IllegalArgumentException("invalid (blank) shortLabel");
155 }
156 this.shortLabel = shortLabel;
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170 @BeanTagAttribute(name="constraintText")
171 public String getConstraintText() {
172 return constraintText;
173 }
174
175
176
177
178
179
180 public void setConstraintText(String constraintText) {
181 this.constraintText = constraintText;
182 }
183
184
185
186
187
188
189
190 @BeanTagAttribute(name="summary")
191 public String getSummary() {
192 if ( summary != null ) {
193 return summary;
194 }
195 return "";
196 }
197
198
199
200
201
202 public void setSummary(String summary) {
203 this.summary = summary;
204 }
205
206
207
208
209
210
211
212 @BeanTagAttribute(name="description")
213 public String getDescription() {
214 if ( description != null ) {
215 return description;
216 }
217 if ( getDataObjectAttribute() != null ) {
218 return getDataObjectAttribute().getDescription();
219 }
220 return "";
221 }
222
223
224
225
226
227 public void setDescription(String description) {
228 this.description = description;
229 }
230
231 public String getDisplayLabelAttribute() {
232 if ( displayLabelAttribute != null ) {
233 return displayLabelAttribute;
234 }
235 if ( getDataObjectAttribute() != null ) {
236 return getDataObjectAttribute().getDisplayAttributeName();
237 }
238 return null;
239 }
240
241
242
243
244
245
246
247
248
249
250 public void setDisplayLabelAttribute(String displayLabelAttribute) {
251 this.displayLabelAttribute = displayLabelAttribute;
252 }
253
254
255
256
257
258
259 @Override
260 public SimpleConstraint getSimpleConstraint() {
261 return simpleConstraint;
262 }
263
264
265
266
267
268
269 public void setSimpleConstraint(SimpleConstraint simpleConstraint) {
270 this.simpleConstraint = simpleConstraint;
271 }
272
273
274
275
276
277
278 public void setRequired(Boolean required) {
279 this.simpleConstraint.setRequired(required);
280 }
281
282
283
284
285
286
287 @Override
288 @BeanTagAttribute(name="required")
289 public Boolean isRequired() {
290 if ( simpleConstraint.isRequired() != null ) {
291 return simpleConstraint.isRequired();
292 }
293 if ( getDataObjectAttribute() != null ) {
294 return getDataObjectAttribute().isRequired();
295 }
296 return Boolean.FALSE;
297 }
298
299
300 public DataObjectAttribute getDataObjectAttribute() {
301 return dataObjectAttribute;
302 }
303
304 public void setDataObjectAttribute(DataObjectAttribute dataObjectAttribute) {
305 this.dataObjectAttribute = dataObjectAttribute;
306 }
307 }