org.apache.tinkerpop.gremlin.jsr223

## Class GremlinLangScriptEngine

- java.lang.Object
- - javax.script.AbstractScriptEngine
  - - org.apache.tinkerpop.gremlin.jsr223.GremlinLangScriptEngine

- All Implemented Interfaces:
    ScriptEngine, GremlinScriptEngine

      public class GremlinLangScriptEngine
      extends AbstractScriptEngine
      implements GremlinScriptEngine

  A `GremlinScriptEngine` implementation that evaluates Gremlin scripts using `gremlin-language`. As it uses `gremlin-language` and thus the ANTLR parser, it is not capable of process arbitrary scripts as the `GremlinGroovyScriptEngine` can and is therefore a more secure Gremlin evaluator. It is obviously restricted to the capabilities of the ANTLR grammar so therefore syntax that includes things like lambdas are not supported. For bytecode evaluation it simply uses the `JavaTranslator`.

  As an internal note, technically, this is an incomplete implementation of the `GremlinScriptEngine` in the traditional sense as a drop-in replacement for something like the `GremlinGroovyScriptEngine`. As a result, this `GremlinScriptEngine` cannot pass the `GremlinScriptEngineSuite` tests in full. On the other hand, this limitation is precisely what makes this implementation better from a security perspective. Ultimately, this implementation represents the first step to changes in what it means to have a `GremlinScriptEngine`. In some sense, there is question why a `GremlinScriptEngine` approach is necessary at all except for easily plugging into the existing internals of Gremlin Server or more specifically the `GremlinExecutor`.

- - ### Field Summary

    - ### Fields inherited from class javax.script.AbstractScriptEngine

      `context`

    - ### Fields inherited from interface org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine

      `HIDDEN_G`

    - ### Fields inherited from interface javax.script.ScriptEngine

      `ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GremlinLangScriptEngine()` Creates a new instance using no `Customizer`.
    `GremlinLangScriptEngine(Customizer... customizers)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Bindings` | `createBindings()`
    `Traversal.Admin` | `eval(Bytecode bytecode, Bindings bindings, String traversalSource)` Bytecode is evaluated by the `JavaTranslator`.
    `Object` | `eval(Reader reader, ScriptContext context)`
    `Object` | `eval(String script, ScriptContext context)` Gremlin scripts evaluated by the grammar must be bound to "g" and should evaluate to a "g" in the `ScriptContext` that is of type `TraversalSource`
    `GremlinScriptEngineFactory` | `getFactory()`
    `protected ScriptContext` | `getScriptContext(Bindings nn)` Creates the `ScriptContext` using a `GremlinScriptContext` which avoids a significant amount of additional object creation on script evaluation.

    - ### Methods inherited from class javax.script.AbstractScriptEngine

      `eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine

      `eval`

    - ### Methods inherited from interface javax.script.ScriptEngine

      `eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext`

- - ### Constructor Detail

    - #### GremlinLangScriptEngine

          public GremlinLangScriptEngine()

      Creates a new instance using no `Customizer`.

    - #### GremlinLangScriptEngine

          public GremlinLangScriptEngine(Customizer... customizers)

  - ### Method Detail

    - #### getFactory

          public GremlinScriptEngineFactory getFactory()

      Specified by:
        `getFactory` in interface `ScriptEngine`
      Specified by:
        `getFactory` in interface `GremlinScriptEngine`

    - #### eval

          public Traversal.Admin eval(Bytecode bytecode,
                                      Bindings bindings,
                                      String traversalSource)
                               throws ScriptException

      Bytecode is evaluated by the `JavaTranslator`.
      Specified by:
        `eval` in interface `GremlinScriptEngine`
      Throws:
        `ScriptException`

    - #### eval

          public Object eval(String script,
                             ScriptContext context)
                      throws ScriptException

      Gremlin scripts evaluated by the grammar must be bound to "g" and should evaluate to a "g" in the `ScriptContext` that is of type `TraversalSource`
      Specified by:
        `eval` in interface `ScriptEngine`
      Throws:
        `ScriptException`

    - #### eval

          public Object eval(Reader reader,
                             ScriptContext context)
                      throws ScriptException

      Specified by:
        `eval` in interface `ScriptEngine`
      Throws:
        `ScriptException`

    - #### createBindings

          public Bindings createBindings()

      Specified by:
        `createBindings` in interface `ScriptEngine`

    - #### getScriptContext

          protected ScriptContext getScriptContext(Bindings nn)

      Creates the `ScriptContext` using a `GremlinScriptContext` which avoids a significant amount of additional object creation on script evaluation.
      Overrides:
        `getScriptContext` in class `AbstractScriptEngine`

Copyright © 2013–2022 Apache Software Foundation. All rights reserved.