private String readFully(Reader reader) throws ScriptException { char[] array = new char[8192]; StringBuilder strBuffer = new StringBuilder(); int count; try { while ((count = reader.read(array, 0, array.length)) > 0) { strBuffer.append(array, 0, count); } } catch (IOException exp) { throw new ScriptException(exp); } return strBuffer.toString(); }
private static String readFully(Reader reader) throws ScriptException { char[] arr = new char[8 * 1024]; // 8K at a time StringBuilder buf = new StringBuilder(); int numChars; try { while ((numChars = reader.read(arr, 0, arr.length)) > 0) { buf.append(arr, 0, numChars); } } catch (IOException exp) { throw new ScriptException(exp); } return buf.toString(); } }
private Object evaluateExpression(ValueExpression expr, ScriptContext ctx) throws ScriptException { try { return expr.getValue(createElContext(ctx)); } catch (ELException elexp) { throw new ScriptException(elexp); } }
private ValueExpression parse(String script, ScriptContext scriptContext) throws ScriptException { try { return expressionFactory.createValueExpression(createElContext(scriptContext), script, Object.class); } catch (ELException ele) { throw new ScriptException(ele); } }
@Override public CompiledScript compile(Reader reader) throws ScriptException { try { InputStream is = new ReaderInputStream(reader); Context context = new Context(is); ModuleEntity module = environment.importModule(context); return new JPHPCompiledScript(module, environment); } catch (IOException e) { throw new ScriptException(e); } catch (Throwable e) { throw new ScriptException(new Exception(e)); } }
@Override public Object eval(ScriptContext context) throws ScriptException { try { try { return module.include(environment); } catch (Exception e) { environment.catchUncaught(e); } catch (Throwable throwable) { throw new RuntimeException(throwable); } finally { try { environment.doFinal(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } } } catch (Throwable e) { throw new ScriptException(new Exception(e)); } return null; }
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { Scriptable scope = setupScope(cx, context); String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "<unknown>" : filename; try { return cx.evaluateReader(scope, reader, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } ScriptException scriptException = new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); throw scriptException; } catch (IOException e) { throw new ScriptException(e); } finally { Context.exit(); } }
return cx.evaluateString(scope, script, filename, 1, null); } catch (Error e) { throw new ScriptException(e.getMessage()); } catch (RhinoException e) { if (e instanceof WrappedException) { new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e);
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { try { // Get engine bindings and send them to Clojure Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE); engineBindings.entrySet().forEach((entry) -> Var.intern(Namespace.findOrCreate(NAMESPACE_SYMBOL), Symbol.create(entry.getKey().intern()), entry.getValue(), true)); Var.pushThreadBindings( RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref(), RT.IN, new LineNumberingPushbackReader(context.getReader()), RT.OUT, context.getWriter(), RT.ERR, context.getErrorWriter())); Object result = Compiler.load(reader); return result; } catch (Exception e) { throw new ScriptException(e); } finally { Namespace.remove(NAMESPACE_SYMBOL); } }
throw new ScriptException("No LookupService was defined by the script."); throw new ScriptException("Script engine is not Invocable, cannot be used for ScriptedLookupService");
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); throw new ScriptException(e);
throw new ScriptException("No RecordSetWriterFactory was defined by the script.");
throw new ScriptException("No RecordReader was defined by the script.");
@Override public Object eval(String script, ScriptContext context) throws ScriptException { Scriptable scope = setupScope(cx, context); String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "<unknown>" : filename; try { return cx.evaluateString(scope, script, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } ScriptException scriptException = new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); throw scriptException; } finally { Context.exit(); } }
throw new ScriptException("No processor was defined by the script.");
throw new ScriptException("No LookupService was defined by the script.");
@OnDisabled public void onDisabled(final ConfigurationContext context) { // Call an non-interface method onDisabled(context), to allow a scripted LookupService the chance to shut down as necessary final Invocable invocable = (Invocable) scriptEngine; if (configurationContext != null) { try { // Get the actual object from the script engine, versus the proxy stored in lookupService. The object may have additional methods, // where lookupService is a proxied interface final Object obj = scriptEngine.get("lookupService"); if (obj != null) { try { invocable.invokeMethod(obj, "onDisabled", context); } catch (final NoSuchMethodException nsme) { if (getLogger().isDebugEnabled()) { getLogger().debug("Configured script LookupService does not contain an onDisabled() method."); } } } else { throw new ScriptException("No LookupService was defined by the script."); } } catch (ScriptException se) { throw new ProcessException("Error executing onDisabled(context) method", se); } } }
/** * {@inheritDoc} */ @Override public CompiledScript compile(final String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (Exception e) { throw new ScriptException(e); } }
private Object evaluateExpression(ValueExpression expr, ScriptContext ctx) throws ScriptException { try { return expr.getValue(createElContext(ctx)); } catch (ELException elexp) { throw new ScriptException(elexp); } }
private Object evaluateExpression(ValueExpression expr, ScriptContext ctx) throws ScriptException { try { return expr.getValue(createElContext(ctx)); } catch (ELException elexp) { throw new ScriptException(elexp); } }