1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18
19
20
21
22
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
28 import org.kuali.rice.krad.datadictionary.exception.CompletionException;
29 import org.kuali.rice.krad.datadictionary.validation.ValidationPattern;
30 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
31
32
33
34
35
36
37
38
39 public class ExternalizableAttributeDefinitionProxy extends AttributeDefinition {
40 private static final long serialVersionUID = -3204870440281417429L;
41
42
43 private static Log LOG = LogFactory
44 .getLog(ExternalizableAttributeDefinitionProxy.class);
45
46 private String sourceExternalizableBusinessObjectInterface;
47 private String sourceAttributeName;
48 private AttributeDefinition delegate;
49
50
51
52
53 public ExternalizableAttributeDefinitionProxy() {
54 LOG.debug("creating new ExternalizableAttributeDefinitionProxy");
55 }
56
57 public void setSourceExternalizableBusinessObjectInterface(
58 String sourceClassName) {
59 if (StringUtils.isBlank(sourceClassName)) {
60 throw new IllegalArgumentException(
61 "invalid (blank) sourceClassName");
62 }
63
64 this.sourceExternalizableBusinessObjectInterface = sourceClassName;
65 }
66
67 public String getSourceExternalizableBusinessObjectInterface() {
68 return this.sourceExternalizableBusinessObjectInterface;
69 }
70
71 public void setSourceAttributeName(String sourceAttributeName) {
72 if (StringUtils.isBlank(sourceAttributeName)) {
73 throw new IllegalArgumentException(
74 "invalid (blank) sourceAttributeName");
75 }
76
77 this.sourceAttributeName = sourceAttributeName;
78 }
79
80 public String getSourceAttributeName() {
81 return this.sourceAttributeName;
82 }
83
84
85
86
87
88 AttributeDefinition getDelegate() {
89 BusinessObjectEntry delegateEntry = null;
90 if ( delegate == null ) {
91 try {
92 delegateEntry = KRADServiceLocatorWeb
93 .getKualiModuleService()
94 .getResponsibleModuleService(
95 Class
96 .forName(getSourceExternalizableBusinessObjectInterface()))
97 .getExternalizableBusinessObjectDictionaryEntry(
98 Class
99 .forName(getSourceExternalizableBusinessObjectInterface()));
100 } catch (ClassNotFoundException e) {
101 LOG.error("Unable to get delegate entry for sourceExternalizableBusinessObjectInterface",e);
102 }
103
104 if (delegateEntry == null) {
105 throw new CompletionException(
106 "no BusinessObjectEntry exists for sourceClassName '"
107 + getSourceExternalizableBusinessObjectInterface()
108 + "'");
109 }
110 delegate = delegateEntry
111 .getAttributeDefinition(getSourceAttributeName());
112 if (delegate == null) {
113 throw new CompletionException(
114 "no AttributeDefnintion exists for sourceAttributeName '"
115 + getSourceExternalizableBusinessObjectInterface()
116 + "." + getSourceAttributeName() + "'");
117 }
118 }
119
120 return delegate;
121 }
122
123
124
125
126
127
128 void setDelegate(AttributeDefinition delegate) {
129 if (delegate == null) {
130 throw new IllegalArgumentException("invalid (null) delegate");
131 }
132
133 this.delegate = delegate;
134 }
135
136
137
138
139
140
141
142 public Boolean getForceUppercase() {
143 Boolean value = super.getForceUppercase();
144 if (value == null) {
145 value = getDelegate().getForceUppercase();
146 }
147
148 return value;
149 }
150
151
152
153
154
155
156 public String getName() {
157 String name = super.getName();
158 if (name == null) {
159 name = getDelegate().getName();
160 }
161
162 return name;
163 }
164
165
166
167
168
169
170 public String getLabel() {
171 String label = super.getLabel();
172
173 if (label == null) {
174 label = getDelegate().getLabel();
175 }
176
177 return label;
178 }
179
180
181
182
183
184
185
186 public String getShortLabel() {
187 String shortLabel = super.getDirectShortLabel();
188 if (shortLabel == null) {
189 shortLabel = getDelegate().getShortLabel();
190 }
191
192 return shortLabel;
193 }
194
195
196
197
198
199
200
201 public Integer getMaxLength() {
202 Integer maxLength = super.getMaxLength();
203 if (maxLength == null) {
204 maxLength = getDelegate().getMaxLength();
205 }
206
207 return maxLength;
208 }
209
210
211
212
213
214
215 public boolean hasValidationPattern() {
216 return (getValidationPattern() != null);
217 }
218
219
220
221
222
223
224
225 public ValidationPattern getValidationPattern() {
226 ValidationPattern validationPattern = super.getValidationPattern();
227 if (validationPattern == null) {
228 validationPattern = getDelegate().getValidationPattern();
229 }
230
231 return validationPattern;
232 }
233
234
235
236
237
238
239 public Boolean isRequired() {
240 Boolean required = super.isRequired();
241 if (required == null) {
242 required = getDelegate().isRequired();
243 }
244
245 return required;
246 }
247
248
249
250
251
252
253 public ControlDefinition getControl() {
254 ControlDefinition control = super.getControl();
255 if (control == null) {
256 control = getDelegate().getControl();
257 }
258
259 return control;
260 }
261
262
263
264
265
266
267 public String getSummary() {
268 String summary = super.getSummary();
269 if (summary == null) {
270 summary = getDelegate().getSummary();
271 }
272
273 return summary;
274 }
275
276
277
278
279
280
281
282 public String getDescription() {
283 String description = super.getDescription();
284 if (description == null) {
285 description = getDelegate().getDescription();
286 }
287
288 return description;
289 }
290
291
292
293
294
295
296 public boolean hasFormatterClass() {
297 return (getFormatterClass() != null);
298 }
299
300
301
302
303
304
305
306 public String getFormatterClass() {
307 String formatterClass = super.getFormatterClass();
308 if (formatterClass == null) {
309 formatterClass = getDelegate().getFormatterClass();
310 }
311
312 return formatterClass;
313 }
314
315
316
317
318 @Override
319 public String getDisplayLabelAttribute() {
320 String displayLabelAttribute = super.getDisplayLabelAttribute();
321 if (StringUtils.isBlank(displayLabelAttribute)) {
322 displayLabelAttribute = getDelegate().getDisplayLabelAttribute();
323 }
324 return displayLabelAttribute;
325 }
326
327
328
329
330
331
332
333 @Override
334 public void completeValidation(Class rootObjectClass, Class otherObjectClass) {
335 if (StringUtils.isBlank(sourceExternalizableBusinessObjectInterface)) {
336 throw new IllegalArgumentException(
337 "invalid (blank) sourceClassName for attribute '"
338 + rootObjectClass.getName() + "." + getName() + "'");
339 }
340 if (StringUtils.isBlank(sourceAttributeName)) {
341 throw new IllegalArgumentException(
342 "invalid (blank) sourceAttributeName for attribute '"
343 + rootObjectClass.getName() + "." + getName() + "'");
344 }
345 if ( DataDictionary.validateEBOs ) {
346 getDelegate();
347 super.completeValidation(rootObjectClass, otherObjectClass);
348 }
349 }
350
351
352
353
354 public String toString() {
355 String name = super.getName();
356
357
358
359
360 if ((name == null) && (getDelegate() != null)) {
361 name = getDelegate().getName();
362 }
363 return "AttributeReferenceDefinition for attribute " + name;
364 }
365 }