/** * Evaluate the specified BeanShell script based on the given script source, * returning the Class defined by the script. * <p>The script may either declare a full class or return an actual instance of * the scripted object (in which case the Class of the object will be returned). * In any other case, the returned Class will be {@code null}. * @param scriptSource the script source text * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java class, or {@code null} if none could be determined * @throws EvalError in case of BeanShell parsing failure */ @Nullable static Class<?> determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); Interpreter interpreter = new Interpreter(); if (classLoader != null) { interpreter.setClassLoader(classLoader); } Object result = interpreter.eval(scriptSource); if (result instanceof Class) { return (Class<?>) result; } else if (result != null) { return result.getClass(); } else { return null; } }
interpreter.setClassLoader(classLoader); Object result = interpreter.eval(scriptSource); if (result != null) {
@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); } }
/** * Evaluate the specified BeanShell script based on the given script source, * returning the Class defined by the script. * <p>The script may either declare a full class or return an actual instance of * the scripted object (in which case the Class of the object will be returned). * In any other case, the returned Class will be {@code null}. * @param scriptSource the script source text * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java class, or {@code null} if none could be determined * @throws EvalError in case of BeanShell parsing failure */ @Nullable static Class<?> determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); Interpreter interpreter = new Interpreter(); if (classLoader != null) { interpreter.setClassLoader(classLoader); } Object result = interpreter.eval(scriptSource); if (result instanceof Class) { return (Class<?>) result; } else if (result != null) { return result.getClass(); } else { return null; } }
interpreter.setClassLoader(classLoader); Object result = interpreter.eval(scriptSource); if (result != null) {
@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); } }
/** * Initializes the interpreter. * * @param stub the stub class. * @param scriptPath the path to the script file. * @return the initialized interpreter. */ private final Interpreter initialize( Object stub, String scriptPath) { final Interpreter interpreter = new Interpreter(); interpreter.setClassLoader(stub.getClass().getClassLoader()); return interpreter; }
public BeanshellTask(Processor p) throws ClassNotFoundException { this.proc = (BeanshellProcessor) p; ClassLoader classLoader = proc.findClassLoader(); interpreter = new Interpreter(); interpreter.setClassLoader(classLoader); logger.info("Beanshell using classloader " + classLoader); }
/** * Evaluate the specified BeanShell script based on the given script source, * returning the Class defined by the script. * <p>The script may either declare a full class or return an actual instance of * the scripted object (in which case the Class of the object will be returned). * In any other case, the returned Class will be {@code null}. * @param scriptSource the script source text * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java class, or {@code null} if none could be determined * @throws EvalError in case of BeanShell parsing failure */ @Nullable static Class<?> determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); Interpreter interpreter = new Interpreter(); if (classLoader != null) { interpreter.setClassLoader(classLoader); } Object result = interpreter.eval(scriptSource); if (result instanceof Class) { return (Class<?>) result; } else if (result != null) { return result.getClass(); } else { return null; } }
@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); } }
interpreter.setClassLoader(classLoader); Object result = interpreter.eval(scriptSource); if (result != null) {
/** * */ public JRBshEvaluator(String bshScript) throws JRException { super(); this.bshScript = bshScript; interpreter = new Interpreter(); interpreter.setClassLoader(Thread.currentThread().getContextClassLoader()); try { interpreter.eval(new StringReader(bshScript)); } catch(EvalError e) { throw new JRException( "Error evaluating report expressions BeanShell script." + "\nMessage : " + e.getMessage() + "\nLine " + e.getErrorLineNumber() + " : " + extractLineContent(e) ); } }
} else { interpreter = new Interpreter(); interpreter.setClassLoader(classLoader);
public void init(Page owner, String zslang) { super.init(owner, zslang); _ip = new bsh.Interpreter(); _ip.setClassLoader(Classes.getContextClassLoader(BSHInterpreter.class)); _bshns = new GlobalNS(_ip.getClassManager(), "global"); _ip.setNameSpace(_bshns); }
try { Interpreter i = new Interpreter(); i.setClassLoader(classLoader); i.set("addAdapter", this); i.set("picoContainer", pico);
try { Interpreter i = new Interpreter(); i.setClassLoader(classLoader); i.set("addAdapter", this); i.set("picoContainer", pico);
try { classLoader = findClassLoader(json, workflowRunID); interpreter.setClassLoader(classLoader); } catch (RuntimeException rex) { String message = "Unable to obtain the classloader for Beanshell service";
protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) { Interpreter i = new Interpreter(); try { i.set("parent", parentContainer); i.set("assemblyScope", assemblyScope); i.setClassLoader(this.getClassLoader()); i.eval(getScriptReader(), i.getNameSpace(), "picocontainer.bsh"); return (PicoContainer) i.get("pico"); } catch (EvalError e) { throw new ScriptedPicoContainerMarkupException(e); } catch (IOException e) { throw new ScriptedPicoContainerMarkupException(e); } } }
@Override protected PicoContainer createContainerFromScript(final PicoContainer parentContainer, final Object assemblyScope) { Interpreter i = new Interpreter(); try { i.set("parent", parentContainer); i.set("assemblyScope", assemblyScope); i.setClassLoader(this.getClassLoader()); i.eval(getScriptReader(), i.getNameSpace(), "picocontainer.bsh"); return (PicoContainer) i.get("pico"); } catch (EvalError e) { throw new ScriptedPicoContainerMarkupException(e); } catch (IOException e) { throw new ScriptedPicoContainerMarkupException(e); } } }