Example usage for org.springframework.scripting ScriptSource isModified

List of usage examples for org.springframework.scripting ScriptSource isModified

Introduction

In this page you can find the example usage for org.springframework.scripting ScriptSource isModified.

Prototype

boolean isModified();

Source Link

Document

Indicate whether the underlying script data has been modified since the last time #getScriptAsString() was called.

Usage

From source file:org.romaz.spring.scripting.ext.rhino.RhinoScriptFactory.java

public boolean requiresScriptedObjectRefresh(ScriptSource scriptSource) {
    return scriptSource.isModified();
}

From source file:org.red5.server.script.groovy.GroovyScriptFactory.java

public Class<?> getScriptedObjectType(ScriptSource scriptSource)
        throws IOException, ScriptCompilationException {

    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);
            } else {
                this.scriptResultClass = this.scriptClass;
            }//from  ww  w.  j av a 2  s.  co m
        }
        return this.scriptResultClass;
    }
}

From source file:org.red5.server.script.groovy.GroovyScriptFactory.java

/**
 * Loads and parses the Groovy script via the GroovyClassLoader.
 * @see groovy.lang.GroovyClassLoader/*from w w w  .ja  va  2s . c  o  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.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;
    }/*w  w w.ja va 2  s  .c  o m*/

    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;
}