1 17 package org.apache.bcel.verifier.statics; 18 19 20 import org.apache.bcel.Repository; 21 import org.apache.bcel.classfile.ClassFormatException; 22 import org.apache.bcel.classfile.JavaClass; 23 import org.apache.bcel.verifier.PassVerifier; 24 import org.apache.bcel.verifier.VerificationResult; 25 import org.apache.bcel.verifier.Verifier; 26 import org.apache.bcel.verifier.exc.LoadingException; 27 import org.apache.bcel.verifier.exc.Utility; 28 29 39 public final class Pass1Verifier extends PassVerifier{ 40 44 private JavaClass jc; 45 46 49 private Verifier myOwner; 50 51 52 private JavaClass getJavaClass(){ 53 if (jc == null){ 54 try { 55 jc = Repository.lookupClass(myOwner.getClassName()); 56 } catch (ClassNotFoundException e) { 57 } 62 } 63 return jc; 64 } 65 66 71 public Pass1Verifier(Verifier owner){ 72 myOwner = owner; 73 } 74 75 133 public VerificationResult do_verify(){ 134 JavaClass jc; 135 try{ 136 jc = getJavaClass(); 138 if (jc != null){ 139 140 if (! myOwner.getClassName().equals(jc.getClassName())){ 141 throw new LoadingException("Wrong name: the internal name of the .class file '"+jc.getClassName()+"' does not match the file's name '"+myOwner.getClassName()+"'."); 144 } 145 } 146 147 } 148 catch(LoadingException e){ 149 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); 150 } 151 catch(ClassFormatException e){ 152 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); 153 } 154 catch(RuntimeException e){ 155 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Parsing via BCEL did not succeed. "+e.getClass().getName()+" occured:\n"+Utility.getStackTrace(e)); 158 } 159 160 if (jc != null){ 161 return VerificationResult.VR_OK; 162 } 163 else{ 164 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Repository.lookup() failed. FILE NOT FOUND?"); 167 } 168 } 169 170 180 public String [] getMessages(){ 181 return super.getMessages(); 183 } 184 185 } 186 | Popular Tags |