1 package org.apache.turbine.services.intake.validator; 2 3 18 19 import java.util.Map ; 20 21 import org.apache.torque.om.NumberKey; 22 23 42 public class NumberKeyValidator 43 extends NumberValidator 44 { 45 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 this(); 54 init(paramMap); 55 } 56 57 public NumberKeyValidator() 58 { 59 super(); 61 } 62 63 protected void doInit(Map paramMap) 64 { 65 minValue = null; 66 maxValue = null; 67 68 Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME); 69 if (constraint != null) 70 { 71 String param = constraint.getValue(); 72 minValue = new NumberKey(param); 73 minValueMessage = constraint.getMessage(); 74 } 75 76 constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME); 77 if (constraint != null) 78 { 79 String param = constraint.getValue(); 80 maxValue = new NumberKey(param); 81 maxValueMessage = constraint.getMessage(); 82 } 83 } 84 85 protected String getDefaultInvalidNumberMessage() 86 { 87 return INVALID_NUMBER; 88 } 89 90 98 public void assertValidity(String testValue) 99 throws ValidationException 100 { 101 NumberKey nk = null; 102 try 103 { 104 nk = new NumberKey(testValue); 105 } 106 catch (RuntimeException e) 107 { 108 errorMessage = invalidNumberMessage; 109 throw new ValidationException(invalidNumberMessage); 110 } 111 if (minValue != null && nk.compareTo(minValue) < 0) 112 { 113 errorMessage = minValueMessage; 114 throw new ValidationException(minValueMessage); 115 } 116 if (maxValue != null && nk.compareTo(maxValue) > 0) 117 { 118 errorMessage = maxValueMessage; 119 throw new ValidationException(maxValueMessage); 120 } 121 } 122 123 124 128 133 public NumberKey getMinValue() 134 { 135 return minValue; 136 } 137 138 143 public void setMinValue(NumberKey minValue) 144 { 145 this.minValue = minValue; 146 } 147 148 153 public NumberKey getMaxValue() 154 { 155 return maxValue; 156 } 157 158 163 public void setMaxValue(NumberKey maxValue) 164 { 165 this.maxValue = maxValue; 166 } 167 } 168 | Popular Tags |