use of javax.script.ScriptEngine in project orientdb by orientechnologies.
the class OSQLFunctionGremlin method execute.
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) {
final ODatabaseDocumentTx db = OGremlinHelper.getGraphDatabase(ODatabaseRecordThreadLocal.INSTANCE.get());
result = new ArrayList<Object>();
OGremlinHelper.execute(db, (String) iParams[0], null, (Map) iContext.getVariables(), result, new OGremlinHelper.OGremlinCallback() {
@Override
public boolean call(final ScriptEngine iEngine, final OrientBaseGraph iGraph) {
if (iCurrentRecord == null)
// IGNORE PRE-PROCESSING
return true;
final ODocument document = (ODocument) iCurrentRecord;
OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) {
// EDGE TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientEdge graphElement = (OrientEdge) new OrientElementIterable<OrientEdge>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
} else {
// VERTEX TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientVertex graphElement = (OrientVertex) new OrientElementIterable<OrientVertex>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
}
return true;
}
}, null);
return result;
}
use of javax.script.ScriptEngine in project OpenAM by OpenRock.
the class GroovyEngineFactoryTest method shouldUseConfiguredSandbox.
@Test
public void shouldUseConfiguredSandbox() {
// Given
testFactory.setSandbox(mockFilter);
// When
ScriptEngine engine = testFactory.getScriptEngine();
// Then
assertThat(engine).isInstanceOf(SandboxedGroovyScriptEngine.class);
SandboxedGroovyScriptEngine sandboxedGroovyScriptEngine = (SandboxedGroovyScriptEngine) engine;
assertThat(sandboxedGroovyScriptEngine.getSandbox()).isEqualTo(mockFilter);
}
use of javax.script.ScriptEngine in project opennms by OpenNMS.
the class OSGiScriptEngineManager method getEngineByMimeType.
public ScriptEngine getEngineByMimeType(String mimeType) {
//TODO this is a hack to deal with context class loader issues
ScriptEngine engine = null;
for (ScriptEngineManager manager : classLoaders.keySet()) {
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
engine = manager.getEngineByMimeType(mimeType);
Thread.currentThread().setContextClassLoader(old);
if (engine != null)
break;
}
return engine;
}
use of javax.script.ScriptEngine in project opennms by OpenNMS.
the class OSGiScriptEngineManager method getEngineByExtension.
public ScriptEngine getEngineByExtension(String extension) {
//TODO this is a hack to deal with context class loader issues
ScriptEngine engine = null;
for (ScriptEngineManager manager : classLoaders.keySet()) {
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
engine = manager.getEngineByExtension(extension);
Thread.currentThread().setContextClassLoader(old);
if (engine != null)
break;
}
return engine;
}
use of javax.script.ScriptEngine in project Activiti by Activiti.
the class Extender method resolveScriptEngine.
// script engine part
public static ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException {
ServiceReference[] refs = context.getServiceReferences(ScriptEngineResolver.class.getName(), null);
if (refs == null) {
LOGGER.info("No OSGi script engine resolvers available!");
return null;
}
LOGGER.debug("Found {} OSGi ScriptEngineResolver services", refs.length);
for (ServiceReference ref : refs) {
ScriptEngineResolver resolver = (ScriptEngineResolver) context.getService(ref);
ScriptEngine engine = resolver.resolveScriptEngine(scriptEngineName);
context.ungetService(ref);
LOGGER.debug("OSGi resolver {} produced {} engine {}", resolver, scriptEngineName, engine);
if (engine != null) {
return engine;
}
}
return null;
}
Aggregations