Coverage report

  %line %branch
org.apache.turbine.services.intake.validator.NumberKeyValidator
0% 
0% 

 1  
 package org.apache.turbine.services.intake.validator;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.torque.om.NumberKey;
 22  
 
 23  
 /**
 24  
  * Validates numbers with the following constraints in addition to those
 25  
  * listed in DefaultValidator.
 26  
  *
 27  
  * <table>
 28  
  * <tr><th>Name</th><th>Valid Values</th><th>Default Value</th></tr>
 29  
  * <tr><td>minValue</td><td>greater than Integer.MIN_VALUE</td>
 30  
  * <td>&nbsp;</td></tr>
 31  
  * <tr><td>maxValue</td><td>less than BigDecimal.MAX_VALUE</td>
 32  
  * <td>&nbsp;</td></tr>
 33  
  * <tr><td>notANumberMessage</td><td>Some text</td>
 34  
  * <td>Entry was not a valid number</td></tr>
 35  
  * </table>
 36  
  *
 37  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 38  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 39  
  * @version $Id: NumberKeyValidator.java 264148 2005-08-29 14:21:04Z henning $
 40  
  * @deprecated No replacement
 41  
  */
 42  
 public class NumberKeyValidator
 43  
         extends NumberValidator
 44  
 {
 45  0
     private static String INVALID_NUMBER = "Entry was not valid.";
 46  
 
 47  
     private NumberKey minValue;
 48  
     private NumberKey maxValue;
 49  
 
 50  
     public NumberKeyValidator(Map paramMap)
 51  
             throws InvalidMaskException
 52  
     {
 53  0
         this();
 54  0
         init(paramMap);
 55  0
     }
 56  
 
 57  
     public NumberKeyValidator()
 58  
     {
 59  
         // sets the default invalid number message
 60  0
         super();
 61  0
     }
 62  
 
 63  
     protected void doInit(Map paramMap)
 64  
     {
 65  0
         minValue = null;
 66  0
         maxValue = null;
 67  
 
 68  0
         Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
 69  0
         if (constraint != null)
 70  
         {
 71  0
             String param = constraint.getValue();
 72  0
             minValue = new NumberKey(param);
 73  0
             minValueMessage = constraint.getMessage();
 74  
         }
 75  
 
 76  0
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
 77  0
         if (constraint != null)
 78  
         {
 79  0
             String param = constraint.getValue();
 80  0
             maxValue = new NumberKey(param);
 81  0
             maxValueMessage = constraint.getMessage();
 82  
         }
 83  0
     }
 84  
 
 85  
     protected String getDefaultInvalidNumberMessage()
 86  
     {
 87  0
         return INVALID_NUMBER;
 88  
     }
 89  
 
 90  
     /**
 91  
      * Determine whether a testValue meets the criteria specified
 92  
      * in the constraints defined for this validator
 93  
      *
 94  
      * @param testValue a <code>String</code> to be tested
 95  
      * @exception ValidationException containing an error message if the
 96  
      * testValue did not pass the validation tests.
 97  
      */
 98  
     public void assertValidity(String testValue)
 99  
             throws ValidationException
 100  
     {
 101  0
         NumberKey nk = null;
 102  
         try
 103  
         {
 104  0
             nk = new NumberKey(testValue);
 105  
         }
 106  0
         catch (RuntimeException e)
 107  
         {
 108  0
             errorMessage = invalidNumberMessage;
 109  0
             throw new ValidationException(invalidNumberMessage);
 110  0
         }
 111  0
         if (minValue != null && nk.compareTo(minValue) < 0)
 112  
         {
 113  0
             errorMessage = minValueMessage;
 114  0
             throw new ValidationException(minValueMessage);
 115  
         }
 116  0
         if (maxValue != null && nk.compareTo(maxValue) > 0)
 117  
         {
 118  0
             errorMessage = maxValueMessage;
 119  0
             throw new ValidationException(maxValueMessage);
 120  
         }
 121  0
     }
 122  
 
 123  
 
 124  
     // ************************************************************
 125  
     // **                Bean accessor methods                   **
 126  
     // ************************************************************
 127  
 
 128  
     /**
 129  
      * Get the value of minValue.
 130  
      *
 131  
      * @return value of minValue.
 132  
      */
 133  
     public NumberKey getMinValue()
 134  
     {
 135  0
         return minValue;
 136  
     }
 137  
 
 138  
     /**
 139  
      * Set the value of minValue.
 140  
      *
 141  
      * @param minValue Value to assign to minValue.
 142  
      */
 143  
     public void setMinValue(NumberKey minValue)
 144  
     {
 145  0
         this.minValue = minValue;
 146  0
     }
 147  
 
 148  
     /**
 149  
      * Get the value of maxValue.
 150  
      *
 151  
      * @return value of maxValue.
 152  
      */
 153  
     public NumberKey getMaxValue()
 154  
     {
 155  0
         return maxValue;
 156  
     }
 157  
 
 158  
     /**
 159  
      * Set the value of maxValue.
 160  
      *
 161  
      * @param maxValue Value to assign to maxValue.
 162  
      */
 163  
     public void setMaxValue(NumberKey maxValue)
 164  
     {
 165  0
         this.maxValue = maxValue;
 166  0
     }
 167  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.