Coverage Report - org.kuali.rice.kns.datadictionary.ApcRuleDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
ApcRuleDefinition
0%
0/34
0%
0/14
2.077
 
 1  
 /*
 2  
  * Copyright 2006-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.kns.datadictionary;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
 20  
 
 21  
 /**
 22  
     The apcRule element is used to specifiy legal values
 23  
     for an attribute.  This is done by specifiying the key
 24  
     to the System Parameters table that indicates
 25  
     the allowable values.
 26  
 
 27  
     JSTL: apcRules are Maps with the following keys:
 28  
     * attributeName (String)
 29  
     * parameterNamespace (String)
 30  
     * parameterDetailType (String)
 31  
     * parameterName (String)
 32  
     * errorMessage (String) a property key usually defined in ApplicationResources.properties
 33  
  */
 34  
 public class ApcRuleDefinition extends DataDictionaryDefinitionBase {
 35  
     private static final long serialVersionUID = 8600032669267029028L;
 36  
     
 37  
         protected String attributeName;
 38  
     protected String parameterNamespace;
 39  
     protected String parameterDetailType;
 40  
     protected String parameterName;
 41  
     protected String errorMessage;
 42  
 
 43  
 
 44  0
     public ApcRuleDefinition() {
 45  0
     }
 46  
 
 47  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 48  
         
 49  
         // make sure the attributeName is actually a property of the BO
 50  0
         if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeName)) {
 51  0
             throw new AttributeValidationException("unable to find attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "'" );
 52  
         }
 53  
 
 54  
         // make sure that the member reference by attributeName is actually a string
 55  0
         Class attributeClass = DataDictionary.getAttributeClass(rootBusinessObjectClass, attributeName);
 56  0
         if (!attributeClass.equals(String.class)) {
 57  0
             throw new AttributeValidationException("the attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' is of type '" + attributeClass.getName() + "'. These attributes may only be string." );
 58  
         }
 59  
 
 60  
 
 61  0
     }
 62  
 
 63  
     public String getParameterNamespace() {
 64  0
         return parameterNamespace;
 65  
     }
 66  
 
 67  
     public void setParameterNamespace(String parameterNamespace) {
 68  0
         if (StringUtils.isBlank(parameterNamespace)) {
 69  0
             throw new IllegalArgumentException("invalid (blank) parameterNamespace");
 70  
         }
 71  0
         this.parameterNamespace = parameterNamespace;
 72  0
     }
 73  
 
 74  
     public String getParameterName() {
 75  0
         return parameterName;
 76  
     }
 77  
     
 78  
     /**
 79  
 
 80  
      * attributeName is the name of an attribute for
 81  
          which the rule applies
 82  
 
 83  
      * parameterNamespace, parameterDetailType, and parameterName identify the parameter
 84  
 
 85  
      * errorMessage is the text that is to be displayed when
 86  
          the error is detected.
 87  
       */
 88  
     void setParameterName(String parameterName) {
 89  0
         if (StringUtils.isBlank(parameterName)) {
 90  0
             throw new IllegalArgumentException("invalid (blank) parameterName");
 91  
         }
 92  0
         this.parameterName = parameterName;
 93  0
     }
 94  
 
 95  
     public String getAttributeName() {
 96  0
         return attributeName;
 97  
     }
 98  
 
 99  
     /**
 100  
 
 101  
     * attributeName is the name of an attribute for
 102  
         which the rule applies
 103  
 
 104  
     * parameterNamespace, parameterDetailType, and parameterName identify the parameter
 105  
 
 106  
     * errorMessage is the text that is to be displayed when
 107  
         the error is detected.
 108  
      */
 109  
     public void setAttributeName(String attributeName) {
 110  0
         if (StringUtils.isBlank(attributeName)) {
 111  0
             throw new IllegalArgumentException("invalid (blank) attributeName");
 112  
         }
 113  0
         this.attributeName = attributeName;
 114  0
     }
 115  
 
 116  
     public String getErrorMessage() {
 117  0
         return errorMessage;
 118  
     }
 119  
 
 120  
     public void setErrorMessage(String errorMessage) {
 121  0
         if (StringUtils.isBlank(errorMessage)) {
 122  0
             throw new IllegalArgumentException("invalid (blank) errorMessage");
 123  
         }
 124  0
         this.errorMessage = errorMessage;
 125  0
     }
 126  
 
 127  
     /**
 128  
      * @see java.lang.Object#toString()
 129  
      */
 130  
     public String toString() {
 131  0
         return "ApcRuleDefinition for attribute " + getAttributeName();
 132  
     }
 133  
 
 134  
         public String getParameterDetailType() {
 135  0
                 return this.parameterDetailType;
 136  
         }
 137  
 
 138  
     /**
 139  
 
 140  
             * attributeName is the name of an attribute for
 141  
                 which the rule applies
 142  
 
 143  
             * parameterNamespace, parameterDetailType, and parameterName identify the parameter
 144  
 
 145  
             * errorMessage is the text that is to be displayed when
 146  
                 the error is detected.
 147  
              */
 148  
         public void setParameterDetailType(String parameterDetailType) {
 149  0
         if (StringUtils.isBlank(parameterDetailType)) {
 150  0
             throw new IllegalArgumentException("invalid (blank) parameterDetailType");
 151  
         }
 152  0
                 this.parameterDetailType = parameterDetailType;
 153  0
         }
 154  
 }