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