scriptException.initCause(e);
@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(); } }
@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(); } }
private static void throwScriptExecutionException(String parseLocation, Object[] params, Throwable e) throws ScriptException { ScriptException se = new ScriptException("Cannot execute script: " + parseLocation + " for params " + Arrays.asList(params).toString()); se.initCause(e); throw se; }
private static void throwScriptExecutionException(String parseLocation, Object[] params, Throwable e) throws ScriptException { ScriptException se = new ScriptException("Cannot execute script: " + parseLocation + " for params " + Arrays.asList(params).toString()); se.initCause(e); throw se; }
private static void throwScriptCompilationException(String parseLocation, String msg, Throwable t) throws ScriptException { if (t == null) { throw new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg); } else { ScriptException se = new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg); se.initCause(t); throw se; } }
private static void throwScriptCompilationException(String parseLocation, String msg, Throwable t) throws ScriptException { if (t == null) { throw new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg); } else { ScriptException se = new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg); se.initCause(t); throw se; } }
/** * Returns the parsed xml document. * * @param text xml string or document needed to be parser * @return parsed document */ public Document parseXml(String text) throws ScriptException { InputSource sax = new InputSource(new java.io.StringReader(text)); DOMParser parser = new DOMParser(); Document doc; try { parser.parse(sax); doc = parser.getDocument(); doc.getDocumentElement().normalize(); } catch (SAXException | IOException e) { ScriptException scriptException = new ScriptException("Failed to parse provided xml"); scriptException.initCause(e); throw scriptException; } return doc; }
/** * This method will convert the message payload in to xml string. * * @param omElement axiom element representation of xml document * @return xml string by adding the xml content * @throws ScriptException when error */ public Object toScriptXML(OMElement omElement) throws ScriptException { String xmlString; if (omElement == null) { return null; } try { xmlString = omElement.toStringWithConsume(); } catch (XMLStreamException e) { ScriptException scriptException = new ScriptException("Failed to convert OMElement to a string"); scriptException.initCause(e); throw scriptException; } return xmlString; } }
private void _setContext(ScriptContext c) throws ScriptException { try { this.jep.set("context", c); } catch (JepException e) { throw (ScriptException) new ScriptException(e.getMessage()) .initCause(e); } }
@Override public synchronized Class<?> lookupClass(final String alias) throws ScriptException { final String componentAlias = stripArrayNotation(alias); final Class<?> type = aliasMap().get(componentAlias); if (type != null) { final int arrayDim = (alias.length() - componentAlias.length()) / 2; return Types.array(type, arrayDim); } try { final Class<?> c = Types.load(alias, false); aliasMap().put(alias, c); return c; } catch (final IllegalArgumentException exc) { final ScriptException se = new ScriptException("Unknown type: " + alias); se.initCause(exc); throw se; } }
@Override public synchronized Class<?> lookupClass(final String alias) throws ScriptException { final String componentAlias = stripArrayNotation(alias); final Class<?> type = aliasMap().get(componentAlias); if (type != null) { final int arrayDim = (alias.length() - componentAlias.length()) / 2; return Types.array(type, arrayDim); } try { final Class<?> c = Types.load(alias, false); aliasMap().put(alias, c); return c; } catch (final IllegalArgumentException exc) { final ScriptException se = new ScriptException("Unknown type: " + alias); se.initCause(exc); throw se; } }
@Override public Object eval(final Trace trace) throws ScriptException { try { final Object result = expression().resolve(trace); if(StandardAdapter.isSet(result)) { return result; } return null; } catch(final GrinException e) { final ScriptException ex = new ScriptException(String.format("Execution of %s aborted", name())); ex.initCause(e); throw ex; } }
/** * Make a new JepScriptEngine * * @throws ScriptException * if an error occurs */ public JepScriptEngine() throws ScriptException { try { // make interactive because javax.script sucks this.jep = new Jep(new JepConfig().setInteractive(true)); this.jep.setClassLoader( Thread.currentThread().getContextClassLoader()); } catch (JepException e) { throw (ScriptException) new ScriptException(e.getMessage()) .initCause(e); } }
private Object eval(String line, ScriptContext context, Bindings b) throws ScriptException { this.jep.setInteractive(true); try { _setContext(context); this.jep.eval(line); } catch (JepException e) { throw (ScriptException) new ScriptException(e.getMessage()) .initCause(e); } return null; }
private Object eval(Reader reader, ScriptContext context, Bindings bindings) throws ScriptException { try { // make sure to always set a context, even if null (None) _setContext(context); // turn off interactive mode this.jep.setInteractive(false); File temp = writeTemp(reader); // okay sic jep on it this.jep.runScript(temp.getAbsolutePath()); } catch (IOException e) { throw new ScriptException( "Error writing to file: " + e.getMessage()); } catch (JepException e) { throw (ScriptException) new ScriptException(e.getMessage()) .initCause(e); } return null; }
public Object eval(ScriptContext context) throws ScriptException { Object result = null; Context cx = RhinoScriptEngine.enterContext(); try { Scriptable scope = engine.getRuntimeScope(context); Object ret = script.exec(cx, scope); result = engine.unwrapReturnValue(ret); } catch (RhinoException re) { int line = (line = re.lineNumber()) == 0 ? -1 : line; String msg; if (re instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException)re).getValue()); } else { msg = re.toString(); } ScriptException se = new ScriptException(msg, re.sourceName(), line); se.initCause(re); throw se; } finally { Context.exit(); } return result; }
public Object eval(Reader reader, ScriptContext ctxt) throws ScriptException { Object ret; Context cx = enterContext(); try { Scriptable scope = getRuntimeScope(ctxt); String filename = (String) get(ScriptEngine.FILENAME); filename = filename == null ? "<Unknown source>" : filename; ret = cx.evaluateReader(scope, reader, filename , 1, null); } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; String msg; if (re instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException)re).getValue()); } else { msg = re.toString(); } ScriptException se = new ScriptException(msg, re.sourceName(), line); se.initCause(re); throw se; } catch (IOException ee) { throw new ScriptException(ee); } finally { cx.exit(); } return unwrapReturnValue(ret); }
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { try ( Interpreter bsh = getInterpreter() ) { NameSpace contextNameSpace = getEngineNameSpace(scriptContext); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } } catch (ParseException e) { // explicit parsing error throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (IOException e) { throw new ScriptException(e.toString()); } }
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { bsh.NameSpace contextNameSpace = getEngineNameSpace(scriptContext); Interpreter bsh = getInterpreter(); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); try { if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } //} catch (ParseException e) { // explicit parsing error TODO how to handle parse exception ? //throw new ScriptException(e.toString()); //e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception // set it as the cause ? ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (InterpreterError e) { // The interpreter had a fatal problem throw new ScriptException(e.toString()); } }