public BSFEngine loadScriptingEngine()

in src/main/java/org/apache/bsf/BSFManager.java [652:710]


    public BSFEngine loadScriptingEngine(final String lang) throws BSFException {
        logger.debug("BSFManager:loadScriptingEngine");

        // if its already loaded return that
        BSFEngine eng = (BSFEngine) loadedEngines.get(lang);
        if (eng != null) {
            return eng;
        }

        // is it a registered language?
        final String engineClassName = (String) registeredEngines.get(lang);
        if (engineClassName == null) {
            logger.error("[BSFManager] unsupported language: " + lang);
            throw new BSFException(BSFException.REASON_UNKNOWN_LANGUAGE, "[BSFManager.loadScriptingEngine()] unsupported language: " + lang);
        }

        // create the engine and initialize it. if anything goes wrong
        // except.
        try {

            Class engineClass = null;

            final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
            if (tccl != null) {
                try {
                    engineClass = tccl.loadClass(engineClassName);
                } catch (final ClassNotFoundException cnfe) {
                }
            }

            if (engineClass == null) // not found, try the defined classLoader
            {
                engineClass = definedClassLoader.loadClass(engineClassName);
            }

            final BSFEngine engf = (BSFEngine) engineClass.newInstance();
            final BSFManager thisf = this;
            final String langf = lang;
            final Vector dbf = declaredBeans;
            AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() throws Exception {
                    engf.initialize(thisf, langf, dbf);
                    return null;
                }
            });
            eng = engf;
            loadedEngines.put(lang, eng);
            pcs.addPropertyChangeListener(eng);
            return eng;
        } catch (final PrivilegedActionException prive) {

            logger.error("[BSFManager] Exception :", prive);
            throw (BSFException) prive.getException();
        } catch (final Throwable t) {

            logger.error("[BSFManager] Exception :", t);
            throw new BSFException(BSFException.REASON_OTHER_ERROR, "[BSFManager.loadScriptingEngine()] unable to load language: " + lang, t);
        }
    }