Search in sources :

Example 1 with ReferenceBundle

use of org.codehaus.groovy.util.ReferenceBundle in project groovy-core by groovy.

the class GroovyScriptEngineImpl method eval.

public Object eval(String script, ScriptContext ctx) throws ScriptException {
    try {
        String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE);
        ReferenceBundle bundle = ReferenceBundle.getHardBundle();
        if (val != null && val.length() > 0) {
            if (val.equalsIgnoreCase("soft")) {
                bundle = ReferenceBundle.getSoftBundle();
            } else if (val.equalsIgnoreCase("weak")) {
                bundle = ReferenceBundle.getWeakBundle();
            } else if (val.equalsIgnoreCase("phantom")) {
                bundle = ReferenceBundle.getPhantomBundle();
            }
        }
        globalClosures.setBundle(bundle);
    } catch (ClassCastException cce) {
    /*ignore.*/
    }
    try {
        Class clazz = getScriptClass(script);
        if (clazz == null)
            throw new ScriptException("Script class is null");
        return eval(clazz, ctx);
    } catch (SyntaxException e) {
        throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine());
    } catch (Exception e) {
        if (debug)
            e.printStackTrace();
        throw new ScriptException(e);
    }
}
Also used : ScriptException(javax.script.ScriptException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException) ReferenceBundle(org.codehaus.groovy.util.ReferenceBundle) MetaClass(groovy.lang.MetaClass) Class(java.lang.Class) DelegatingMetaClass(groovy.lang.DelegatingMetaClass) String(java.lang.String) MissingPropertyException(groovy.lang.MissingPropertyException) ScriptException(javax.script.ScriptException) MissingMethodException(groovy.lang.MissingMethodException) IOException(java.io.IOException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 2 with ReferenceBundle

use of org.codehaus.groovy.util.ReferenceBundle in project groovy by apache.

the class GroovyScriptEngineImpl method eval.

public Object eval(String script, ScriptContext ctx) throws ScriptException {
    try {
        String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE);
        ReferenceBundle bundle = ReferenceBundle.getHardBundle();
        if (val != null && val.length() > 0) {
            if (val.equalsIgnoreCase("soft")) {
                bundle = ReferenceBundle.getSoftBundle();
            } else if (val.equalsIgnoreCase("weak")) {
                bundle = ReferenceBundle.getWeakBundle();
            } else if (val.equalsIgnoreCase("phantom")) {
                bundle = ReferenceBundle.getPhantomBundle();
            }
        }
        globalClosures.setBundle(bundle);
    } catch (ClassCastException cce) {
    /*ignore.*/
    }
    try {
        Class<?> clazz = getScriptClass(script);
        if (clazz == null)
            throw new ScriptException("Script class is null");
        return eval(clazz, ctx);
    } catch (Exception e) {
        if (debug)
            e.printStackTrace();
        throw new ScriptException(e);
    }
}
Also used : ScriptException(javax.script.ScriptException) ReferenceBundle(org.codehaus.groovy.util.ReferenceBundle) MissingPropertyException(groovy.lang.MissingPropertyException) ScriptException(javax.script.ScriptException) MissingMethodException(groovy.lang.MissingMethodException) IOException(java.io.IOException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException)

Aggregations

MissingMethodException (groovy.lang.MissingMethodException)2 MissingPropertyException (groovy.lang.MissingPropertyException)2 IOException (java.io.IOException)2 ScriptException (javax.script.ScriptException)2 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)2 ReferenceBundle (org.codehaus.groovy.util.ReferenceBundle)2 DelegatingMetaClass (groovy.lang.DelegatingMetaClass)1 MetaClass (groovy.lang.MetaClass)1 Class (java.lang.Class)1 String (java.lang.String)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1