List of usage examples for org.springframework.scripting ScriptCompilationException ScriptCompilationException
public ScriptCompilationException(ScriptSource scriptSource, Throwable cause)
From source file:org.romaz.spring.scripting.ext.rhino.RhinoScriptFactory.java
public Object getScriptedObject(ScriptSource actualScriptSource, Class[] interfacesImplementedByScript) throws IOException, ScriptCompilationException { // Fall back on the interfaces passed in via the constructor. if (interfacesImplementedByScript.length == 0) { interfacesImplementedByScript = scriptInterfaces; }/*from w w w . ja va 2 s. c om*/ synchronized (this.scriptClassMonitor) { if (this.cached == null || actualScriptSource.isModified()) { logger.info("Compiling " + getScriptSourceLocator()); Context ctx = Context.enter(); try { ctx.setLanguageVersion(Context.VERSION_1_7); ctx.setOptimizationLevel(9); Script script = ctx.compileString(actualScriptSource.getScriptAsString(), scriptSourceLocator, 1, null); Object scriptExecutionResult = script.exec(ctx, config.getSharedScope()); this.cached = processScriptResult(ctx, config.getSharedScope(), scriptExecutionResult, interfacesImplementedByScript); } catch (RhinoException e) { throw new ScriptCompilationException("Compilation error: " + e.getMessage(), e); } finally { Context.exit(); } } } return this.cached; }
From source file:org.red5.server.script.groovy.GroovyScriptFactory.java
/** * Loads and parses the Groovy script via the GroovyClassLoader. * @see groovy.lang.GroovyClassLoader//from ww w .ja v a2s.co m */ @SuppressWarnings({ "rawtypes" }) public Object getScriptedObject(ScriptSource scriptSource, Class[] actualInterfaces) throws IOException, ScriptCompilationException { try { Class<?> scriptClassToExecute = null; synchronized (this.scriptClassMonitor) { if (this.scriptClass == null || scriptSource.isModified()) { this.scriptClass = this.groovyClassLoader.parseClass(scriptSource.getScriptAsString()); if (Script.class.isAssignableFrom(this.scriptClass)) { // A Groovy script, probably creating an instance: let's execute it. Object result = executeScript(this.scriptClass); this.scriptResultClass = (result != null ? result.getClass() : null); return result; } else { this.scriptResultClass = this.scriptClass; } } scriptClassToExecute = this.scriptClass; } // Process re-execution outside of the synchronized block. return executeScript(scriptClassToExecute); } catch (CompilationFailedException ex) { throw new ScriptCompilationException("Could not compile Groovy script: " + scriptSource, ex); } }
From source file:org.red5.server.script.groovy.GroovyScriptFactory.java
/** * Instantiate the given Groovy script class and run it if necessary. * @param scriptClass the Groovy script class * @return the result object (either an instance of the script class * or the result of running the script instance) * @throws ScriptCompilationException in case of instantiation failure *//*ww w.j ava 2s . co m*/ protected Object executeScript(Class<?> scriptClass) throws ScriptCompilationException { try { GroovyObject goo = (GroovyObject) scriptClass.newInstance(); if (this.groovyObjectCustomizer != null) { // Allow metaclass and other customization. this.groovyObjectCustomizer.customize(goo); } if (goo instanceof Script) { // A Groovy script, probably creating an instance: let's execute it. return ((Script) goo).run(); } else { // An instance of the scripted class: let's return it as-is. return goo; } } catch (InstantiationException ex) { throw new ScriptCompilationException( "Could not instantiate Groovy script class: " + scriptClass.getName(), ex); } catch (IllegalAccessException ex) { throw new ScriptCompilationException( "Could not access Groovy script constructor: " + scriptClass.getName(), ex); } }
From source file:org.red5.server.script.rhino.RhinoScriptFactory.java
/** * Load and parse the Rhino script via RhinoScriptUtils. * * @see RhinoScriptUtils#createRhinoObject(String, Class[]) *//* ww w. ja v a 2 s . c o m*/ public Object getScriptedObject(ScriptSource actualScriptSource, Class[] actualInterfaces) throws IOException, ScriptCompilationException { log.debug("Getting scripted object..."); try { return RhinoScriptUtils.createRhinoObject(actualScriptSource.getScriptAsString(), actualInterfaces, extendedClass); } catch (Exception ex) { throw new ScriptCompilationException("Could not compile Rhino script: " + actualScriptSource, ex); } }