public class DefaultGremlinScriptEngineManager extends Object implements GremlinScriptEngineManager
ScriptEngineManager
implements a discovery, instantiation and configuration mechanism for
GremlinScriptEngine
classes and also maintains a collection of key/value pairs storing state shared by all
engines created by it. This class uses the ServiceProvider
mechanism to enumerate all the
implementations of GremlinScriptEngineFactory
. The ScriptEngineManager
provides a method
to return a list of all these factories as well as utility methods which look up factories on the basis of language
name, file extension and mime type.
The Bindings
of key/value pairs, referred to as the "Global Scope" maintained by the manager is available
to all instances of @code ScriptEngine} created by the GremlinScriptEngineManager
. The values
in the Bindings
are generally exposed in all scripts.
This class is based quite heavily on the workings of the ScriptEngineManager
supplied in the
javax.script
packages, but adds some additional features that are specific to Gremlin and TinkerPop.
Unfortunately, it's not easily possible to extend ScriptEngineManager
directly as there certain behaviors
don't appear to be be straightforward to implement and member variables are all private. It is important to note
that this class is designed to provide support for "Gremlin-enabled" ScriptEngine
instances (i.e. those
that extend from GremlinScriptEngine
) and is not meant to manage just any ScriptEngine
instance
that may be on the path.
As this is a "Gremlin" ScriptEngine
, certain common imports are automatically applied when a
GremlinScriptEngine
is instantiated via the GremlinScriptEngineFactory
.. Initial imports from
gremlin-core come from the CoreImports
.Constructor and Description |
---|
DefaultGremlinScriptEngineManager()
The effect of calling this constructor is the same as calling
DefaultGremlinScriptEngineManager(Thread.currentThread().getContextClassLoader()) . |
DefaultGremlinScriptEngineManager(ClassLoader loader)
This constructor loads the implementations of
GremlinScriptEngineFactory visible to the given
ClassLoader using the ServiceLoader mechanism. |
Modifier and Type | Method and Description |
---|---|
void |
addPlugin(GremlinPlugin plugin)
Add
GremlinPlugin instances to customize newly created GremlinScriptEngine instances. |
Object |
get(String key)
Gets the value for the specified key in the global scope.
|
Bindings |
getBindings()
Gets the bindings of the
Bindings in global scope. |
List<Customizer> |
getCustomizers(String scriptEngineName)
Get the list of
Customizer instances filtered by the scriptEngineName . |
GremlinScriptEngine |
getEngineByExtension(String extension)
Look up and create a
GremlinScriptEngine for a given extension. |
GremlinScriptEngine |
getEngineByMimeType(String mimeType)
Look up and create a
GremlinScriptEngine for a given mime type. |
GremlinScriptEngine |
getEngineByName(String shortName)
Looks up and creates a
GremlinScriptEngine for a given name. |
List<GremlinScriptEngineFactory> |
getEngineFactories()
Returns a list whose elements are instances of all the
GremlinScriptEngineFactory classes
found by the discovery mechanism. |
void |
put(String key,
Object value)
Sets the specified key/value pair in the global scope.
|
void |
registerEngineExtension(String extension,
GremlinScriptEngineFactory factory)
Registers a
GremlinScriptEngineFactory to handle an extension. |
void |
registerEngineMimeType(String type,
GremlinScriptEngineFactory factory)
Registers a
GremlinScriptEngineFactory to handle a mime type. |
void |
registerEngineName(String name,
GremlinScriptEngineFactory factory)
Registers a
GremlinScriptEngineFactory to handle a language name. |
void |
setBindings(Bindings bindings)
Stores the specified
Bindings as a global for all GremlinScriptEngine objects created by it. |
public DefaultGremlinScriptEngineManager()
DefaultGremlinScriptEngineManager(Thread.currentThread().getContextClassLoader())
.public DefaultGremlinScriptEngineManager(ClassLoader loader)
GremlinScriptEngineFactory
visible to the given
ClassLoader
using the ServiceLoader
mechanism. If loader is null
, the script
engine factories that are bundled with the platform and that are in the usual extension directories
(installed extensions) are loaded.public List<Customizer> getCustomizers(String scriptEngineName)
GremlinScriptEngineManager
Customizer
instances filtered by the scriptEngineName
.getCustomizers
in interface GremlinScriptEngineManager
public void addPlugin(GremlinPlugin plugin)
GremlinScriptEngineManager
GremlinPlugin
instances to customize newly created GremlinScriptEngine
instances.addPlugin
in interface GremlinScriptEngineManager
public void setBindings(Bindings bindings)
Bindings
as a global for all GremlinScriptEngine
objects created by it.
If the bindings are to be updated by multiple threads it is recommended that a ConcurrentBindings
instance is supplied.setBindings
in interface GremlinScriptEngineManager
IllegalArgumentException
- if bindings is null.public Bindings getBindings()
Bindings
in global scope.getBindings
in interface GremlinScriptEngineManager
public void put(String key, Object value)
put
in interface GremlinScriptEngineManager
IllegalArgumentException
- if key is null or empty.public Object get(String key)
get
in interface GremlinScriptEngineManager
public GremlinScriptEngine getEngineByName(String shortName)
GremlinScriptEngine
for a given name. The algorithm first searches for a
GremlinScriptEngineFactory
that has been registered as a handler for the specified name using the
registerEngineExtension(String, GremlinScriptEngineFactory)
method. If one is not found, it searches
the set of GremlinScriptEngineFactory
instances stored by the constructor for one with the specified
name. If a ScriptEngineFactory
is found by either method, it is used to create instance of
GremlinScriptEngine
.getEngineByName
in interface GremlinScriptEngineManager
shortName
- The short name of the GremlinScriptEngine
implementation returned by the
ScriptEngineFactory.getNames()
method.GremlinScriptEngine
created by the factory located in the search. Returns null
if no such factory was found. The global scope of this manager is applied to the newly created
GremlinScriptEngine
NullPointerException
- if shortName is null
.public GremlinScriptEngine getEngineByExtension(String extension)
GremlinScriptEngine
for a given extension. The algorithm
used by getEngineByName(String)
is used except that the search starts by looking for a
GremlinScriptEngineFactory
registered to handle the given extension using
registerEngineExtension(String, GremlinScriptEngineFactory)
.getEngineByExtension
in interface GremlinScriptEngineManager
null
if not found.NullPointerException
- if extension is null
.public GremlinScriptEngine getEngineByMimeType(String mimeType)
GremlinScriptEngine
for a given mime type. The algorithm used by
getEngineByName(String)
is used except that the search starts by looking for a
GremlinScriptEngineFactory
registered to handle the given mime type using
registerEngineMimeType(String, GremlinScriptEngineFactory)
.getEngineByMimeType
in interface GremlinScriptEngineManager
mimeType
- The given mime typenull
if not found.NullPointerException
- if mime-type is null
.public List<GremlinScriptEngineFactory> getEngineFactories()
GremlinScriptEngineFactory
classes
found by the discovery mechanism.getEngineFactories
in interface GremlinScriptEngineManager
GremlinScriptEngineFactory
objects.public void registerEngineName(String name, GremlinScriptEngineFactory factory)
GremlinScriptEngineFactory
to handle a language name. Overrides any such association found
using the discovery mechanism.registerEngineName
in interface GremlinScriptEngineManager
name
- The name to be associated with the GremlinScriptEngineFactory
factory
- The class to associate with the given name.NullPointerException
- if any of the parameters is null.public void registerEngineMimeType(String type, GremlinScriptEngineFactory factory)
GremlinScriptEngineFactory
to handle a mime type. Overrides any such association found using
the discovery mechanism.registerEngineMimeType
in interface GremlinScriptEngineManager
type
- The mime type to be associated with the GremlinScriptEngineFactory
.factory
- The class to associate with the given mime type.NullPointerException
- if any of the parameters is null.public void registerEngineExtension(String extension, GremlinScriptEngineFactory factory)
GremlinScriptEngineFactory
to handle an extension. Overrides any such association found
using the discovery mechanism.registerEngineExtension
in interface GremlinScriptEngineManager
extension
- The extension type to be associated with the GremlinScriptEngineFactory
factory
- The class to associate with the given extension.NullPointerException
- if any of the parameters is null.Copyright © 2013–2023 Apache Software Foundation. All rights reserved.