org.springframework.scripting.ScriptSource

Here are the examples of the java api org.springframework.scripting.ScriptSource taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

60 Examples 7

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

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

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    return null;
}

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

@Nullable
protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager(this.beanClreplacedLoader);
    if (this.scriptEngineName != null) {
        return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.scriptEngineName);
    }
    if (scriptSource instanceof ResourceScriptSource) {
        String filename = ((ResourceScriptSource) scriptSource).getResource().getFilename();
        if (filename != null) {
            String extension = StringUtils.getFilenameExtension(filename);
            if (extension != null) {
                ScriptEngine engine = scriptEngineManager.getEngineByExtension(extension);
                if (engine != null) {
                    return engine;
                }
            }
        }
    }
    return null;
}

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

@Nullable
protected Object adaptToInterfaces(@Nullable Object script, ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) {
    Clreplaced<?> adaptedIfc;
    if (actualInterfaces.length == 1) {
        adaptedIfc = actualInterfaces[0];
    } else {
        adaptedIfc = ClreplacedUtils.createCompositeInterface(actualInterfaces, this.beanClreplacedLoader);
    }
    if (adaptedIfc != null) {
        ScriptEngine scriptEngine = this.scriptEngine;
        if (!(scriptEngine instanceof Invocable)) {
            throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine);
        }
        Invocable invocable = (Invocable) scriptEngine;
        if (script != null) {
            script = invocable.getInterface(script, adaptedIfc);
        }
        if (script == null) {
            script = invocable.getInterface(adaptedIfc);
            if (script == null) {
                throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]");
            }
        }
    }
    return script;
}

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

protected Object evaluateScript(ScriptSource scriptSource) {
    try {
        ScriptEngine scriptEngine = this.scriptEngine;
        if (scriptEngine == null) {
            scriptEngine = retrieveScriptEngine(scriptSource);
            if (scriptEngine == null) {
                throw new IllegalStateException("Could not determine script engine for " + scriptSource);
            }
            this.scriptEngine = scriptEngine;
        }
        return scriptEngine.eval(scriptSource.getScriptreplacedtring());
    } catch (Exception ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : StandardScriptFactory.java
with MIT License
from Vip-Augus

/**
 * Load and parse the script via JSR-223's ScriptEngine.
 */
@Override
@Nullable
public Object getScriptedObject(ScriptSource scriptSource, @Nullable Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    Object script = evaluateScript(scriptSource);
    if (!ObjectUtils.isEmpty(actualInterfaces)) {
        boolean adaptationRequired = false;
        for (Clreplaced<?> requestedIfc : actualInterfaces) {
            if (script instanceof Clreplaced ? !requestedIfc.isreplacedignableFrom((Clreplaced<?>) script) : !requestedIfc.isInstance(script)) {
                adaptationRequired = true;
                break;
            }
        }
        if (adaptationRequired) {
            script = adaptToInterfaces(script, scriptSource, actualInterfaces);
        }
    }
    if (script instanceof Clreplaced) {
        Clreplaced<?> scriptClreplaced = (Clreplaced<?>) script;
        try {
            return ReflectionUtils.accessibleConstructor(scriptClreplaced).newInstance();
        } catch (NoSuchMethodException ex) {
            throw new ScriptCompilationException("No default constructor on script clreplaced: " + scriptClreplaced.getName(), ex);
        } catch (InstantiationException ex) {
            throw new ScriptCompilationException(scriptSource, "Unable to instantiate script clreplaced: " + scriptClreplaced.getName(), ex);
        } catch (IllegalAccessException ex) {
            throw new ScriptCompilationException(scriptSource, "Could not access script constructor: " + scriptClreplaced.getName(), ex);
        } catch (InvocationTargetException ex) {
            throw new ScriptCompilationException("Failed to invoke script constructor: " + scriptClreplaced.getName(), ex.getTargetException());
        }
    }
    return script;
}

19 Source : StandardScriptEvaluator.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Object evaluate(ScriptSource script) {
    return evaluate(script, null);
}

19 Source : ScriptFactoryPostProcessor.java
with MIT License
from Vip-Augus

/**
 * Obtain a ScriptSource for the given bean, lazily creating it
 * if not cached already.
 * @param beanName the name of the scripted bean
 * @param scriptSourceLocator the script source locator replacedociated with the bean
 * @return the corresponding ScriptSource instance
 * @see #convertToScriptSource
 */
protected ScriptSource getScriptSource(String beanName, String scriptSourceLocator) {
    synchronized (this.scriptSourceCache) {
        ScriptSource scriptSource = this.scriptSourceCache.get(beanName);
        if (scriptSource == null) {
            scriptSource = convertToScriptSource(beanName, scriptSourceLocator, this.resourceLoader);
            this.scriptSourceCache.put(beanName, scriptSource);
        }
        return scriptSource;
    }
}

19 Source : RefreshableScriptTargetSource.java
with MIT License
from Vip-Augus

/**
 * Subclreplaced of {@link BeanFactoryRefreshableTargetSource} that determines whether
 * a refresh is required through the given {@link ScriptFactory}.
 *
 * @author Rob Harrop
 * @author Juergen Hoeller
 * @author Mark Fisher
 * @since 2.0
 */
public clreplaced RefreshableScriptTargetSource extends BeanFactoryRefreshableTargetSource {

    private final ScriptFactory scriptFactory;

    private final ScriptSource scriptSource;

    private final boolean isFactoryBean;

    /**
     * Create a new RefreshableScriptTargetSource.
     * @param beanFactory the BeanFactory to fetch the scripted bean from
     * @param beanName the name of the target bean
     * @param scriptFactory the ScriptFactory to delegate to for determining
     * whether a refresh is required
     * @param scriptSource the ScriptSource for the script definition
     * @param isFactoryBean whether the target script defines a FactoryBean
     */
    public RefreshableScriptTargetSource(BeanFactory beanFactory, String beanName, ScriptFactory scriptFactory, ScriptSource scriptSource, boolean isFactoryBean) {
        super(beanFactory, beanName);
        replacedert.notNull(scriptFactory, "ScriptFactory must not be null");
        replacedert.notNull(scriptSource, "ScriptSource must not be null");
        this.scriptFactory = scriptFactory;
        this.scriptSource = scriptSource;
        this.isFactoryBean = isFactoryBean;
    }

    /**
     * Determine whether a refresh is required through calling
     * ScriptFactory's {@code requiresScriptedObjectRefresh} method.
     * @see ScriptFactory#requiresScriptedObjectRefresh(ScriptSource)
     */
    @Override
    protected boolean requiresRefresh() {
        return this.scriptFactory.requiresScriptedObjectRefresh(this.scriptSource);
    }

    /**
     * Obtain a fresh target object, retrieving a FactoryBean if necessary.
     */
    @Override
    protected Object obtainFreshBean(BeanFactory beanFactory, String beanName) {
        return super.obtainFreshBean(beanFactory, (this.isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName));
    }
}

19 Source : GroovyScriptFactory.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    synchronized (this.scriptClreplacedMonitor) {
        try {
            if (this.scriptClreplaced == null || scriptSource.isModified()) {
                // New script content...
                this.wasModifiedForTypeCheck = true;
                this.scriptClreplaced = getGroovyClreplacedLoader().parseClreplaced(scriptSource.getScriptreplacedtring(), scriptSource.suggestedClreplacedName());
                if (Script.clreplaced.isreplacedignableFrom(this.scriptClreplaced)) {
                    // A Groovy script, probably creating an instance: let's execute it.
                    Object result = executeScript(scriptSource, this.scriptClreplaced);
                    this.scriptResultClreplaced = (result != null ? result.getClreplaced() : null);
                    this.cachedResult = new CachedResultHolder(result);
                } else {
                    this.scriptResultClreplaced = this.scriptClreplaced;
                }
            }
            return this.scriptResultClreplaced;
        } catch (CompilationFailedException ex) {
            this.scriptClreplaced = null;
            this.scriptResultClreplaced = null;
            this.cachedResult = null;
            throw new ScriptCompilationException(scriptSource, ex);
        }
    }
}

19 Source : GroovyScriptFactory.java
with MIT License
from Vip-Augus

@Override
public boolean requiresScriptedObjectRefresh(ScriptSource scriptSource) {
    synchronized (this.scriptClreplacedMonitor) {
        return (scriptSource.isModified() || this.wasModifiedForTypeCheck);
    }
}

19 Source : GroovyScriptFactory.java
with MIT License
from Vip-Augus

/**
 * Loads and parses the Groovy script via the GroovyClreplacedLoader.
 * @see groovy.lang.GroovyClreplacedLoader
 */
@Override
@Nullable
public Object getScriptedObject(ScriptSource scriptSource, @Nullable Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    synchronized (this.scriptClreplacedMonitor) {
        try {
            Clreplaced<?> scriptClreplacedToExecute;
            this.wasModifiedForTypeCheck = false;
            if (this.cachedResult != null) {
                Object result = this.cachedResult.object;
                this.cachedResult = null;
                return result;
            }
            if (this.scriptClreplaced == null || scriptSource.isModified()) {
                // New script content...
                this.scriptClreplaced = getGroovyClreplacedLoader().parseClreplaced(scriptSource.getScriptreplacedtring(), scriptSource.suggestedClreplacedName());
                if (Script.clreplaced.isreplacedignableFrom(this.scriptClreplaced)) {
                    // A Groovy script, probably creating an instance: let's execute it.
                    Object result = executeScript(scriptSource, this.scriptClreplaced);
                    this.scriptResultClreplaced = (result != null ? result.getClreplaced() : null);
                    return result;
                } else {
                    this.scriptResultClreplaced = this.scriptClreplaced;
                }
            }
            scriptClreplacedToExecute = this.scriptClreplaced;
            // Process re-execution outside of the synchronized block.
            return executeScript(scriptSource, scriptClreplacedToExecute);
        } catch (CompilationFailedException ex) {
            this.scriptClreplaced = null;
            this.scriptResultClreplaced = null;
            throw new ScriptCompilationException(scriptSource, ex);
        }
    }
}

19 Source : GroovyScriptEvaluator.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
    GroovyShell groovyShell = new GroovyShell(this.clreplacedLoader, new Binding(arguments), this.compilerConfiguration);
    try {
        String filename = (script instanceof ResourceScriptSource ? ((ResourceScriptSource) script).getResource().getFilename() : null);
        if (filename != null) {
            return groovyShell.evaluate(script.getScriptreplacedtring(), filename);
        } else {
            return groovyShell.evaluate(script.getScriptreplacedtring());
        }
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access Groovy script", ex);
    } catch (GroovyRuntimeException ex) {
        throw new ScriptCompilationException(script, ex);
    }
}

19 Source : BshScriptFactory.java
with MIT License
from Vip-Augus

/**
 * Load and parse the BeanShell script via {@link BshScriptUtils}.
 * @see BshScriptUtils#createBshObject(String, Clreplaced[], ClreplacedLoader)
 */
@Override
@Nullable
public Object getScriptedObject(ScriptSource scriptSource, @Nullable Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    Clreplaced<?> clazz;
    try {
        synchronized (this.scriptClreplacedMonitor) {
            boolean requiresScriptEvaluation = (this.wasModifiedForTypeCheck && this.scriptClreplaced == null);
            this.wasModifiedForTypeCheck = false;
            if (scriptSource.isModified() || requiresScriptEvaluation) {
                // New script content: Let's check whether it evaluates to a Clreplaced.
                Object result = BshScriptUtils.evaluateBshScript(scriptSource.getScriptreplacedtring(), actualInterfaces, this.beanClreplacedLoader);
                if (result instanceof Clreplaced) {
                    // A Clreplaced: We'll cache the Clreplaced here and create an instance
                    // outside of the synchronized block.
                    this.scriptClreplaced = (Clreplaced<?>) result;
                } else {
                    // Not a Clreplaced: OK, we'll simply create BeanShell objects
                    // through evaluating the script for every call later on.
                    // For this first-time check, let's simply return the
                    // already evaluated object.
                    return result;
                }
            }
            clazz = this.scriptClreplaced;
        }
    } catch (EvalError ex) {
        this.scriptClreplaced = null;
        throw new ScriptCompilationException(scriptSource, ex);
    }
    if (clazz != null) {
        // A Clreplaced: We need to create an instance for every call.
        try {
            return ReflectionUtils.accessibleConstructor(clazz).newInstance();
        } catch (Throwable ex) {
            throw new ScriptCompilationException(scriptSource, "Could not instantiate script clreplaced: " + clazz.getName(), ex);
        }
    } else {
        // Not a Clreplaced: We need to evaluate the script for every call.
        try {
            return BshScriptUtils.createBshObject(scriptSource.getScriptreplacedtring(), actualInterfaces, this.beanClreplacedLoader);
        } catch (EvalError ex) {
            throw new ScriptCompilationException(scriptSource, ex);
        }
    }
}

19 Source : BshScriptFactory.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    synchronized (this.scriptClreplacedMonitor) {
        try {
            if (scriptSource.isModified()) {
                // New script content: Let's check whether it evaluates to a Clreplaced.
                this.wasModifiedForTypeCheck = true;
                this.scriptClreplaced = BshScriptUtils.determineBshObjectType(scriptSource.getScriptreplacedtring(), this.beanClreplacedLoader);
            }
            return this.scriptClreplaced;
        } catch (EvalError ex) {
            this.scriptClreplaced = null;
            throw new ScriptCompilationException(scriptSource, ex);
        }
    }
}

19 Source : BshScriptEvaluator.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
    try {
        Interpreter interpreter = new Interpreter();
        interpreter.setClreplacedLoader(this.clreplacedLoader);
        if (arguments != null) {
            for (Map.Entry<String, Object> entry : arguments.entrySet()) {
                interpreter.set(entry.getKey(), entry.getValue());
            }
        }
        return interpreter.eval(new StringReader(script.getScriptreplacedtring()));
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
    } catch (EvalError ex) {
        throw new ScriptCompilationException(script, ex);
    }
}

19 Source : StandardScriptFactory.java
with MIT License
from mindcarver

/**
 * Load and parse the script via JSR-223's ScriptEngine.
 */
@Override
@Nullable
public Object getScriptedObject(ScriptSource scriptSource, @Nullable Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    Object script = evaluateScript(scriptSource);
    if (!ObjectUtils.isEmpty(actualInterfaces)) {
        boolean adaptationRequired = false;
        for (Clreplaced<?> requestedIfc : actualInterfaces) {
            if (script instanceof Clreplaced ? !requestedIfc.isreplacedignableFrom((Clreplaced<?>) script) : !requestedIfc.isInstance(script)) {
                adaptationRequired = true;
            }
        }
        if (adaptationRequired) {
            script = adaptToInterfaces(script, scriptSource, actualInterfaces);
        }
    }
    if (script instanceof Clreplaced) {
        Clreplaced<?> scriptClreplaced = (Clreplaced<?>) script;
        try {
            return ReflectionUtils.accessibleConstructor(scriptClreplaced).newInstance();
        } catch (NoSuchMethodException ex) {
            throw new ScriptCompilationException("No default constructor on script clreplaced: " + scriptClreplaced.getName(), ex);
        } catch (InstantiationException ex) {
            throw new ScriptCompilationException(scriptSource, "Unable to instantiate script clreplaced: " + scriptClreplaced.getName(), ex);
        } catch (IllegalAccessException ex) {
            throw new ScriptCompilationException(scriptSource, "Could not access script constructor: " + scriptClreplaced.getName(), ex);
        } catch (InvocationTargetException ex) {
            throw new ScriptCompilationException("Failed to invoke script constructor: " + scriptClreplaced.getName(), ex.getTargetException());
        }
    }
    return script;
}

19 Source : StandardScriptFactory.java
with Apache License 2.0
from langtianya

protected Object adaptToInterfaces(Object script, ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) {
    Clreplaced<?> adaptedIfc;
    if (actualInterfaces.length == 1) {
        adaptedIfc = actualInterfaces[0];
    } else {
        adaptedIfc = ClreplacedUtils.createCompositeInterface(actualInterfaces, this.beanClreplacedLoader);
    }
    if (adaptedIfc != null) {
        if (!(this.scriptEngine instanceof Invocable)) {
            throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + this.scriptEngine);
        }
        Invocable invocable = (Invocable) this.scriptEngine;
        if (script != null) {
            script = invocable.getInterface(script, adaptedIfc);
        }
        if (script == null) {
            script = invocable.getInterface(adaptedIfc);
            if (script == null) {
                throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]");
            }
        }
    }
    return script;
}

19 Source : StandardScriptFactory.java
with Apache License 2.0
from langtianya

@Override
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    return null;
}

19 Source : StandardScriptFactory.java
with Apache License 2.0
from langtianya

protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager(this.beanClreplacedLoader);
    if (this.scriptEngineName != null) {
        return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.scriptEngineName);
    }
    if (scriptSource instanceof ResourceScriptSource) {
        String filename = ((ResourceScriptSource) scriptSource).getResource().getFilename();
        if (filename != null) {
            String extension = StringUtils.getFilenameExtension(filename);
            if (extension != null) {
                ScriptEngine engine = scriptEngineManager.getEngineByExtension(extension);
                if (engine != null) {
                    return engine;
                }
            }
        }
    }
    return null;
}

19 Source : StandardScriptFactory.java
with Apache License 2.0
from langtianya

protected Object evaluateScript(ScriptSource scriptSource) {
    try {
        if (this.scriptEngine == null) {
            this.scriptEngine = retrieveScriptEngine(scriptSource);
            if (this.scriptEngine == null) {
                throw new IllegalStateException("Could not determine script engine for " + scriptSource);
            }
        }
        return this.scriptEngine.eval(scriptSource.getScriptreplacedtring());
    } catch (Exception ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : StandardScriptFactory.java
with Apache License 2.0
from langtianya

/**
 * Load and parse the script via JSR-223's ScriptEngine.
 */
@Override
public Object getScriptedObject(ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    Object script = evaluateScript(scriptSource);
    if (!ObjectUtils.isEmpty(actualInterfaces)) {
        boolean adaptationRequired = false;
        for (Clreplaced<?> requestedIfc : actualInterfaces) {
            if (script instanceof Clreplaced ? !requestedIfc.isreplacedignableFrom((Clreplaced<?>) script) : !requestedIfc.isInstance(script)) {
                adaptationRequired = true;
            }
        }
        if (adaptationRequired) {
            script = adaptToInterfaces(script, scriptSource, actualInterfaces);
        }
    }
    if (script instanceof Clreplaced) {
        Clreplaced<?> scriptClreplaced = (Clreplaced<?>) script;
        try {
            return scriptClreplaced.newInstance();
        } catch (InstantiationException ex) {
            throw new ScriptCompilationException(scriptSource, "Could not instantiate script clreplaced: " + scriptClreplaced.getName(), ex);
        } catch (IllegalAccessException ex) {
            throw new ScriptCompilationException(scriptSource, "Could not access script constructor: " + scriptClreplaced.getName(), ex);
        }
    }
    return script;
}

19 Source : StandardScriptEvaluator.java
with Apache License 2.0
from langtianya

@Override
public Object evaluate(ScriptSource script) {
    return evaluate(script, null);
}

19 Source : StandardScriptEvaluator.java
with Apache License 2.0
from langtianya

@Override
public Object evaluate(ScriptSource script, Map<String, Object> argumentBindings) {
    ScriptEngine engine = getScriptEngine(script);
    try {
        if (CollectionUtils.isEmpty(argumentBindings)) {
            return engine.eval(script.getScriptreplacedtring());
        } else {
            Bindings bindings = StandardScriptUtils.getBindings(argumentBindings);
            return engine.eval(script.getScriptreplacedtring(), bindings);
        }
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access script for ScriptEngine", ex);
    } catch (ScriptException ex) {
        throw new ScriptCompilationException(script, new StandardScriptEvalException(ex));
    }
}

19 Source : StandardScriptEvaluator.java
with Apache License 2.0
from langtianya

/**
 * Obtain the JSR-223 ScriptEngine to use for the given script.
 * @param script the script to evaluate
 * @return the ScriptEngine (never {@code null})
 */
protected ScriptEngine getScriptEngine(ScriptSource script) {
    if (this.scriptEngineManager == null) {
        this.scriptEngineManager = new ScriptEngineManager();
    }
    if (StringUtils.hasText(this.engineName)) {
        return StandardScriptUtils.retrieveEngineByName(this.scriptEngineManager, this.engineName);
    } else if (script instanceof ResourceScriptSource) {
        Resource resource = ((ResourceScriptSource) script).getResource();
        String extension = StringUtils.getFilenameExtension(resource.getFilename());
        if (extension == null) {
            throw new IllegalStateException("No script language defined, and no file extension defined for resource: " + resource);
        }
        ScriptEngine engine = this.scriptEngineManager.getEngineByExtension(extension);
        if (engine == null) {
            throw new IllegalStateException("No matching engine found for file extension '" + extension + "'");
        }
        return engine;
    } else {
        throw new IllegalStateException("No script language defined, and no resource replacedociated with script: " + script);
    }
}

19 Source : JRubyScriptFactory.java
with Apache License 2.0
from langtianya

/**
 * Load and parse the JRuby script via JRubyScriptUtils.
 * @see JRubyScriptUtils#createJRubyObject(String, Clreplaced[], ClreplacedLoader)
 */
@Override
public Object getScriptedObject(ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    try {
        return JRubyScriptUtils.createJRubyObject(scriptSource.getScriptreplacedtring(), actualInterfaces, this.beanClreplacedLoader);
    } catch (RaiseException ex) {
        RubyException rubyEx = ex.getException();
        String msg = (rubyEx != null && rubyEx.message != null) ? rubyEx.message.toString() : "Unexpected JRuby error";
        throw new ScriptCompilationException(scriptSource, msg, ex);
    } catch (JumpException ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : GroovyScriptFactory.java
with Apache License 2.0
from langtianya

@Override
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    try {
        synchronized (this.scriptClreplacedMonitor) {
            if (this.scriptClreplaced == null || scriptSource.isModified()) {
                // New script content...
                this.wasModifiedForTypeCheck = true;
                this.scriptClreplaced = getGroovyClreplacedLoader().parseClreplaced(scriptSource.getScriptreplacedtring(), scriptSource.suggestedClreplacedName());
                if (Script.clreplaced.isreplacedignableFrom(this.scriptClreplaced)) {
                    // A Groovy script, probably creating an instance: let's execute it.
                    Object result = executeScript(scriptSource, this.scriptClreplaced);
                    this.scriptResultClreplaced = (result != null ? result.getClreplaced() : null);
                    this.cachedResult = new CachedResultHolder(result);
                } else {
                    this.scriptResultClreplaced = this.scriptClreplaced;
                }
            }
            return this.scriptResultClreplaced;
        }
    } catch (CompilationFailedException ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : GroovyScriptFactory.java
with Apache License 2.0
from langtianya

/**
 * Loads and parses the Groovy script via the GroovyClreplacedLoader.
 * @see groovy.lang.GroovyClreplacedLoader
 */
@Override
public Object getScriptedObject(ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    try {
        Clreplaced<?> scriptClreplacedToExecute;
        synchronized (this.scriptClreplacedMonitor) {
            this.wasModifiedForTypeCheck = false;
            if (this.cachedResult != null) {
                Object result = this.cachedResult.object;
                this.cachedResult = null;
                return result;
            }
            if (this.scriptClreplaced == null || scriptSource.isModified()) {
                // New script content...
                this.scriptClreplaced = getGroovyClreplacedLoader().parseClreplaced(scriptSource.getScriptreplacedtring(), scriptSource.suggestedClreplacedName());
                if (Script.clreplaced.isreplacedignableFrom(this.scriptClreplaced)) {
                    // A Groovy script, probably creating an instance: let's execute it.
                    Object result = executeScript(scriptSource, this.scriptClreplaced);
                    this.scriptResultClreplaced = (result != null ? result.getClreplaced() : null);
                    return result;
                } else {
                    this.scriptResultClreplaced = this.scriptClreplaced;
                }
            }
            scriptClreplacedToExecute = this.scriptClreplaced;
        }
        // Process re-execution outside of the synchronized block.
        return executeScript(scriptSource, scriptClreplacedToExecute);
    } catch (CompilationFailedException ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : GroovyScriptEvaluator.java
with Apache License 2.0
from langtianya

@Override
public Object evaluate(ScriptSource script, Map<String, Object> arguments) {
    GroovyShell groovyShell = new GroovyShell(this.clreplacedLoader, new Binding(arguments));
    try {
        String filename = (script instanceof ResourceScriptSource ? ((ResourceScriptSource) script).getResource().getFilename() : null);
        if (filename != null) {
            return groovyShell.evaluate(script.getScriptreplacedtring(), filename);
        } else {
            return groovyShell.evaluate(script.getScriptreplacedtring());
        }
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access Groovy script", ex);
    } catch (GroovyRuntimeException ex) {
        throw new ScriptCompilationException(script, ex);
    }
}

19 Source : BshScriptFactory.java
with Apache License 2.0
from langtianya

@Override
public Clreplaced<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
    try {
        synchronized (this.scriptClreplacedMonitor) {
            if (scriptSource.isModified()) {
                // New script content: Let's check whether it evaluates to a Clreplaced.
                this.wasModifiedForTypeCheck = true;
                this.scriptClreplaced = BshScriptUtils.determineBshObjectType(scriptSource.getScriptreplacedtring(), this.beanClreplacedLoader);
            }
            return this.scriptClreplaced;
        }
    } catch (EvalError ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : BshScriptFactory.java
with Apache License 2.0
from langtianya

/**
 * Load and parse the BeanShell script via {@link BshScriptUtils}.
 * @see BshScriptUtils#createBshObject(String, Clreplaced[], ClreplacedLoader)
 */
@Override
public Object getScriptedObject(ScriptSource scriptSource, Clreplaced<?>... actualInterfaces) throws IOException, ScriptCompilationException {
    try {
        Clreplaced<?> clazz;
        synchronized (this.scriptClreplacedMonitor) {
            boolean requiresScriptEvaluation = (this.wasModifiedForTypeCheck && this.scriptClreplaced == null);
            this.wasModifiedForTypeCheck = false;
            if (scriptSource.isModified() || requiresScriptEvaluation) {
                // New script content: Let's check whether it evaluates to a Clreplaced.
                Object result = BshScriptUtils.evaluateBshScript(scriptSource.getScriptreplacedtring(), actualInterfaces, this.beanClreplacedLoader);
                if (result instanceof Clreplaced) {
                    // A Clreplaced: We'll cache the Clreplaced here and create an instance
                    // outside of the synchronized block.
                    this.scriptClreplaced = (Clreplaced<?>) result;
                } else {
                    // Not a Clreplaced: OK, we'll simply create BeanShell objects
                    // through evaluating the script for every call later on.
                    // For this first-time check, let's simply return the
                    // already evaluated object.
                    return result;
                }
            }
            clazz = this.scriptClreplaced;
        }
        if (clazz != null) {
            // A Clreplaced: We need to create an instance for every call.
            try {
                return clazz.newInstance();
            } catch (Throwable ex) {
                throw new ScriptCompilationException(scriptSource, "Could not instantiate script clreplaced: " + clazz.getName(), ex);
            }
        } else {
            // Not a Clreplaced: We need to evaluate the script for every call.
            return BshScriptUtils.createBshObject(scriptSource.getScriptreplacedtring(), actualInterfaces, this.beanClreplacedLoader);
        }
    } catch (EvalError ex) {
        throw new ScriptCompilationException(scriptSource, ex);
    }
}

19 Source : BshScriptEvaluator.java
with Apache License 2.0
from langtianya

@Override
public Object evaluate(ScriptSource script, Map<String, Object> arguments) {
    try {
        Interpreter interpreter = new Interpreter();
        interpreter.setClreplacedLoader(this.clreplacedLoader);
        if (arguments != null) {
            for (Map.Entry<String, Object> entry : arguments.entrySet()) {
                interpreter.set(entry.getKey(), entry.getValue());
            }
        }
        return interpreter.eval(new StringReader(script.getScriptreplacedtring()));
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
    } catch (EvalError ex) {
        throw new ScriptCompilationException(script, ex);
    }
}

19 Source : Jsr233Evaluator.java
with Apache License 2.0
from cuba-rnd

@Override
public Object evaluate(ScriptSource script, Map<String, Object> arguments) throws ScriptCompilationException {
    return eval(script, arguments);
}

19 Source : Jsr233Evaluator.java
with Apache License 2.0
from cuba-rnd

@Override
public Object evaluate(ScriptSource script) throws ScriptCompilationException {
    return eval(script, Collections.emptyMap());
}

18 Source : ScriptFactoryPostProcessor.java
with MIT License
from Vip-Augus

/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
    // Avoid recreation of the script bean definition in case of a prototype.
    synchronized (this.scriptBeanFactory) {
        if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {
            this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
            ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.clreplaced);
            ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
            Clreplaced<?>[] interfaces = scriptFactory.getScriptInterfaces();
            Clreplaced<?>[] scriptedInterfaces = interfaces;
            if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
                Clreplaced<?> configInterface = createConfigInterface(bd, interfaces);
                scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
            }
            BeanDefinition objectBd = createScriptedObjectBeanDefinition(bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
            long refreshCheckDelay = resolveRefreshCheckDelay(bd);
            if (refreshCheckDelay >= 0) {
                objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
            }
            this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
        }
    }
}

18 Source : ScriptFactoryPostProcessor.java
with MIT License
from Vip-Augus

/**
 * Create a bean definition for the scripted object, based on the given script
 * definition, extracting the definition data that is relevant for the scripted
 * object (that is, everything but bean clreplaced and constructor arguments).
 * @param bd the full script bean definition
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptSource the ScriptSource for the scripted bean
 * @param interfaces the interfaces that the scripted bean is supposed to implement
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
 */
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, @Nullable Clreplaced<?>[] interfaces) {
    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
}

18 Source : GroovyScriptFactory.java
with MIT License
from Vip-Augus

/**
 * Instantiate the given Groovy script clreplaced and run it if necessary.
 * @param scriptSource the source for the underlying script
 * @param scriptClreplaced the Groovy script clreplaced
 * @return the result object (either an instance of the script clreplaced
 * or the result of running the script instance)
 * @throws ScriptCompilationException in case of instantiation failure
 */
@Nullable
protected Object executeScript(ScriptSource scriptSource, Clreplaced<?> scriptClreplaced) throws ScriptCompilationException {
    try {
        GroovyObject goo = (GroovyObject) ReflectionUtils.accessibleConstructor(scriptClreplaced).newInstance();
        if (this.groovyObjectCustomizer != null) {
            // Allow metaclreplaced 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 clreplaced: let's return it as-is.
            return goo;
        }
    } catch (NoSuchMethodException ex) {
        throw new ScriptCompilationException("No default constructor on Groovy script clreplaced: " + scriptClreplaced.getName(), ex);
    } catch (InstantiationException ex) {
        throw new ScriptCompilationException(scriptSource, "Unable to instantiate Groovy script clreplaced: " + scriptClreplaced.getName(), ex);
    } catch (IllegalAccessException ex) {
        throw new ScriptCompilationException(scriptSource, "Could not access Groovy script constructor: " + scriptClreplaced.getName(), ex);
    } catch (InvocationTargetException ex) {
        throw new ScriptCompilationException("Failed to invoke Groovy script constructor: " + scriptClreplaced.getName(), ex.getTargetException());
    }
}

18 Source : ScriptFactoryPostProcessor.java
with Apache License 2.0
from langtianya

/**
 * Create a bean definition for the scripted object, based on the given script
 * definition, extracting the definition data that is relevant for the scripted
 * object (that is, everything but bean clreplaced and constructor arguments).
 * @param bd the full script bean definition
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptSource the ScriptSource for the scripted bean
 * @param interfaces the interfaces that the scripted bean is supposed to implement
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
 */
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, Clreplaced<?>[] interfaces) {
    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
}

18 Source : GroovyScriptFactory.java
with Apache License 2.0
from langtianya

/**
 * Instantiate the given Groovy script clreplaced and run it if necessary.
 * @param scriptSource the source for the underlying script
 * @param scriptClreplaced the Groovy script clreplaced
 * @return the result object (either an instance of the script clreplaced
 * or the result of running the script instance)
 * @throws ScriptCompilationException in case of instantiation failure
 */
protected Object executeScript(ScriptSource scriptSource, Clreplaced<?> scriptClreplaced) throws ScriptCompilationException {
    try {
        GroovyObject goo = (GroovyObject) scriptClreplaced.newInstance();
        if (this.groovyObjectCustomizer != null) {
            // Allow metaclreplaced 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 clreplaced: let's return it as-is.
            return goo;
        }
    } catch (InstantiationException ex) {
        throw new ScriptCompilationException(scriptSource, "Could not instantiate Groovy script clreplaced: " + scriptClreplaced.getName(), ex);
    } catch (IllegalAccessException ex) {
        throw new ScriptCompilationException(scriptSource, "Could not access Groovy script constructor: " + scriptClreplaced.getName(), ex);
    }
}

18 Source : Jsr233Evaluator.java
with Apache License 2.0
from cuba-rnd

private Object eval(ScriptSource script, Map<String, Object> parameters) {
    String engineName = getEngineName();
    ScriptEngine scriptEngine = manager.getEngineByName(engineName);
    log.trace("Script bindings: {}", parameters);
    try {
        String scriptreplacedtring = script.getScriptreplacedtring();
        log.trace("Script text ({}): \n {} \n", engineName, scriptreplacedtring);
        return scriptEngine.eval(scriptreplacedtring, new SimpleBindings(parameters));
    } catch (IOException | ScriptException e) {
        throw new ScriptCompilationException("Error executing script", e);
    }
}

17 Source : StandardScriptEvaluator.java
with MIT License
from Vip-Augus

/**
 * Obtain the JSR-223 ScriptEngine to use for the given script.
 * @param script the script to evaluate
 * @return the ScriptEngine (never {@code null})
 */
protected ScriptEngine getScriptEngine(ScriptSource script) {
    ScriptEngineManager scriptEngineManager = this.scriptEngineManager;
    if (scriptEngineManager == null) {
        scriptEngineManager = new ScriptEngineManager();
        this.scriptEngineManager = scriptEngineManager;
    }
    if (StringUtils.hasText(this.engineName)) {
        return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.engineName);
    } else if (script instanceof ResourceScriptSource) {
        Resource resource = ((ResourceScriptSource) script).getResource();
        String extension = StringUtils.getFilenameExtension(resource.getFilename());
        if (extension == null) {
            throw new IllegalStateException("No script language defined, and no file extension defined for resource: " + resource);
        }
        ScriptEngine engine = scriptEngineManager.getEngineByExtension(extension);
        if (engine == null) {
            throw new IllegalStateException("No matching engine found for file extension '" + extension + "'");
        }
        return engine;
    } else {
        throw new IllegalStateException("No script language defined, and no resource replacedociated with script: " + script);
    }
}

17 Source : ScriptFactoryPostProcessor.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Clreplaced<?> predictBeanType(Clreplaced<?> beanClreplaced, String beanName) {
    // We only apply special treatment to ScriptFactory implementations here.
    if (!ScriptFactory.clreplaced.isreplacedignableFrom(beanClreplaced)) {
        return null;
    }
    replacedert.state(this.beanFactory != null, "No BeanFactory set");
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    try {
        String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
        String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
        prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
        ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.clreplaced);
        ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
        Clreplaced<?>[] interfaces = scriptFactory.getScriptInterfaces();
        Clreplaced<?> scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
        if (scriptedType != null) {
            return scriptedType;
        } else if (!ObjectUtils.isEmpty(interfaces)) {
            return (interfaces.length == 1 ? interfaces[0] : createCompositeInterface(interfaces));
        } else {
            if (bd.isSingleton()) {
                return this.scriptBeanFactory.getBean(scriptedObjectBeanName).getClreplaced();
            }
        }
    } catch (Exception ex) {
        if (ex instanceof BeanCreationException && ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
            if (logger.isTraceEnabled()) {
                logger.trace("Could not determine scripted object type for bean '" + beanName + "': " + ex.getMessage());
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not determine scripted object type for bean '" + beanName + "'", ex);
            }
        }
    }
    return null;
}

17 Source : ScriptFactoryPostProcessor.java
with MIT License
from Vip-Augus

@Override
public Object postProcessBeforeInstantiation(Clreplaced<?> beanClreplaced, String beanName) {
    // We only apply special treatment to ScriptFactory implementations here.
    if (!ScriptFactory.clreplaced.isreplacedignableFrom(beanClreplaced)) {
        return null;
    }
    replacedert.state(this.beanFactory != null, "No BeanFactory set");
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
    String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
    prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
    ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.clreplaced);
    ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
    boolean isFactoryBean = false;
    try {
        Clreplaced<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
        // Returned type may be null if the factory is unable to determine the type.
        if (scriptedObjectType != null) {
            isFactoryBean = FactoryBean.clreplaced.isreplacedignableFrom(scriptedObjectType);
        }
    } catch (Exception ex) {
        throw new BeanCreationException(beanName, "Could not determine scripted object type for " + scriptFactory, ex);
    }
    long refreshCheckDelay = resolveRefreshCheckDelay(bd);
    if (refreshCheckDelay >= 0) {
        Clreplaced<?>[] interfaces = scriptFactory.getScriptInterfaces();
        RefreshableScriptTargetSource ts = new RefreshableScriptTargetSource(this.scriptBeanFactory, scriptedObjectBeanName, scriptFactory, scriptSource, isFactoryBean);
        boolean proxyTargetClreplaced = resolveProxyTargetClreplaced(bd);
        String language = (String) bd.getAttribute(LANGUAGE_ATTRIBUTE);
        if (proxyTargetClreplaced && (language == null || !language.equals("groovy"))) {
            throw new BeanDefinitionValidationException("Cannot use proxyTargetClreplaced=true with script beans where language is not 'groovy': '" + language + "'");
        }
        ts.setRefreshCheckDelay(refreshCheckDelay);
        return createRefreshableProxy(ts, interfaces, proxyTargetClreplaced);
    }
    if (isFactoryBean) {
        scriptedObjectBeanName = BeanFactory.FACTORY_BEAN_PREFIX + scriptedObjectBeanName;
    }
    return this.scriptBeanFactory.getBean(scriptedObjectBeanName);
}

17 Source : ScriptFactoryPostProcessor.java
with Apache License 2.0
from langtianya

@Override
public Clreplaced<?> predictBeanType(Clreplaced<?> beanClreplaced, String beanName) {
    // We only apply special treatment to ScriptFactory implementations here.
    if (!ScriptFactory.clreplaced.isreplacedignableFrom(beanClreplaced)) {
        return null;
    }
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    try {
        String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
        String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
        prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
        ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.clreplaced);
        ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
        Clreplaced<?>[] interfaces = scriptFactory.getScriptInterfaces();
        Clreplaced<?> scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
        if (scriptedType != null) {
            return scriptedType;
        } else if (!ObjectUtils.isEmpty(interfaces)) {
            return (interfaces.length == 1 ? interfaces[0] : createCompositeInterface(interfaces));
        } else {
            if (bd.isSingleton()) {
                Object bean = this.scriptBeanFactory.getBean(scriptedObjectBeanName);
                if (bean != null) {
                    return bean.getClreplaced();
                }
            }
        }
    } catch (Exception ex) {
        if (ex instanceof BeanCreationException && ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
            if (logger.isTraceEnabled()) {
                logger.trace("Could not determine scripted object type for bean '" + beanName + "': " + ex.getMessage());
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not determine scripted object type for bean '" + beanName + "'", ex);
            }
        }
    }
    return null;
}

17 Source : ScriptFactoryPostProcessor.java
with Apache License 2.0
from langtianya

@Override
public Object postProcessBeforeInstantiation(Clreplaced<?> beanClreplaced, String beanName) {
    // We only apply special treatment to ScriptFactory implementations here.
    if (!ScriptFactory.clreplaced.isreplacedignableFrom(beanClreplaced)) {
        return null;
    }
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
    String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
    prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
    ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.clreplaced);
    ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
    boolean isFactoryBean = false;
    try {
        Clreplaced<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
        // Returned type may be null if the factory is unable to determine the type.
        if (scriptedObjectType != null) {
            isFactoryBean = FactoryBean.clreplaced.isreplacedignableFrom(scriptedObjectType);
        }
    } catch (Exception ex) {
        throw new BeanCreationException(beanName, "Could not determine scripted object type for " + scriptFactory, ex);
    }
    long refreshCheckDelay = resolveRefreshCheckDelay(bd);
    if (refreshCheckDelay >= 0) {
        Clreplaced<?>[] interfaces = scriptFactory.getScriptInterfaces();
        RefreshableScriptTargetSource ts = new RefreshableScriptTargetSource(this.scriptBeanFactory, scriptedObjectBeanName, scriptFactory, scriptSource, isFactoryBean);
        boolean proxyTargetClreplaced = resolveProxyTargetClreplaced(bd);
        String language = (String) bd.getAttribute(LANGUAGE_ATTRIBUTE);
        if (proxyTargetClreplaced && (language == null || !language.equals("groovy"))) {
            throw new BeanDefinitionValidationException("Cannot use proxyTargetClreplaced=true with script beans where language is not 'groovy': '" + language + "'");
        }
        ts.setRefreshCheckDelay(refreshCheckDelay);
        return createRefreshableProxy(ts, interfaces, proxyTargetClreplaced);
    }
    if (isFactoryBean) {
        scriptedObjectBeanName = BeanFactory.FACTORY_BEAN_PREFIX + scriptedObjectBeanName;
    }
    return this.scriptBeanFactory.getBean(scriptedObjectBeanName);
}

16 Source : GroovyScriptFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testScriptedClreplacedThatHasNoPublicNoArgCtor() throws Exception {
    ScriptSource script = mock(ScriptSource.clreplaced);
    String badScript = "clreplaced Foo { protected Foo() {} \n String toString() { 'X' }}";
    given(script.getScriptreplacedtring()).willReturn(badScript);
    given(script.suggestedClreplacedName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
    replacedertEquals("X", factory.getScriptedObject(script).toString());
}

16 Source : GroovyScriptFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPreplacededIn() throws Exception {
    ScriptSource script = mock(ScriptSource.clreplaced);
    given(script.getScriptreplacedtring()).willReturn("clreplaced Bar {}");
    given(script.suggestedClreplacedName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
    Object scriptedObject = factory.getScriptedObject(script);
    replacedertNotNull(scriptedObject);
}

16 Source : GroovyScriptFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testScriptedClreplacedThatDoesNotHaveANoArgCtor() throws Exception {
    ScriptSource script = mock(ScriptSource.clreplaced);
    String badScript = "clreplaced Foo { public Foo(String foo) {}}";
    given(script.getScriptreplacedtring()).willReturn(badScript);
    given(script.suggestedClreplacedName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
    try {
        factory.getScriptedObject(script);
        fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted clreplaced).");
    } catch (ScriptCompilationException expected) {
        replacedertTrue(expected.contains(NoSuchMethodException.clreplaced));
    }
}

16 Source : StandardScriptEvaluator.java
with MIT License
from Vip-Augus

@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> argumentBindings) {
    ScriptEngine engine = getScriptEngine(script);
    try {
        if (CollectionUtils.isEmpty(argumentBindings)) {
            return engine.eval(script.getScriptreplacedtring());
        } else {
            Bindings bindings = StandardScriptUtils.getBindings(argumentBindings);
            return engine.eval(script.getScriptreplacedtring(), bindings);
        }
    } catch (IOException ex) {
        throw new ScriptCompilationException(script, "Cannot access script for ScriptEngine", ex);
    } catch (ScriptException ex) {
        throw new ScriptCompilationException(script, new StandardScriptEvalException(ex));
    }
}

16 Source : GroovyScriptFactoryTests.java
with Apache License 2.0
from SourceHot

@Test
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPreplacededIn() throws Exception {
    ScriptSource script = mock(ScriptSource.clreplaced);
    given(script.getScriptreplacedtring()).willReturn("clreplaced Bar {}");
    given(script.suggestedClreplacedName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
    Object scriptedObject = factory.getScriptedObject(script);
    replacedertThat(scriptedObject).isNotNull();
}

See More Examples