List of usage examples for javax.script Compilable compile
public CompiledScript compile(Reader script) throws ScriptException;
Reader
) for later execution. From source file:org.apache.camel.builder.script.ScriptBuilder.java
protected void compileScript(Compilable compilable) { try {/* ww w. j a v a 2s . co m*/ if (scriptText != null) { compiledScript = compilable.compile(scriptText); } else if (scriptResource != null) { compiledScript = compilable.compile(createScriptReader()); } } catch (ScriptException e) { if (LOG.isDebugEnabled()) { LOG.debug("Script compile failed: " + e, e); } throw createScriptCompileException(e); } catch (IOException e) { throw createScriptCompileException(e); } }
From source file:org.openadaptor.auxil.processor.script.ScriptProcessor.java
/** * Initialise the script engine.//from w ww . ja v a 2s. com * <br> * This will create a script engine, and compile the supplied * script is compilation is possible, and enabled. * @throws ValidationException */ private void initialise() throws ValidationException { log.info("Initialising script engine for language: " + language); log.debug("Compile flag: " + compile); scriptEngine = createScriptEngine(); if (compile && scriptEngine instanceof Compilable) { Compilable compilableScriptEngine = (Compilable) scriptEngine; try { if (script != null) { log.debug("Compiling script: " + script); compiledScript = compilableScriptEngine.compile(script); } else { log.debug("Compiling script from file: " + scriptFilename); compiledScript = compilableScriptEngine.compile(new FileReader(scriptFilename)); } log.info("Script compiled successfully"); } catch (ScriptException e) { String failMsg = "Failed to compile script, " + e.getMessage() + " line " + e.getLineNumber() + " col " + e.getColumnNumber(); log.warn(failMsg); throw new ValidationException(failMsg, e, this); } catch (FileNotFoundException e) { String failMsg = "Failed to compile script, " + e.getMessage(); log.warn(failMsg); throw new ValidationException(failMsg, e, this); } } //Apply binding to allow scripts to access logging scriptEngine.put(logBinding, log); //Apply extra bindings, if any. applyBindings(scriptEngine, additionalBindings); }