use of javax.script.ScriptEngineFactory in project hazelcast by hazelcast.
the class HazelcastOSGiScriptEngineTest method putAndGetOverBindingsSuccessfully.
@Test
public void putAndGetOverBindingsSuccessfully() {
ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
assertNotNull(engineFactories);
for (ScriptEngineFactory engineFactory : engineFactories) {
verifyThatBindingsPutAndGetOverBindingsSuccessfully(engineFactory.getScriptEngine());
}
}
use of javax.script.ScriptEngineFactory in project hazelcast by hazelcast.
the class HazelcastOSGiScriptEngineTest method bindingsGetAndSetSuccessfully.
@Test
public void bindingsGetAndSetSuccessfully() {
ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
assertNotNull(engineFactories);
for (ScriptEngineFactory engineFactory : engineFactories) {
verifyThatBindingsGetAndSetSuccessfully(engineFactory.getScriptEngine());
}
}
use of javax.script.ScriptEngineFactory in project camel by apache.
the class ActivatorTest method findScriptEngines.
@Test
public void findScriptEngines() throws IOException {
Enumeration<URL> urls = getClass().getClassLoader().getResources(Activator.META_INF_SERVICES_DIR + "/" + Activator.SCRIPT_ENGINE_SERVICE_FILE);
assertThat(urls.hasMoreElements(), is(true));
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
LOG.info("Found {}", url);
System.out.println("Found: " + url);
Activator.BundleScriptEngineResolver resolver = new Activator.BundleScriptEngineResolver(mockBundle, url);
ScriptEngineFactory factory = ReflectionTestUtils.invokeMethod(resolver, "getFactory");
System.out.println("Factory: " + factory);
assertNotNull(factory);
}
}
use of javax.script.ScriptEngineFactory in project spring-framework by spring-projects.
the class StandardScriptUtils method retrieveEngineByName.
/**
* Retrieve a {@link ScriptEngine} from the given {@link ScriptEngineManager}
* by name, delegating to {@link ScriptEngineManager#getEngineByName} but
* throwing a descriptive exception if not found or if initialization failed.
* @param scriptEngineManager the ScriptEngineManager to use
* @param engineName the name of the engine
* @return a corresponding ScriptEngine (never {@code null})
* @throws IllegalArgumentException if no matching engine has been found
* @throws IllegalStateException if the desired engine failed to initialize
*/
public static ScriptEngine retrieveEngineByName(ScriptEngineManager scriptEngineManager, String engineName) {
ScriptEngine engine = scriptEngineManager.getEngineByName(engineName);
if (engine == null) {
Set<String> engineNames = new LinkedHashSet<>();
for (ScriptEngineFactory engineFactory : scriptEngineManager.getEngineFactories()) {
List<String> factoryNames = engineFactory.getNames();
if (factoryNames.contains(engineName)) {
// If it happens to initialize fine now, alright, but we really expect an exception.
try {
engine = engineFactory.getScriptEngine();
engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.GLOBAL_SCOPE);
} catch (Throwable ex) {
throw new IllegalStateException("Script engine with name '" + engineName + "' failed to initialize", ex);
}
}
engineNames.addAll(factoryNames);
}
throw new IllegalArgumentException("Script engine with name '" + engineName + "' not found; registered engine names: " + engineNames);
}
return engine;
}
use of javax.script.ScriptEngineFactory in project zaproxy by zaproxy.
the class ExtensionScript method getEngineWrapper.
public ScriptEngineWrapper getEngineWrapper(String name) {
for (ScriptEngineWrapper sew : this.engineWrappers) {
if (isSameScriptEngine(name, sew.getEngineName(), sew.getLanguageName())) {
return sew;
}
}
// Not one we know of, create a default wrapper
List<ScriptEngineFactory> engines = mgr.getEngineFactories();
ScriptEngine engine = null;
for (ScriptEngineFactory e : engines) {
if (isSameScriptEngine(name, e.getEngineName(), e.getLanguageName())) {
engine = e.getScriptEngine();
break;
}
}
if (engine != null) {
DefaultEngineWrapper dew = new DefaultEngineWrapper(engine);
this.registerScriptEngineWrapper(dew);
return dew;
}
throw new InvalidParameterException("No such engine: " + name);
}
Aggregations