public class GremlinLangScriptEngine extends AbstractScriptEngine implements GremlinScriptEngine
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
.context
HIDDEN_G
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
Constructor and Description |
---|
GremlinLangScriptEngine()
Creates a new instance using no
Customizer . |
GremlinLangScriptEngine(Customizer... customizers) |
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. |
eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eval
eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
public GremlinLangScriptEngine()
Customizer
.public GremlinLangScriptEngine(Customizer... customizers)
public GremlinScriptEngineFactory getFactory()
getFactory
in interface ScriptEngine
getFactory
in interface GremlinScriptEngine
public Traversal.Admin eval(Bytecode bytecode, Bindings bindings, String traversalSource) throws ScriptException
JavaTranslator
.eval
in interface GremlinScriptEngine
ScriptException
public Object eval(String script, ScriptContext context) throws ScriptException
ScriptContext
that is of type TraversalSource
eval
in interface ScriptEngine
ScriptException
public Object eval(Reader reader, ScriptContext context) throws ScriptException
eval
in interface ScriptEngine
ScriptException
public Bindings createBindings()
createBindings
in interface ScriptEngine
protected ScriptContext getScriptContext(Bindings nn)
ScriptContext
using a GremlinScriptContext
which avoids a significant amount of
additional object creation on script evaluation.getScriptContext
in class AbstractScriptEngine
Copyright © 2013–2023 Apache Software Foundation. All rights reserved.