1 package org.apache.fulcrum.intake.validator; 2 3 56 57 import java.util.Map ; 58 59 import org.apache.fulcrum.ServiceException; 60 import org.apache.torque.om.NumberKey; 61 62 79 public class NumberKeyValidator 80 extends NumberValidator 81 { 82 private static String INVALID_NUMBER = "Entry was not valid."; 83 84 private NumberKey minValue; 85 private NumberKey maxValue; 86 87 public NumberKeyValidator(Map paramMap) 88 throws ServiceException 89 { 90 this(); 91 init(paramMap); 92 } 93 94 public NumberKeyValidator() 95 { 96 super(); 98 } 99 100 protected void doInit(Map paramMap) 101 { 102 minValue = null; 103 maxValue = null; 104 105 Constraint constraint = (Constraint)paramMap.get("minValue"); 106 if ( constraint != null ) 107 { 108 String param = constraint.getValue(); 109 minValue = new NumberKey(param); 110 minValueMessage = constraint.getMessage(); 111 } 112 113 constraint = (Constraint)paramMap.get("maxValue"); 114 if ( constraint != null ) 115 { 116 String param = constraint.getValue(); 117 maxValue = new NumberKey(param); 118 maxValueMessage = constraint.getMessage(); 119 } 120 } 121 122 protected String getDefaultInvalidNumberMessage() 123 { 124 return INVALID_NUMBER; 125 } 126 127 135 protected void doAssertValidity(String testValue) 136 throws ValidationException 137 { 138 NumberKey nk = null; 139 try 140 { 141 nk = new NumberKey(testValue); 142 } 143 catch (RuntimeException e) 144 { 145 message = invalidNumberMessage; 146 throw new ValidationException(invalidNumberMessage); 147 } 148 if ( minValue != null && nk.compareTo(minValue) < 0 ) 149 { 150 message = minValueMessage; 151 throw new ValidationException(minValueMessage); 152 } 153 if ( maxValue != null && nk.compareTo(maxValue) > 0 ) 154 { 155 message = maxValueMessage; 156 throw new ValidationException(maxValueMessage); 157 } 158 } 159 160 161 165 169 public NumberKey getMinValue() 170 { 171 return minValue; 172 } 173 174 178 public void setMinValue(NumberKey v) 179 { 180 this.minValue = v; 181 } 182 183 187 public NumberKey getMaxValue() 188 { 189 return maxValue; 190 } 191 192 196 public void setMaxValue(NumberKey v) 197 { 198 this.maxValue = v; 199 } 200 } 201 | Popular Tags |