FileDocCategorySizeDatePackage
FileClassLoader.javaAPI DocGlassfish v2 API4322Fri May 04 22:32:08 BST 2007com.sun.enterprise.util

FileClassLoader

public class FileClassLoader extends ClassLoader

Fields Summary
String
codebase
Hashtable
cache
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
Constructors Summary
public FileClassLoader(String codebase)


      
    
	this.codebase = codebase;
    
Methods Summary
java.lang.StringgetClassName(java.io.File f)

	FileInputStream fis = new FileInputStream(f);
	int avail = fis.available();
	byte[] buf = new byte[avail];
	fis.read(buf);
        fis.close();
	Class c = super.defineClass(null, buf, 0, avail);
	return c.getName();
    
public synchronized java.lang.ClassloadClass(java.lang.String name, boolean resolve)

exception
ClassNotFoundException if class load fails

        Class c = (Class)cache.get(name);
        if (c == null) {
	    try { 
                byte data[] = loadClassData(name);
                c = defineClass(null,data, 0, data.length);
                if( !name.equals(c.getName()) ) {
                    throw new ClassNotFoundException(localStrings.getLocalString("classloader.wrongpackage", "", new Object[] { name, c.getName() }));
                }
	    }
	    catch ( Exception ex ) {
		// Try to use default classloader. If this fails, 
		// then a ClassNotFoundException is thrown.
		c = Class.forName(name);
	    }
            cache.put(name, c);
        }
        if (resolve)
            resolveClass(c);
        return c;
    
private byte[]loadClassData(java.lang.String name)

        // load the class data from the codebase
	String sep = System.getProperty("file.separator");
	String c = name.replace('.", sep.charAt(0)) + ".class";
	File file = new File(codebase + sep + c);
	if (!file.exists()) {
	    File wf = new File(codebase + sep + "WEB-INF" + sep + "classes" + sep + c);
	    if (wf.exists()) {
		file = wf;
	    }
	}
	FileInputStream fis = new FileInputStream(file);
	int avail = fis.available();
	byte[] buf = new byte[avail];
	fis.read(buf);
        fis.close();
	return buf;
    
public java.lang.StringtoString()

	return "FileClassLoader: Codebase = "+codebase+"\n";