Search in sources :

Example 1 with BSFFunctions

use of org.apache.bsf.util.BSFFunctions in project groovy by apache.

the class GroovyEngine method initialize.

/**
     * Initialize the engine.
     */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    // create a shell
    shell = new GroovyShell(mgr.getClassLoader());
    // register the mgr with object name "bsf"
    shell.setVariable("bsf", new BSFFunctions(mgr, this));
    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
Also used : GroovyShell(groovy.lang.GroovyShell) BSFFunctions(org.apache.bsf.util.BSFFunctions)

Example 2 with BSFFunctions

use of org.apache.bsf.util.BSFFunctions in project groovy-core by groovy.

the class CachingGroovyEngine method initialize.

/**
     * Initialize the engine.
     */
public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    ClassLoader parent = mgr.getClassLoader();
    if (parent == null)
        parent = GroovyShell.class.getClassLoader();
    setLoader(mgr, parent);
    execScripts = new HashMap<Object, Class>();
    evalScripts = new HashMap<Object, Class>();
    context = shell.getContext();
    // create a shell
    // register the mgr with object name "bsf"
    context.setVariable("bsf", new BSFFunctions(mgr, this));
    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) BSFFunctions(org.apache.bsf.util.BSFFunctions)

Example 3 with BSFFunctions

use of org.apache.bsf.util.BSFFunctions in project groovy-core by groovy.

the class GroovyEngine method initialize.

/**
     * Initialize the engine.
     */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    // create a shell
    shell = new GroovyShell(mgr.getClassLoader());
    // register the mgr with object name "bsf"
    shell.setVariable("bsf", new BSFFunctions(mgr, this));
    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
Also used : GroovyShell(groovy.lang.GroovyShell) BSFFunctions(org.apache.bsf.util.BSFFunctions)

Example 4 with BSFFunctions

use of org.apache.bsf.util.BSFFunctions in project groovy by apache.

the class CachingGroovyEngine method initialize.

/**
     * Initialize the engine.
     */
public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    ClassLoader parent = mgr.getClassLoader();
    if (parent == null)
        parent = GroovyShell.class.getClassLoader();
    setLoader(mgr, parent);
    execScripts = new HashMap<Object, Class>();
    evalScripts = new HashMap<Object, Class>();
    context = shell.getContext();
    // create a shell
    // register the mgr with object name "bsf"
    context.setVariable("bsf", new BSFFunctions(mgr, this));
    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) BSFFunctions(org.apache.bsf.util.BSFFunctions)

Example 5 with BSFFunctions

use of org.apache.bsf.util.BSFFunctions in project jmeter by apache.

the class BSFJavaScriptEngine method initialize.

/**
     * Initialize the engine.
     * Put the manager into the context-manager
     * map hashtable too.
     */
@Override
public void initialize(BSFManager mgr, String lang, // superclass does not support types
@SuppressWarnings("rawtypes") Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    // Initialize context and global scope object
    try {
        Context cx = Context.enter();
        global = new ImporterTopLevel(cx);
        Scriptable bsf = Context.toObject(new BSFFunctions(mgr, this), global);
        global.put("bsf", global, bsf);
        // superclass does not support types
        @SuppressWarnings("unchecked") final Vector<BSFDeclaredBean> beans = declaredBeans;
        for (BSFDeclaredBean declaredBean : beans) {
            declareBean(declaredBean);
        }
    } catch (Throwable t) {
        // NOSONAR We handle correctly Error case in function
        handleError(t);
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) ImporterTopLevel(org.mozilla.javascript.ImporterTopLevel) Scriptable(org.mozilla.javascript.Scriptable) BSFFunctions(org.apache.bsf.util.BSFFunctions) BSFDeclaredBean(org.apache.bsf.BSFDeclaredBean)

Aggregations

BSFFunctions (org.apache.bsf.util.BSFFunctions)5 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 GroovyShell (groovy.lang.GroovyShell)2 BSFDeclaredBean (org.apache.bsf.BSFDeclaredBean)1 Context (org.mozilla.javascript.Context)1 ImporterTopLevel (org.mozilla.javascript.ImporterTopLevel)1 Scriptable (org.mozilla.javascript.Scriptable)1