Coverage Report - org.kuali.rice.krad.datadictionary.ExternalizableAttributeDefinitionProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
ExternalizableAttributeDefinitionProxy
0%
0/92
0%
0/50
2.348
 
 1  
 /*
 2  
  * Copyright 2007-2008 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  
 /**
 19  
  * A single attribute definition in the DataDictionary, which contains information relating to the display, validation, and general
 20  
  * maintenance of a specific attribute of an entry.
 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  
  * A single attribute definition in the DataDictionary, which contains
 34  
  * information relating to the display, validation, and general maintenance of a
 35  
  * specific attribute of an entry.
 36  
  * 
 37  
  * 
 38  
  */
 39  
 public class ExternalizableAttributeDefinitionProxy extends AttributeDefinition {
 40  
         private static final long serialVersionUID = -3204870440281417429L;
 41  
 
 42  
         // logger
 43  0
         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  
          * Constructs an AttributeReferenceDefinition
 52  
          */
 53  0
         public ExternalizableAttributeDefinitionProxy() {
 54  0
                 LOG.debug("creating new ExternalizableAttributeDefinitionProxy");
 55  0
         }
 56  
 
 57  
         public void setSourceExternalizableBusinessObjectInterface(
 58  
                         String sourceClassName) {
 59  0
                 if (StringUtils.isBlank(sourceClassName)) {
 60  0
                         throw new IllegalArgumentException(
 61  
                                         "invalid (blank) sourceClassName");
 62  
                 }
 63  
 
 64  0
                 this.sourceExternalizableBusinessObjectInterface = sourceClassName;
 65  0
         }
 66  
 
 67  
         public String getSourceExternalizableBusinessObjectInterface() {
 68  0
                 return this.sourceExternalizableBusinessObjectInterface;
 69  
         }
 70  
 
 71  
         public void setSourceAttributeName(String sourceAttributeName) {
 72  0
                 if (StringUtils.isBlank(sourceAttributeName)) {
 73  0
                         throw new IllegalArgumentException(
 74  
                                         "invalid (blank) sourceAttributeName");
 75  
                 }
 76  
 
 77  0
                 this.sourceAttributeName = sourceAttributeName;
 78  0
         }
 79  
 
 80  
         public String getSourceAttributeName() {
 81  0
                 return this.sourceAttributeName;
 82  
         }
 83  
 
 84  
         /**
 85  
          * @return AttributeDefinition acting as delegate for this
 86  
          *         AttributeReferenceDefinition
 87  
          */
 88  
         AttributeDefinition getDelegate() {
 89  0
                 BusinessObjectEntry delegateEntry = null;
 90  0
                 if ( delegate == null ) {
 91  
                         try {
 92  0
                                 delegateEntry = KRADServiceLocatorWeb
 93  
                                                 .getKualiModuleService()
 94  
                                                 .getResponsibleModuleService(
 95  
                                                                 Class
 96  
                                                                                 .forName(getSourceExternalizableBusinessObjectInterface()))
 97  
                                                 .getExternalizableBusinessObjectDictionaryEntry(
 98  
                                                                 Class
 99  
                                                                                 .forName(getSourceExternalizableBusinessObjectInterface()));
 100  0
                         } catch (ClassNotFoundException e) {
 101  0
                                 LOG.error("Unable to get delegate entry for sourceExternalizableBusinessObjectInterface",e);
 102  0
                         }
 103  
         
 104  0
                         if (delegateEntry == null) {
 105  0
                                 throw new CompletionException(
 106  
                                                 "no BusinessObjectEntry exists for sourceClassName '"
 107  
                                                                 + getSourceExternalizableBusinessObjectInterface()
 108  
                                                                 + "'");
 109  
                         }
 110  0
                         delegate = delegateEntry
 111  
                                         .getAttributeDefinition(getSourceAttributeName());
 112  0
                         if (delegate == null) {
 113  0
                                 throw new CompletionException(
 114  
                                                 "no AttributeDefnintion exists for sourceAttributeName '"
 115  
                                                                 + getSourceExternalizableBusinessObjectInterface()
 116  
                                                                 + "." + getSourceAttributeName() + "'");
 117  
                         }
 118  
                 }
 119  
 
 120  0
                 return delegate;
 121  
         }
 122  
 
 123  
         /**
 124  
          * Sets the given AttributeDefinition as the delegate for this instance
 125  
          * 
 126  
          * @param delegate
 127  
          */
 128  
         void setDelegate(AttributeDefinition delegate) {
 129  0
                 if (delegate == null) {
 130  0
                         throw new IllegalArgumentException("invalid (null) delegate");
 131  
                 }
 132  
 
 133  0
                 this.delegate = delegate;
 134  0
         }
 135  
 
 136  
         /**
 137  
          * If forceUppercase wasn't set on this instance, use the value from its
 138  
          * delegate.
 139  
          * 
 140  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getForceUppercase()
 141  
          */
 142  
         public Boolean getForceUppercase() {
 143  0
                 Boolean value = super.getForceUppercase();
 144  0
                 if (value == null) {
 145  0
                         value = getDelegate().getForceUppercase();
 146  
                 }
 147  
 
 148  0
                 return value;
 149  
         }
 150  
 
 151  
         /**
 152  
          * If name wasn't set on this instance, use the value from its delegate.
 153  
          * 
 154  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getName()
 155  
          */
 156  
         public String getName() {
 157  0
                 String name = super.getName();
 158  0
                 if (name == null) {
 159  0
                         name = getDelegate().getName();
 160  
                 }
 161  
 
 162  0
                 return name;
 163  
         }
 164  
 
 165  
         /**
 166  
          * If label wasn't set on this instance, use the value from its delegate.
 167  
          * 
 168  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getLabel()
 169  
          */
 170  
         public String getLabel() {
 171  0
                 String label = super.getLabel();
 172  
 
 173  0
                 if (label == null) {
 174  0
                         label = getDelegate().getLabel();
 175  
                 }
 176  
 
 177  0
                 return label;
 178  
         }
 179  
 
 180  
         /**
 181  
          * If shortlabel wasn't set on this instance, use the value from its
 182  
          * delegate.
 183  
          * 
 184  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getShortLabel()
 185  
          */
 186  
         public String getShortLabel() {
 187  0
                 String shortLabel = super.getDirectShortLabel();
 188  0
                 if (shortLabel == null) {
 189  0
                         shortLabel = getDelegate().getShortLabel();
 190  
                 }
 191  
 
 192  0
                 return shortLabel;
 193  
         }
 194  
 
 195  
         /**
 196  
          * If maxLength wasn't set on this instance, use the value from its
 197  
          * delegate.
 198  
          * 
 199  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getMaxLength()
 200  
          */
 201  
         public Integer getMaxLength() {
 202  0
                 Integer maxLength = super.getMaxLength();
 203  0
                 if (maxLength == null) {
 204  0
                         maxLength = getDelegate().getMaxLength();
 205  
                 }
 206  
 
 207  0
                 return maxLength;
 208  
         }
 209  
 
 210  
         /**
 211  
          * @return true if a validationPattern is available, directly or indirectly
 212  
          * 
 213  
          * @see org.kuali.core.datadictionary.AttributeDefinition#hasValidationPattern()
 214  
          */
 215  
         public boolean hasValidationPattern() {
 216  0
                 return (getValidationPattern() != null);
 217  
         }
 218  
 
 219  
         /**
 220  
          * If validationPattern wasn't set on this instance, use the value from its
 221  
          * delegate.
 222  
          * 
 223  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getValidationPattern()
 224  
          */
 225  
         public ValidationPattern getValidationPattern() {
 226  0
                 ValidationPattern validationPattern = super.getValidationPattern();
 227  0
                 if (validationPattern == null) {
 228  0
                         validationPattern = getDelegate().getValidationPattern();
 229  
                 }
 230  
 
 231  0
                 return validationPattern;
 232  
         }
 233  
 
 234  
         /**
 235  
          * If required wasn't set on this instance, use the value from its delegate.
 236  
          * 
 237  
          * @see org.kuali.core.datadictionary.AttributeDefinition#isRequired()
 238  
          */
 239  
         public Boolean isRequired() {
 240  0
                 Boolean required = super.isRequired();
 241  0
                 if (required == null) {
 242  0
                         required = getDelegate().isRequired();
 243  
                 }
 244  
 
 245  0
                 return required;
 246  
         }
 247  
 
 248  
         /**
 249  
          * If control wasn't set on this instance, use the value from its delegate.
 250  
          * 
 251  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getControl()
 252  
          */
 253  
         public ControlDefinition getControl() {
 254  0
                 ControlDefinition control = super.getControl();
 255  0
                 if (control == null) {
 256  0
                         control = getDelegate().getControl();
 257  
                 }
 258  
 
 259  0
                 return control;
 260  
         }
 261  
 
 262  
         /**
 263  
          * If summary wasn't set on this instance, use the value from its delegate.
 264  
          * 
 265  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getSummary()
 266  
          */
 267  
         public String getSummary() {
 268  0
                 String summary = super.getSummary();
 269  0
                 if (summary == null) {
 270  0
                         summary = getDelegate().getSummary();
 271  
                 }
 272  
 
 273  0
                 return summary;
 274  
         }
 275  
 
 276  
         /**
 277  
          * If description wasn't set on this instance, use the value from its
 278  
          * delegate.
 279  
          * 
 280  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getDescription()
 281  
          */
 282  
         public String getDescription() {
 283  0
                 String description = super.getDescription();
 284  0
                 if (description == null) {
 285  0
                         description = getDelegate().getDescription();
 286  
                 }
 287  
 
 288  0
                 return description;
 289  
         }
 290  
 
 291  
         /**
 292  
          * @return true if a formatterClass is available, directly or indirectly
 293  
          * 
 294  
          * @see org.kuali.core.datadictionary.AttributeDefinition#hasFormatterClass()
 295  
          */
 296  
         public boolean hasFormatterClass() {
 297  0
                 return (getFormatterClass() != null);
 298  
         }
 299  
 
 300  
         /**
 301  
          * If a formatterClass wasn't set for this instance, use the value from its
 302  
          * delegate.
 303  
          * 
 304  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getFormatterClass()
 305  
          */
 306  
         public String getFormatterClass() {
 307  0
                 String formatterClass = super.getFormatterClass();
 308  0
                 if (formatterClass == null) {
 309  0
                         formatterClass = getDelegate().getFormatterClass();
 310  
                 }
 311  
 
 312  0
                 return formatterClass;
 313  
         }
 314  
 
 315  
         /**
 316  
          * @see org.kuali.core.datadictionary.AttributeDefinition#getDisplayLabelAttribute()
 317  
          */
 318  
         @Override
 319  
         public String getDisplayLabelAttribute() {
 320  0
                 String displayLabelAttribute = super.getDisplayLabelAttribute();
 321  0
                 if (StringUtils.isBlank(displayLabelAttribute)) {
 322  0
                         displayLabelAttribute = getDelegate().getDisplayLabelAttribute();
 323  
                 }
 324  0
                 return displayLabelAttribute;
 325  
         }
 326  
 
 327  
         /**
 328  
          * Validate the fields associated with locating the delegate. Other
 329  
          * validation must be deferred until the delegate class has been assigned.
 330  
          * 
 331  
          * @see org.kuali.core.datadictionary.DataDictionaryEntry#completeValidation()
 332  
          */
 333  
         @Override
 334  
         public void completeValidation(Class rootObjectClass, Class otherObjectClass) {
 335  0
                 if (StringUtils.isBlank(sourceExternalizableBusinessObjectInterface)) {
 336  0
                         throw new IllegalArgumentException(
 337  
                                         "invalid (blank) sourceClassName for attribute '"
 338  
                                                         + rootObjectClass.getName() + "." + getName() + "'");
 339  
                 }
 340  0
                 if (StringUtils.isBlank(sourceAttributeName)) {
 341  0
                         throw new IllegalArgumentException(
 342  
                                         "invalid (blank) sourceAttributeName for attribute '"
 343  
                                                         + rootObjectClass.getName() + "." + getName() + "'");
 344  
                 }
 345  0
                 if ( DataDictionary.validateEBOs ) {
 346  0
                         getDelegate(); // forces validation
 347  0
                         super.completeValidation(rootObjectClass, otherObjectClass);
 348  
                 }
 349  0
         }
 350  
 
 351  
         /**
 352  
          * @see java.lang.Object#toString()
 353  
          */
 354  
         public String toString() {
 355  0
                 String name = super.getName();
 356  
 
 357  
                 // workaround for the mysterious,
 358  
                 // still-unreproducible-on-my-machine, null delegate exception on
 359  
                 // Tomcat startup
 360  0
                 if ((name == null) && (getDelegate() != null)) {
 361  0
                         name = getDelegate().getName();
 362  
                 }
 363  0
                 return "AttributeReferenceDefinition for attribute " + name;
 364  
         }
 365  
 }