View Javadoc

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.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
22  import org.kuali.rice.krad.datadictionary.exception.CompletionException;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25  import org.kuali.rice.krad.datadictionary.validation.ValidationPattern;
26  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27  
28  /**
29   * A single attribute definition in the DataDictionary, which contains
30   * information relating to the display, validation, and general maintenance of a
31   * specific attribute of an entry.
32   */
33  @BeanTag(name = "externalizableAttributeDefinitionProxy-bean")
34  public class ExternalizableAttributeDefinitionProxy extends AttributeDefinition {
35      private static final long serialVersionUID = -3204870440281417429L;
36  
37      // logger
38      private static Log LOG = LogFactory.getLog(ExternalizableAttributeDefinitionProxy.class);
39  
40      private String sourceExternalizableBusinessObjectInterface;
41      private String sourceAttributeName;
42      private AttributeDefinition delegate;
43  
44      /**
45       * Constructs an AttributeReferenceDefinition
46       */
47      public ExternalizableAttributeDefinitionProxy() {
48          LOG.debug("creating new ExternalizableAttributeDefinitionProxy");
49      }
50  
51      public void setSourceExternalizableBusinessObjectInterface(String sourceClassName) {
52          if (StringUtils.isBlank(sourceClassName)) {
53              throw new IllegalArgumentException("invalid (blank) sourceClassName");
54          }
55  
56          this.sourceExternalizableBusinessObjectInterface = sourceClassName;
57      }
58  
59      @BeanTagAttribute(name = "sourceExternalizableBusinessObjectInterface")
60      public String getSourceExternalizableBusinessObjectInterface() {
61          return this.sourceExternalizableBusinessObjectInterface;
62      }
63  
64      public void setSourceAttributeName(String sourceAttributeName) {
65          if (StringUtils.isBlank(sourceAttributeName)) {
66              throw new IllegalArgumentException("invalid (blank) sourceAttributeName");
67          }
68  
69          this.sourceAttributeName = sourceAttributeName;
70      }
71  
72      @BeanTagAttribute(name = "sourceAttributeName")
73      public String getSourceAttributeName() {
74          return this.sourceAttributeName;
75      }
76  
77      /**
78       * @return AttributeDefinition acting as delegate for this
79       *         AttributeReferenceDefinition
80       */
81      @BeanTagAttribute(name = "delegate", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
82      AttributeDefinition getDelegate() {
83          BusinessObjectEntry delegateEntry = null;
84          if (delegate == null) {
85              try {
86                  delegateEntry = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(Class.forName(
87                          getSourceExternalizableBusinessObjectInterface()))
88                          .getExternalizableBusinessObjectDictionaryEntry(Class.forName(
89                                  getSourceExternalizableBusinessObjectInterface()));
90              } catch (ClassNotFoundException e) {
91                  LOG.error("Unable to get delegate entry for sourceExternalizableBusinessObjectInterface", e);
92              }
93  
94              if (delegateEntry == null) {
95                  throw new CompletionException("no BusinessObjectEntry exists for sourceClassName '"
96                          + getSourceExternalizableBusinessObjectInterface()
97                          + "'");
98              }
99              delegate = delegateEntry.getAttributeDefinition(getSourceAttributeName());
100             if (delegate == null) {
101                 throw new CompletionException("no AttributeDefnintion exists for sourceAttributeName '"
102                         + getSourceExternalizableBusinessObjectInterface()
103                         + "."
104                         + getSourceAttributeName()
105                         + "'");
106             }
107         }
108 
109         return delegate;
110     }
111 
112     /**
113      * Sets the given AttributeDefinition as the delegate for this instance
114      *
115      * @param delegate
116      */
117     void setDelegate(AttributeDefinition delegate) {
118         if (delegate == null) {
119             throw new IllegalArgumentException("invalid (null) delegate");
120         }
121 
122         this.delegate = delegate;
123     }
124 
125     /**
126      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getForceUppercase()
127      */
128     public Boolean getForceUppercase() {
129         Boolean value = super.getForceUppercase();
130         if (value == null) {
131             value = getDelegate().getForceUppercase();
132         }
133 
134         return value;
135     }
136 
137     /**
138      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getName()
139      */
140     public String getName() {
141         String name = super.getName();
142         if (name == null) {
143             name = getDelegate().getName();
144         }
145 
146         return name;
147     }
148 
149     /**
150      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getLabel()
151      */
152     public String getLabel() {
153         String label = super.getLabel();
154 
155         if (label == null) {
156             label = getDelegate().getLabel();
157         }
158 
159         return label;
160     }
161 
162     /**
163      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getShortLabel()
164      */
165     public String getShortLabel() {
166         String shortLabel = super.getDirectShortLabel();
167         if (shortLabel == null) {
168             shortLabel = getDelegate().getShortLabel();
169         }
170 
171         return shortLabel;
172     }
173 
174     /**
175      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getMaxLength()
176      */
177     public Integer getMaxLength() {
178         Integer maxLength = super.getMaxLength();
179         if (maxLength == null) {
180             maxLength = getDelegate().getMaxLength();
181         }
182 
183         return maxLength;
184     }
185 
186     /**
187      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#hasValidationPattern()
188      */
189     public boolean hasValidationPattern() {
190         return (getValidationPattern() != null);
191     }
192 
193     /**
194      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getValidationPattern()
195      */
196     public ValidationPattern getValidationPattern() {
197         ValidationPattern validationPattern = super.getValidationPattern();
198         if (validationPattern == null) {
199             validationPattern = getDelegate().getValidationPattern();
200         }
201 
202         return validationPattern;
203     }
204 
205     /**
206      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#isRequired()
207      */
208     public Boolean isRequired() {
209         Boolean required = super.isRequired();
210         if (required == null) {
211             required = getDelegate().isRequired();
212         }
213 
214         return required;
215     }
216 
217     /**
218      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getControl()
219      */
220     public ControlDefinition getControl() {
221         ControlDefinition control = super.getControl();
222         if (control == null) {
223             control = getDelegate().getControl();
224         }
225 
226         return control;
227     }
228 
229     /**
230      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getSummary()
231      */
232     public String getSummary() {
233         String summary = super.getSummary();
234         if (summary == null) {
235             summary = getDelegate().getSummary();
236         }
237 
238         return summary;
239     }
240 
241     /**
242      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getDescription()
243      */
244     public String getDescription() {
245         String description = super.getDescription();
246         if (description == null) {
247             description = getDelegate().getDescription();
248         }
249 
250         return description;
251     }
252 
253     /**
254      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#hasFormatterClass()
255      */
256     public boolean hasFormatterClass() {
257         return (getFormatterClass() != null);
258     }
259 
260     /**
261      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getFormatterClass()
262      */
263     public String getFormatterClass() {
264         String formatterClass = super.getFormatterClass();
265         if (formatterClass == null) {
266             formatterClass = getDelegate().getFormatterClass();
267         }
268 
269         return formatterClass;
270     }
271 
272     /**
273      * @see org.kuali.rice.krad.datadictionary.AttributeDefinition#getDisplayLabelAttribute()
274      */
275     @Override
276     public String getDisplayLabelAttribute() {
277         String displayLabelAttribute = super.getDisplayLabelAttribute();
278         if (StringUtils.isBlank(displayLabelAttribute)) {
279             displayLabelAttribute = getDelegate().getDisplayLabelAttribute();
280         }
281         return displayLabelAttribute;
282     }
283 
284     /**
285      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation()
286      */
287     @Override
288     public void completeValidation(Class rootObjectClass, Class otherObjectClass) {
289         if (StringUtils.isBlank(sourceExternalizableBusinessObjectInterface)) {
290             throw new IllegalArgumentException("invalid (blank) sourceClassName for attribute '"
291                     + rootObjectClass.getName()
292                     + "."
293                     + getName()
294                     + "'");
295         }
296         if (StringUtils.isBlank(sourceAttributeName)) {
297             throw new IllegalArgumentException("invalid (blank) sourceAttributeName for attribute '"
298                     + rootObjectClass.getName()
299                     + "."
300                     + getName()
301                     + "'");
302         }
303         if (DataDictionary.validateEBOs) {
304             getDelegate(); // forces validation
305             super.completeValidation(rootObjectClass, otherObjectClass);
306         }
307     }
308 
309     /**
310      * @see java.lang.Object#toString()
311      */
312     public String toString() {
313         String name = super.getName();
314 
315         // workaround for the mysterious,
316         // still-unreproducible-on-my-machine, null delegate exception on
317         // Tomcat startup
318         if ((name == null) && (getDelegate() != null)) {
319             name = getDelegate().getName();
320         }
321         return "AttributeReferenceDefinition for attribute " + name;
322     }
323 }