public static Class loadClass()

in src/main/java/org/apache/bsf/util/EngineUtils.java [314:356]


    public static Class loadClass(final BSFManager mgr, final String name) throws BSFException {

        ClassLoader mgrCL = null;

        try {
            // TCCL may not be set, adapt logic!
            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
            if (cl != null) {
                try { // try the Thread's context loader first
                    return Thread.currentThread().getContextClassLoader().loadClass(name);
                } catch (final ClassNotFoundException e01) {
                }
            }

            try { // try the class loader of the supplied BSFManager ("mgr")
                mgrCL = mgr.getClassLoader();
                if (mgrCL != null) {
                    return mgrCL.loadClass(name);
                }
            } catch (final ClassNotFoundException e02) {
                // o.k., now try the defined class loader
            }

            // try the class loader stored with the BSF manager
            if (mgrCL != bsfManagerDefinedCL) {
                return bsfManagerDefinedCL.loadClass(name);
            }

        } catch (final ClassNotFoundException e) {
            // try to load it from the temp dir using my own class loader
            try {
                if (bsfCL == null) {
                    bsfCL = new BSFClassLoader();
                }
                bsfCL.setTempDir(mgr.getTempDir());
                return bsfCL.loadClass(name);
            } catch (final ClassNotFoundException e2) {
                throw new BSFException(BSFException.REASON_OTHER_ERROR, "[EngineUtils.loadClass()] unable to load class '" + name + "':" + e, e);
            }
        }

        throw new BSFException(BSFException.REASON_OTHER_ERROR, "[EngineUtils.loadClass()] unable to load class '" + name + "'");
    }