1 package net.firstpartners.nounit.ui.common; 2 3 26 27 import java.lang.reflect.Field ; 28 import java.util.Iterator ; 29 30 import net.firstpartners.nounit.utility.NoUnitException; 31 32 33 39 public class ExtraValueChecker { 40 41 48 public boolean checkForExtraKeys(CommandPackage inValues) 49 throws NoUnitException, java.lang.ClassNotFoundException { 50 51 String acceptableValues; 53 boolean successFlag = true; Iterator storeNames; 55 String thisName; 56 57 try { 59 acceptableValues=getConcatinatedFields(CommandPackage.class,inValues); 60 } catch (IllegalAccessException iae) { 61 throw new NoUnitException(iae,"Could not read the list of Values that the System will accept"); 62 } 63 64 storeNames= inValues.getStoreNames(); 66 67 while (storeNames.hasNext()) { 69 70 thisName = (String )storeNames.next(); 71 if (acceptableValues.indexOf(thisName)<0) { 72 if (!(thisName.equals("XXX"))) { throw new NoUnitException("The System did not recognize the key:"+thisName); 74 } 75 } 76 } 77 78 return successFlag; 79 } 80 81 87 private String getConcatinatedFields(Class classToProcess, Object instanceOfClass) 88 throws IllegalAccessException { 89 90 StringBuffer concatinatedFields=new StringBuffer (); 92 Field [] listOfFields; 93 String thisName; 94 Object thisValue; 95 96 listOfFields = classToProcess.getFields(); 98 99 for (int a=0; a<listOfFields.length;a++) { 100 101 thisName=listOfFields[a].getName(); 103 thisValue=listOfFields[a].get(instanceOfClass); 104 105 if (thisValue!=null) { 107 concatinatedFields.append(thisValue); 108 } 109 concatinatedFields.append(":\n"); 110 111 } 112 113 return concatinatedFields.toString(); 114 115 } 116 117 118 119 120 121 } | Popular Tags |