1 package net.sourceforge.groboutils.codecoverage.v2; 2 3 import java.util.Hashtable ; 4 5 public class ArrayClassLoader extends ClassLoader 6 { 7 10 11 12 15 private Hashtable m_classList = new Hashtable (); 16 private Hashtable m_classCache = new Hashtable (); 17 18 21 24 public ArrayClassLoader() 25 { 26 } 28 29 30 33 34 37 public void addClass( String name, byte[] bytecode ) 38 { 39 if (name == null || bytecode == null) 40 { 41 throw new IllegalArgumentException ("no null args"); 42 } 43 this.m_classList.put( name, bytecode ); 44 } 45 46 47 53 public Class loadClass( String name, boolean resolve ) 54 throws ClassNotFoundException 55 { 56 Class c; 57 58 if (name == null) 59 { 60 throw new IllegalArgumentException ("classname is null"); 61 } 62 63 c = (Class )this.m_classCache.get( name ); 64 if (c == null) 65 { 66 byte bytecode[] = getBytecode( name ); 67 if (bytecode == null) 68 { 69 c = findSystemClass( name ); 70 } 71 else 72 { 73 try 74 { 75 c = defineClass( name, bytecode, 0, bytecode.length ); 76 this.m_classCache.put( name, c ); 77 } 78 catch (Exception ex2) 79 { 80 throw new ClassNotFoundException ( 82 "Bad class format for class "+name ); 83 } 84 } 85 } 86 if (resolve) 87 { 88 resolveClass( c ); 89 } 90 return c; 91 } 92 93 96 97 103 protected byte[] getBytecode( String className ) 104 { 105 byte bytecode[] = (byte[])this.m_classList.get( className ); 106 return bytecode; 107 } 108 109 110 } 113 | Popular Tags |