Coverage Report - org.kuali.rice.kns.datadictionary.control.ControlDefinitionBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ControlDefinitionBase
0%
0/84
0%
0/46
1.717
 
 1  
 /*
 2  
  * Copyright 2005-2007 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  
 
 17  
 package org.kuali.rice.kns.datadictionary.control;
 18  
 
 19  
 import org.apache.commons.lang.ClassUtils;
 20  
 import org.apache.commons.lang.builder.EqualsBuilder;
 21  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 22  
 import org.kuali.rice.kns.bo.BusinessObject;
 23  
 import org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase;
 24  
 import org.kuali.rice.kns.datadictionary.exception.ClassValidationException;
 25  
 import org.kuali.rice.kns.datadictionary.exception.CompletionException;
 26  
 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder;
 27  
 
 28  
 /**
 29  
  * A single HTML control definition in the DataDictionary, which contains information relating to the HTML control used to realize a
 30  
  * specific attribute. All types of controls are represented by an instance of this class; you have to call one of the is* methods
 31  
  * to figure out which of the other accessors should return useful values.
 32  
  *
 33  
  *
 34  
  */
 35  
 public abstract class ControlDefinitionBase extends DataDictionaryDefinitionBase implements ControlDefinition {
 36  
     private static final long serialVersionUID = 4372435175782501152L;
 37  
     
 38  
         protected boolean datePicker;
 39  
         protected boolean expandedTextArea;
 40  
     protected String script;
 41  
     protected String valuesFinderClass;
 42  
     protected String businessObjectClass;
 43  
     protected String keyAttribute;
 44  
     protected String labelAttribute;
 45  
     protected Boolean includeBlankRow;
 46  
     protected Boolean includeKeyInLabel;
 47  
     protected Integer size;
 48  
     protected Integer rows;
 49  
     protected Integer cols;
 50  
     protected boolean ranged;
 51  
 
 52  
 
 53  0
     public ControlDefinitionBase() {
 54  0
             ranged = true;
 55  0
     }
 56  
 
 57  
     public boolean isDatePicker() {
 58  0
         return datePicker;
 59  
     }
 60  
 
 61  
     /** Whether this control should have a date picker button next to the field.
 62  
      *  Valid for text fields.
 63  
      *  
 64  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setDatePicker(boolean)
 65  
      */
 66  
     public void setDatePicker(boolean datePicker) {
 67  0
         this.datePicker=datePicker;
 68  0
     }
 69  
     
 70  
     public boolean isExpandedTextArea() {
 71  0
         return expandedTextArea;
 72  
     }
 73  
 
 74  
     /** Whether this control should have a expanded text area button next to the field.
 75  
      *  Valid for textarea fields.
 76  
      *  
 77  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setExpandedTextArea(boolean)
 78  
      */
 79  
     public void setExpandedTextArea(boolean eTextArea) {
 80  0
         this.expandedTextArea=eTextArea;
 81  0
     }
 82  
 
 83  
     /**
 84  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isCheckbox()
 85  
      */
 86  
     public boolean isCheckbox() {
 87  0
         return false;
 88  
     }
 89  
 
 90  
     /**
 91  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isHidden()
 92  
      */
 93  
     public boolean isHidden() {
 94  0
         return false;
 95  
     }
 96  
 
 97  
     /**
 98  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isRadio()
 99  
      */
 100  
     public boolean isRadio() {
 101  0
         return false;
 102  
     }
 103  
 
 104  
     /**
 105  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isSelect()
 106  
      */
 107  
     public boolean isSelect() {
 108  0
         return false;
 109  
     }
 110  
     
 111  
     /**
 112  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isSelect()
 113  
      */
 114  
     public boolean isMultiselect() {
 115  0
         return false;
 116  
     }
 117  
 
 118  
     /**
 119  
      *
 120  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isApcSelect()
 121  
      */
 122  
 
 123  
     public boolean isApcSelect() {
 124  0
         return false;
 125  
     }
 126  
 
 127  
     /**
 128  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isText()
 129  
      */
 130  
     public boolean isText() {
 131  0
         return false;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isTextarea()
 136  
      */
 137  
     public boolean isTextarea() {
 138  0
         return false;
 139  
     }
 140  
 
 141  
     /**
 142  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isCurrency()
 143  
      */
 144  
     public boolean isCurrency() {
 145  0
         return false;
 146  
     }
 147  
 
 148  
     /**
 149  
      *
 150  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isKualiUser()
 151  
      */
 152  
     public boolean isKualiUser() {
 153  0
         return false;
 154  
     }
 155  
 
 156  
     /**
 157  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isWorkgroup()
 158  
      */
 159  
     public boolean isWorkflowWorkgroup() {
 160  0
         return false;
 161  
     }
 162  
 
 163  
     /**
 164  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isFile()
 165  
      */
 166  
     public boolean isFile() {
 167  0
         return false;
 168  
     }
 169  
 
 170  
     /**
 171  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isLookupHidden()
 172  
      */
 173  
     public boolean isLookupHidden() {
 174  0
         return false;
 175  
     }
 176  
 
 177  
     /**
 178  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isLookupReadonly()
 179  
      */
 180  
     public boolean isLookupReadonly() {
 181  0
         return false;
 182  
     }
 183  
     
 184  
     /**
 185  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isButton()
 186  
      */
 187  
     public boolean isButton() {
 188  0
         return false;
 189  
     }
 190  
     
 191  
     /**
 192  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isLink()
 193  
      */
 194  
     public boolean isLink() {
 195  0
         return false;
 196  
     }
 197  
     
 198  
 
 199  
     /**
 200  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setKeyValuesFinder(java.lang.String)
 201  
      */
 202  
     public void setValuesFinderClass(String valuesFinderClass) {
 203  0
         if (valuesFinderClass == null) {
 204  0
             throw new IllegalArgumentException("invalid (null) valuesFinderClass");
 205  
         }
 206  
 
 207  0
         this.valuesFinderClass = valuesFinderClass;
 208  0
     }
 209  
 
 210  
     /**
 211  
      * @return the businessObjectClass
 212  
      */
 213  
     public String getBusinessObjectClass() {
 214  0
         return this.businessObjectClass;
 215  
     }
 216  
 
 217  
     /**
 218  
      * Used by a PersistableBusinessObjectValuesFinder to automatically query and display a list
 219  
      * of business objects as part of a select list or set of radio buttons.
 220  
      * 
 221  
      * The keyAttribute, labelAttribute, and includeKeyInLabel are used with this property.
 222  
      * 
 223  
      * @param businessObjectClass the businessObjectClass to set
 224  
      */
 225  
     public void setBusinessObjectClass(String businessObjectClass) {
 226  0
         if (businessObjectClass == null) {
 227  0
             throw new IllegalArgumentException("invalid (null) businessObjectClass");
 228  
         }
 229  
 
 230  0
         this.businessObjectClass = businessObjectClass;
 231  0
     }
 232  
 
 233  
     /**
 234  
      * @return the includeBlankRow
 235  
      */
 236  
     public Boolean getIncludeBlankRow() {
 237  0
         return this.includeBlankRow;
 238  
     }
 239  
 
 240  
     /**
 241  
      * @return the includeBlankRow
 242  
      */
 243  
     public void setIncludeBlankRow(Boolean includeBlankRow) {
 244  0
         this.includeBlankRow = includeBlankRow;
 245  0
     }
 246  
 
 247  
     /**
 248  
      * @return the includeKeyInLabel
 249  
      */
 250  
     public Boolean getIncludeKeyInLabel() {
 251  0
         return this.includeKeyInLabel;
 252  
     }
 253  
 
 254  
     /**
 255  
      * Whether to include the key in the label for select lists and radio buttons.
 256  
      */
 257  
     public void setIncludeKeyInLabel(Boolean includeKeyInLabel) {
 258  0
         this.includeKeyInLabel = includeKeyInLabel;
 259  0
     }
 260  
 
 261  
     /**
 262  
      * @return the keyAttribute
 263  
      */
 264  
     public String getKeyAttribute() {
 265  0
         return this.keyAttribute;
 266  
     }
 267  
 
 268  
     /**
 269  
      * Attribute of the given businessObjectClass to use as the value of a select list 
 270  
      * or set of radio buttons. 
 271  
      */
 272  
     public void setKeyAttribute(String keyAttribute) {
 273  0
         this.keyAttribute = keyAttribute;
 274  0
     }
 275  
 
 276  
     /**
 277  
      * @return the labelAttribute
 278  
      */
 279  
     public String getLabelAttribute() {
 280  0
         return this.labelAttribute;
 281  
     }
 282  
 
 283  
     /**
 284  
      * Attribute of the given businessObjectClass to use as the displayed label on a select list 
 285  
      * or set of radio buttons. 
 286  
      */
 287  
     public void setLabelAttribute(String labelAttribute) {
 288  0
         this.labelAttribute = labelAttribute;
 289  0
     }
 290  
 
 291  
     /**
 292  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#getKeyValuesFinder()
 293  
      */
 294  
     public String getValuesFinderClass() {
 295  0
         return valuesFinderClass;
 296  
     }
 297  
 
 298  
     /**
 299  
      * Size of a text control.
 300  
      * 
 301  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setSize(int)
 302  
      */
 303  
     public void setSize(Integer size) {
 304  0
         this.size = size;
 305  0
     }
 306  
 
 307  
     /**
 308  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#getSize()
 309  
      */
 310  
     public Integer getSize() {
 311  0
         return size;
 312  
     }
 313  
 
 314  
     /**
 315  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#hasScript()
 316  
      */
 317  
     public boolean hasScript() {
 318  0
         return false;
 319  
     }
 320  
 
 321  
     /**
 322  
      * Number of rows to display on a text-area widget.
 323  
      * 
 324  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setRows(int)
 325  
      */
 326  
     public void setRows(Integer rows) {
 327  0
         this.rows = rows;
 328  0
     }
 329  
 
 330  
     /**
 331  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#getRows()
 332  
      */
 333  
     public Integer getRows() {
 334  0
         return rows;
 335  
     }
 336  
 
 337  
     /**
 338  
      * Number of columns to display on a text-area widget.
 339  
      * 
 340  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setCols(int)
 341  
      */
 342  
     public void setCols(Integer cols) {
 343  0
         this.cols = cols;
 344  0
     }
 345  
 
 346  
     /**
 347  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#getCols()
 348  
      */
 349  
     public Integer getCols() {
 350  0
         return cols;
 351  
     }
 352  
 
 353  
     /**
 354  
      * Directly validate simple fields.
 355  
      *
 356  
      * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 357  
      */
 358  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 359  0
         if (!isCheckbox() && !isHidden() && !isRadio() && !isSelect() && !isMultiselect() && !isApcSelect() && !isText() && !isTextarea() && !isCurrency() && !isKualiUser() && !isLookupHidden() && !isLookupReadonly() && !isWorkflowWorkgroup() && !isFile()&& !isButton() && !isLink()) {
 360  0
             throw new CompletionException("error validating " + rootBusinessObjectClass.getName() + " control: unknown control type in control definition (" + "" + ")");
 361  
         }
 362  0
         if (valuesFinderClass != null) {
 363  
                 try {
 364  0
                         Class valuesFinderClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getValuesFinderClass());
 365  0
                         if (!KeyValuesFinder.class.isAssignableFrom(valuesFinderClassObject)) {
 366  0
                                 throw new ClassValidationException("valuesFinderClass is not a valid instance of " + KeyValuesFinder.class.getName() + " instead was: " + valuesFinderClassObject.getName());
 367  
                         }
 368  0
                 } catch (ClassNotFoundException e) {
 369  0
                         throw new ClassValidationException("valuesFinderClass could not be found: " + getValuesFinderClass(), e);
 370  0
                 }
 371  
         }
 372  0
         if (businessObjectClass != null) {
 373  
                 try {
 374  0
                         Class businessObjectClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getBusinessObjectClass());
 375  0
                         if (!BusinessObject.class.isAssignableFrom(businessObjectClassObject)) {
 376  0
                                 throw new ClassValidationException("businessObjectClass is not a valid instance of " + BusinessObject.class.getName() + " instead was: " + businessObjectClassObject.getName());
 377  
                         }
 378  0
                 } catch (ClassNotFoundException e) {
 379  0
                         throw new ClassValidationException("businessObjectClass could not be found: " + getBusinessObjectClass(), e);
 380  0
                 }
 381  
         }
 382  0
     }
 383  
 
 384  
     /**
 385  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#getScript()
 386  
      */
 387  
     public String getScript() {
 388  0
         return script;
 389  
     }
 390  
 
 391  
     /**
 392  
      * JavaScript script to run when a select control's value is changed.
 393  
      * 
 394  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#setScript()
 395  
      */
 396  
     public void setScript(String script) {
 397  0
         this.script = script;
 398  0
     }
 399  
     
 400  
     /**
 401  
      * @see org.kuali.rice.kns.datadictionary.control.ControlDefinition#isRanged()
 402  
      */
 403  
     public boolean isRanged() {
 404  0
                 return this.ranged;
 405  
         }
 406  
 
 407  
     /**
 408  
      * Sets the control as a ranged (from and to) date field if true, or a single date field if false
 409  
      * 
 410  
      * @param ranged boolean true for a ranged control, false for a single date field
 411  
      */
 412  
         public void setRanged(boolean ranged) {
 413  0
                 this.ranged = ranged;
 414  0
         }
 415  
 
 416  
         /**
 417  
      * @see java.lang.Object#equals(Object)
 418  
      */
 419  
     public boolean equals(Object object) {
 420  0
             if ( !(object instanceof ControlDefinitionBase) ) {
 421  0
                     return false;
 422  
             }
 423  0
             ControlDefinitionBase rhs = (ControlDefinitionBase)object;
 424  0
             return new EqualsBuilder()
 425  
                     .append( this.cols, rhs.cols )
 426  
                             .append( this.businessObjectClass, rhs.businessObjectClass )
 427  
                             .append( this.valuesFinderClass, rhs.valuesFinderClass )
 428  
                             .append( this.rows, rhs.rows )
 429  
                             .append( this.script, rhs.script )
 430  
                             .append( this.size, rhs.size )
 431  
                             .append( this.datePicker, rhs.datePicker )
 432  
                             .append( this.ranged, rhs.ranged )
 433  
                             .append( this.labelAttribute,rhs.labelAttribute )
 434  
                             .append( this.includeKeyInLabel, rhs.includeKeyInLabel )
 435  
                             .append( this.keyAttribute, rhs.keyAttribute )
 436  
                             .isEquals();
 437  
     }
 438  
     
 439  
     
 440  
 }