Search in sources :

Example 31 with ScriptEngine

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ScriptEngine(javax.script.ScriptEngine) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OGremlinHelper(com.orientechnologies.orient.graph.gremlin.OGremlinHelper) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OrientElementIterable(com.tinkerpop.blueprints.impls.orient.OrientElementIterable)

Example 32 with ScriptEngine

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);
}
Also used : ScriptEngine(javax.script.ScriptEngine) Test(org.testng.annotations.Test)

Example 33 with ScriptEngine

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;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 34 with ScriptEngine

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;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 35 with ScriptEngine

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;
}
Also used : ScriptEngine(javax.script.ScriptEngine) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ScriptEngine (javax.script.ScriptEngine)175 ScriptEngineManager (javax.script.ScriptEngineManager)70 ScriptException (javax.script.ScriptException)46 Test (org.junit.Test)29 Bindings (javax.script.Bindings)20 IOException (java.io.IOException)19 Map (java.util.Map)14 Invocable (javax.script.Invocable)13 File (java.io.File)11 FileReader (java.io.FileReader)11 ScriptEngineFactory (javax.script.ScriptEngineFactory)11 HashMap (java.util.HashMap)10 ScriptContext (javax.script.ScriptContext)10 SimpleBindings (javax.script.SimpleBindings)10 InputStreamReader (java.io.InputStreamReader)9 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)9 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)9 PrintWriter (java.io.PrintWriter)7 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)7 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)7