1 package net.firstpartners.nounit.ui.common; 2 3 26 27 import java.io.File ; 28 import java.util.Enumeration ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 import java.util.Vector ; 33 34 import org.apache.log4j.Logger; 35 36 import net.firstpartners.nounit.utility.NoUnitException; 37 38 39 42 abstract public class AbstractValueChecker { 43 44 45 46 51 public abstract boolean checkValues(AbstractPackage inValues) 52 throws NoUnitException, java.lang.ClassNotFoundException , java.sql.SQLException ; 53 54 55 62 protected void checkForNullEmptyString(AbstractPackage inValues, 63 HashMap namesToCheck) 64 throws NoUnitException { 65 66 Object tmpObject = null; 68 String thisName=null; 69 String thisEnglishName=null; 70 Iterator myNames=namesToCheck.keySet().iterator(); 71 72 while(myNames.hasNext()) { 74 75 thisName = (String )myNames.next(); 76 tmpObject = inValues.getValue(thisName); 77 78 if (tmpObject == null) { 80 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 81 throw new NoUnitException("Please make sure that " 82 +thisEnglishName 83 +" is not empty or void"); 84 } 85 86 if (!(tmpObject instanceof String )) { 88 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 89 throw new NoUnitException("Please make sure that " 90 +thisEnglishName 91 +" is a valid piece of text"); 92 } 93 94 if ((tmpObject.toString().equals(""))) { 96 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 97 throw new NoUnitException("Please make sure that " 98 +thisEnglishName 99 +" contains a value"); 100 } 101 } 102 103 } 104 105 113 boolean checkForNumbers(AbstractPackage inValues, 114 HashMap namesToCheck) 115 throws NoUnitException { 116 117 Object inObject =null; 119 Object tmpObject = null; 120 Integer tmpInteger =null; 121 Vector tmpVector = null; 122 Enumeration myVectorList; 123 String tmpNumberString; 124 String thisName=""; 125 String thisEnglishName=null; 126 Iterator myNames=namesToCheck.keySet().iterator(); 127 128 Logger log = Logger.getLogger(AbstractValueChecker.class); 130 131 while (myNames.hasNext()) { 133 134 thisName=(String )myNames.next(); 135 136 inObject = inValues.getValue(thisName); 137 138 if (inObject instanceof Vector ) { 140 myVectorList = ((Vector )inObject).elements(); 141 } else { 142 tmpVector = new Vector (); 143 tmpVector.add(inObject); 144 myVectorList = tmpVector.elements(); 145 } 146 147 while(myVectorList.hasMoreElements()) { 149 150 tmpObject = myVectorList.nextElement(); 151 152 if (tmpObject == null) { 154 155 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 156 157 log.debug("@@@@@@ problem with "+thisName+" @@@@@"); 158 159 throw new NoUnitException("Please make sure that " 160 +thisEnglishName 161 +" contains a number value"); 162 } 163 164 if (!(tmpObject instanceof Integer )) { 166 if (tmpObject instanceof String ) { 167 168 try { 169 tmpNumberString = (String )tmpObject; 170 tmpInteger = new Integer (tmpNumberString); } catch (NumberFormatException nfe) { 172 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 173 throw new NoUnitException("Please make sure that " 174 +thisEnglishName 175 +" contains a number"); 176 } 177 178 } 179 } 180 } 181 182 } 183 184 return true; 186 } 187 188 196 boolean checkForVectors(AbstractPackage inValues, 197 HashMap namesToCheck) 198 throws NoUnitException { 199 200 Vector tmpVector =null; 202 String thisName=""; 203 String thisEnglishName=null; 204 Iterator myNames=namesToCheck.keySet().iterator(); 205 206 while (myNames.hasNext()) { 208 209 thisName=(String )myNames.next(); 210 tmpVector = inValues.getVector(thisName); 211 212 if (tmpVector == null) { 214 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 215 throw new NoUnitException("Please make sure that " 216 +thisEnglishName 217 +" contains at least one value"); 218 } 219 } 220 221 return true; 223 } 224 225 233 boolean checkForStringVectors(AbstractPackage inValues, 234 HashMap namesToCheck) 235 throws NoUnitException { 236 237 Vector tmpVector =null; 239 Iterator myList; 240 String thisName=""; 241 String thisEnglishName=null; 242 Iterator myNames=namesToCheck.keySet().iterator(); 243 244 245 this.checkForVectors(inValues,namesToCheck); 247 248 while (myNames.hasNext()) { 250 251 thisName=(String )myNames.next(); 252 tmpVector = inValues.getVector(thisName); 253 254 myList = tmpVector.iterator(); 256 while (myList.hasNext()) { 257 if (!(myList.next() instanceof String )) { 258 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 259 throw new NoUnitException("Please make sure that " 260 +thisEnglishName 261 +" All the values are text"); 262 } 263 } 264 265 266 } 267 268 return true; 270 } 271 272 273 280 boolean checkYN(String name,String inCheckString) 281 throws NoUnitException { 282 283 if ((!(inCheckString.equals("Y"))&& 284 (!(inCheckString.equals("N"))))) 285 { 286 throw new NoUnitException (name,inCheckString, "Value was not Y or N"); 287 } 288 289 return true; 291 } 292 293 299 private String getUserFriendlyName(String actualKey, Map names) 300 throws NoUnitException { 301 302 String userFriendlyName = null; 304 305 if(actualKey == null) { 307 throw new NoUnitException("Please make sure that "+actualKey+" is not null"); 308 } 309 310 userFriendlyName = (String )names.get(actualKey); 311 if ((userFriendlyName == null)||(userFriendlyName.equals(""))) { 312 userFriendlyName = actualKey; 313 } 314 315 return userFriendlyName; 316 317 } 318 319 325 protected void checkForDirsExist(AbstractPackage inValues, 326 Map namesToCheck) 327 throws NoUnitException { 328 329 Object tmpObject = null; 331 String thisName=null; 332 String thisEnglishName=null; 333 File thisDir; 334 Iterator myNames=namesToCheck.keySet().iterator(); 335 336 while(myNames.hasNext()) { 338 339 thisName = (String )myNames.next(); 340 tmpObject = inValues.getValue(thisName); 341 342 if (tmpObject == null) { 344 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 345 throw new NoUnitException("Please make sure that " 346 +thisEnglishName 347 +" contains a (non-empty) directory name"); 348 } 349 350 if (!(tmpObject instanceof String )) { 352 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 353 throw new NoUnitException("Please make sure that " 354 +thisEnglishName 355 +" contains a valid directory name"); 356 } 357 358 thisName=(String )tmpObject; 360 thisDir=new File (thisName); 361 if(!thisDir.isDirectory()) { 362 thisEnglishName= getUserFriendlyName(thisName,namesToCheck); 363 throw new NoUnitException("Please make sure that " 364 +thisEnglishName 365 +" is a directory"); 366 } 367 368 } 369 370 } 371 372 373 374 } | Popular Tags |