use of javax.script.ScriptEngine in project es6draft by anba.
the class ScriptEngineFactoryTest method testGetScriptEngine.
@Test
public void testGetScriptEngine() {
ScriptEngine scriptEngine = factory.getScriptEngine();
ScriptEngine scriptEngine2 = factory.getScriptEngine();
assertThat(scriptEngine, notNullValue());
assertThat(scriptEngine2, notNullValue());
assertThat(scriptEngine, not(sameInstance(scriptEngine2)));
assertThat(scriptEngine.getFactory(), is(factory));
assertThat(scriptEngine2.getFactory(), is(factory));
}
use of javax.script.ScriptEngine in project camel by apache.
the class ScriptBuilder method checkForOSGiEngine.
private static ScriptEngine checkForOSGiEngine(String language) {
LOG.debug("No script engine found for {} using standard javax.script auto-registration. Checking OSGi registry.", language);
try {
// Test the OSGi environment with the Activator
Class<?> c = Class.forName("org.apache.camel.script.osgi.Activator");
Method mth = c.getDeclaredMethod("getBundleContext");
Object ctx = mth.invoke(null);
LOG.debug("Found OSGi BundleContext: {}", ctx);
if (ctx != null) {
Method resolveScriptEngine = c.getDeclaredMethod("resolveScriptEngine", String.class);
return (ScriptEngine) resolveScriptEngine.invoke(null, language);
}
} catch (Throwable t) {
LOG.debug("Unable to detect OSGi. ScriptEngine for " + language + " cannot be resolved.", t);
}
return null;
}
use of javax.script.ScriptEngine in project camel by apache.
the class ScriptBuilder method evaluateScript.
protected Object evaluateScript(Exchange exchange) {
try {
if (reuseScriptEngine(exchange)) {
// It's not safe to do the evaluation with a single scriptEngine
synchronized (this) {
LOG.debug("Calling doEvaluateScript without creating a new scriptEngine");
return doEvaluateScript(exchange, scriptEngine);
}
} else {
LOG.debug("Calling doEvaluateScript with a new scriptEngine");
// get a new engine which we must for each exchange
ScriptEngine engine = scriptEngineFactory.getScriptEngine();
return doEvaluateScript(exchange, engine);
}
} catch (ScriptException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Script evaluation failed: " + e.getMessage(), e);
}
if (e.getCause() != null) {
throw createScriptEvaluationException(e.getCause());
} else {
throw createScriptEvaluationException(e);
}
} catch (IOException e) {
throw createScriptEvaluationException(e);
}
}
use of javax.script.ScriptEngine in project camel by apache.
the class ScriptBuilder method lookupScriptEngineFactory.
protected static ScriptEngineFactory lookupScriptEngineFactory(String language) {
ScriptEngineManager manager = new ScriptEngineManager();
for (ScriptEngineFactory factory : manager.getEngineFactories()) {
// some script names has alias
String[] names = getScriptNames(language);
for (String name : names) {
if (factory.getLanguageName().equals(name)) {
return factory;
}
}
}
// fallback to get engine by name
ScriptEngine engine = createScriptEngine(language, true);
if (engine != null) {
return engine.getFactory();
}
return null;
}
use of javax.script.ScriptEngine in project gremlin by tinkerpop.
the class GremlinGroovyScriptEngineTest method testGremlinLoading.
public void testGremlinLoading() throws Exception {
ScriptEngine engine = new GremlinGroovyScriptEngine();
List list = new ArrayList();
engine.put("g", TinkerGraphFactory.createTinkerGraph());
engine.put("list", list);
assertEquals(list.size(), 0);
engine.eval("g.v(1).outE.inV._.fill(list)");
assertEquals(list.size(), 3);
}
Aggregations