protected Object evaluateScript(ScriptSource scriptSource) { try { ScriptEngine scriptEngine = this.scriptEngine; if (scriptEngine == null) { scriptEngine = retrieveScriptEngine(scriptSource); if (scriptEngine == null) { throw new IllegalStateException("Could not determine script engine for " + scriptSource); } this.scriptEngine = scriptEngine; } return scriptEngine.eval(scriptSource.getScriptAsString()); } catch (Exception ex) { throw new ScriptCompilationException(scriptSource, ex); } }
throw new ScriptCompilationException( "No default constructor on Groovy script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Unable to instantiate Groovy script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Could not access Groovy script constructor: " + scriptClass.getName(), ex); throw new ScriptCompilationException( "Failed to invoke Groovy script constructor: " + scriptClass.getName(), ex.getTargetException());
throw new ScriptCompilationException( "No default constructor on script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Unable to instantiate script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Could not access script constructor: " + scriptClass.getName(), ex); throw new ScriptCompilationException( "Failed to invoke script constructor: " + scriptClass.getName(), ex.getTargetException());
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) { try { Interpreter interpreter = new Interpreter(); interpreter.setClassLoader(this.classLoader); if (arguments != null) { for (Map.Entry<String, Object> entry : arguments.entrySet()) { interpreter.set(entry.getKey(), entry.getValue()); } } return interpreter.eval(new StringReader(script.getScriptAsString())); } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex); } catch (EvalError ex) { throw new ScriptCompilationException(script, ex); } }
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) { GroovyShell groovyShell = new GroovyShell( this.classLoader, new Binding(arguments), this.compilerConfiguration); try { String filename = (script instanceof ResourceScriptSource ? ((ResourceScriptSource) script).getResource().getFilename() : null); if (filename != null) { return groovyShell.evaluate(script.getScriptAsString(), filename); } else { return groovyShell.evaluate(script.getScriptAsString()); } } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access Groovy script", ex); } catch (GroovyRuntimeException ex) { throw new ScriptCompilationException(script, ex); } }
@Nullable protected Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) { Class<?> adaptedIfc; if (actualInterfaces.length == 1) { adaptedIfc = actualInterfaces[0]; } else { adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader); } if (adaptedIfc != null) { ScriptEngine scriptEngine = this.scriptEngine; if (!(scriptEngine instanceof Invocable)) { throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine); } Invocable invocable = (Invocable) scriptEngine; if (script != null) { script = invocable.getInterface(script, adaptedIfc); } if (script == null) { script = invocable.getInterface(adaptedIfc); if (script == null) { throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]"); } } } return script; }
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> argumentBindings) { ScriptEngine engine = getScriptEngine(script); try { if (CollectionUtils.isEmpty(argumentBindings)) { return engine.eval(script.getScriptAsString()); } else { Bindings bindings = StandardScriptUtils.getBindings(argumentBindings); return engine.eval(script.getScriptAsString(), bindings); } } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access script for ScriptEngine", ex); } catch (ScriptException ex) { throw new ScriptCompilationException(script, new StandardScriptEvalException(ex)); } }
protected Object evaluateScript(ScriptSource scriptSource) { try { ScriptEngine scriptEngine = this.scriptEngine; if (scriptEngine == null) { scriptEngine = retrieveScriptEngine(scriptSource); if (scriptEngine == null) { throw new IllegalStateException("Could not determine script engine for " + scriptSource); } this.scriptEngine = scriptEngine; } return scriptEngine.eval(scriptSource.getScriptAsString()); } catch (Exception ex) { throw new ScriptCompilationException(scriptSource, ex); } }
throw new ScriptCompilationException( "No default constructor on Groovy script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Unable to instantiate Groovy script class: " + scriptClass.getName(), ex); throw new ScriptCompilationException( scriptSource, "Could not access Groovy script constructor: " + scriptClass.getName(), ex); throw new ScriptCompilationException( "Failed to invoke Groovy script constructor: " + scriptClass.getName(), ex.getTargetException());
@Override @Nullable public Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { try { if (scriptSource.isModified()) { // New script content: Let's check whether it evaluates to a Class. this.wasModifiedForTypeCheck = true; this.scriptClass = BshScriptUtils.determineBshObjectType( scriptSource.getScriptAsString(), this.beanClassLoader); } return this.scriptClass; } catch (EvalError ex) { this.scriptClass = null; throw new ScriptCompilationException(scriptSource, ex); } } }
@Nullable protected Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) { Class<?> adaptedIfc; if (actualInterfaces.length == 1) { adaptedIfc = actualInterfaces[0]; } else { adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader); } if (adaptedIfc != null) { ScriptEngine scriptEngine = this.scriptEngine; if (!(scriptEngine instanceof Invocable)) { throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine); } Invocable invocable = (Invocable) scriptEngine; if (script != null) { script = invocable.getInterface(script, adaptedIfc); } if (script == null) { script = invocable.getInterface(adaptedIfc); if (script == null) { throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]"); } } } return script; }
throw new ScriptCompilationException(scriptSource, ex); throw new ScriptCompilationException( scriptSource, "Could not instantiate script class: " + clazz.getName(), ex); throw new ScriptCompilationException(scriptSource, ex);
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) { try { Interpreter interpreter = new Interpreter(); interpreter.setClassLoader(this.classLoader); if (arguments != null) { for (Map.Entry<String, Object> entry : arguments.entrySet()) { interpreter.set(entry.getKey(), entry.getValue()); } } return interpreter.eval(new StringReader(script.getScriptAsString())); } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex); } catch (EvalError ex) { throw new ScriptCompilationException(script, ex); } }
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) { GroovyShell groovyShell = new GroovyShell( this.classLoader, new Binding(arguments), this.compilerConfiguration); try { String filename = (script instanceof ResourceScriptSource ? ((ResourceScriptSource) script).getResource().getFilename() : null); if (filename != null) { return groovyShell.evaluate(script.getScriptAsString(), filename); } else { return groovyShell.evaluate(script.getScriptAsString()); } } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access Groovy script", ex); } catch (GroovyRuntimeException ex) { throw new ScriptCompilationException(script, ex); } }
@Override @Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> argumentBindings) { ScriptEngine engine = getScriptEngine(script); try { if (CollectionUtils.isEmpty(argumentBindings)) { return engine.eval(script.getScriptAsString()); } else { Bindings bindings = StandardScriptUtils.getBindings(argumentBindings); return engine.eval(script.getScriptAsString(), bindings); } } catch (IOException ex) { throw new ScriptCompilationException(script, "Cannot access script for ScriptEngine", ex); } catch (ScriptException ex) { throw new ScriptCompilationException(script, new StandardScriptEvalException(ex)); } }
@Override @Nullable public Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { try { if (scriptSource.isModified()) { // New script content: Let's check whether it evaluates to a Class. this.wasModifiedForTypeCheck = true; this.scriptClass = BshScriptUtils.determineBshObjectType( scriptSource.getScriptAsString(), this.beanClassLoader); } return this.scriptClass; } catch (EvalError ex) { this.scriptClass = null; throw new ScriptCompilationException(scriptSource, ex); } } }
this.scriptClass = null; this.scriptResultClass = null; throw new ScriptCompilationException(scriptSource, ex);
this.scriptResultClass = null; this.cachedResult = null; throw new ScriptCompilationException(scriptSource, ex);
this.scriptClass = null; this.scriptResultClass = null; throw new ScriptCompilationException(scriptSource, ex);
this.scriptResultClass = null; this.cachedResult = null; throw new ScriptCompilationException(scriptSource, ex);