FileDocCategorySizeDatePackage
HandleDelegateClassLoader.javaAPI DocGlassfish v2 API4205Fri May 04 22:34:54 BST 2007com.sun.enterprise.iiop

HandleDelegateClassLoader

public class HandleDelegateClassLoader extends ClassLoader

Fields Summary
Constructors Summary
public HandleDelegateClassLoader()

        super();
    
Methods Summary
protected java.lang.ClassfindClass(java.lang.String name)

        // This is called only if the class could not be loaded by
        // the parent class loader (see javadoc for loadClass methods).
        // Load the class from the current thread's context class loader.
        
        Class c =Thread.currentThread().getContextClassLoader().loadClass(name);
        
        return c;
    
protected java.lang.ClassloadClass(java.lang.String name, boolean resolve)

        if (!name.equals("com.sun.enterprise.iiop.IIOPHandleDelegate")) {
            return super.loadClass(name, resolve);
        }
        
        Class handleDelClass = findLoadedClass(name);
        if (handleDelClass != null) {
            return handleDelClass;
        }
        
        try {
            // read the bytes for IIOPHandleDelegate.class
            ClassLoader resCl = Thread.currentThread().getContextClassLoader();
            if (Thread.currentThread().getContextClassLoader() == null)  {
                resCl = getSystemClassLoader();
            }
            InputStream is = resCl.getResourceAsStream("com/sun/enterprise/iiop/IIOPHandleDelegate.class");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            
            byte[] buf = new byte[4096]; // currently IIOPHandleDelegate is < 4k
            int nread = 0;
            while ( (nread = is.read(buf, 0, buf.length)) != -1 ) {
                baos.write(buf, 0, nread);
            }
            baos.close();
            is.close();

            byte[] buf2 = baos.toByteArray();
            
            handleDelClass = defineClass(
            "com.sun.enterprise.iiop.IIOPHandleDelegate",
            buf2, 0, buf2.length);
            
        } catch ( Exception ex ) {
            throw (ClassNotFoundException)new ClassNotFoundException(ex.getMessage()).initCause(ex);
        }
        
        if (resolve) {
            resolveClass(handleDelClass);
        }
        
        return handleDelClass;