1 33 34 package bsh.classpath; 35 36 import java.io.*; 37 import java.io.File ; 38 import java.util.*; 39 import java.awt.*; 40 import bsh.BshClassManager; 41 import bsh.classpath.BshClassPath.ClassSource; 42 import bsh.classpath.BshClassPath.DirClassSource; 43 import bsh.classpath.BshClassPath.GeneratedClassSource; 44 45 50 public class DiscreteFilesClassLoader extends BshClassLoader 51 { 52 55 ClassSourceMap map; 56 57 public static class ClassSourceMap extends HashMap 58 { 59 public void put( String name, ClassSource source ) { 60 super.put( name, source ); 61 } 62 public ClassSource get( String name ) { 63 return (ClassSource)super.get( name ); 64 } 65 } 66 67 public DiscreteFilesClassLoader( 68 BshClassManager classManager, ClassSourceMap map ) 69 { 70 super( classManager ); 71 this.map = map; 72 } 73 74 76 public Class findClass( String name ) throws ClassNotFoundException 77 { 78 ClassSource source = map.get( name ); 80 81 if ( source != null ) 82 { 83 byte [] code = source.getCode( name ); 84 return defineClass( name, code, 0, code.length ); 85 } else 86 return super.findClass( name ); 89 } 90 91 public String toString() { 92 return super.toString() + "for files: "+map; 93 } 94 95 } 96 | Popular Tags |