Class DefaultGremlinScriptEngineManager
- java.lang.Object
- 
- org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager
 
- 
- All Implemented Interfaces:
- GremlinScriptEngineManager
 - Direct Known Subclasses:
- CachedGremlinScriptEngineManager
 
 public class DefaultGremlinScriptEngineManager extends Object implements GremlinScriptEngineManager TheScriptEngineManagerimplements a discovery, instantiation and configuration mechanism forGremlinScriptEngineclasses and also maintains a collection of key/value pairs storing state shared by all engines created by it. This class uses theServiceProvidermechanism to enumerate all the implementations ofGremlinScriptEngineFactory. TheScriptEngineManagerprovides 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. TheBindingsof key/value pairs, referred to as the "Global Scope" maintained by the manager is available to all instances of @code ScriptEngine} created by theGremlinScriptEngineManager. The values in theBindingsare generally exposed in all scripts. This class is based quite heavily on the workings of theScriptEngineManagersupplied in thejavax.scriptpackages, but adds some additional features that are specific to Gremlin and TinkerPop. Unfortunately, it's not easily possible to extendScriptEngineManagerdirectly as there certain behaviors don't appear to 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"ScriptEngineinstances (i.e. those that extend fromGremlinScriptEngine) and is not meant to manage just anyScriptEngineinstance that may be on the path. As this is a "Gremlin"ScriptEngine, certain common imports are automatically applied when aGremlinScriptEngineis instantiated via theGremlinScriptEngineFactory.. Initial imports from gremlin-core come from theCoreImports.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
 
- 
- 
Constructor SummaryConstructors Constructor Description DefaultGremlinScriptEngineManager()The effect of calling this constructor is the same as callingDefaultGremlinScriptEngineManager(Thread.currentThread().getContextClassLoader()).DefaultGremlinScriptEngineManager(ClassLoader loader)This constructor loads the implementations ofGremlinScriptEngineFactoryvisible to the givenClassLoaderusing theServiceLoadermechanism.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPlugin(GremlinPlugin plugin)AddGremlinPlugininstances to customize newly createdGremlinScriptEngineinstances.Objectget(String key)Gets the value for the specified key in the global scope.BindingsgetBindings()Gets the bindings of theBindingsin global scope.List<Customizer>getCustomizers(String scriptEngineName)Get the list ofCustomizerinstances filtered by thescriptEngineName.GremlinScriptEnginegetEngineByExtension(String extension)Look up and create aGremlinScriptEnginefor a given extension.GremlinScriptEnginegetEngineByMimeType(String mimeType)Look up and create aGremlinScriptEnginefor a given mime type.GremlinScriptEnginegetEngineByName(String shortName)Looks up and creates aGremlinScriptEnginefor a given name.List<GremlinScriptEngineFactory>getEngineFactories()Returns a list whose elements are instances of all theGremlinScriptEngineFactoryclasses found by the discovery mechanism.voidput(String key, Object value)Sets the specified key/value pair in the global scope.voidregisterEngineExtension(String extension, GremlinScriptEngineFactory factory)Registers aGremlinScriptEngineFactoryto handle an extension.voidregisterEngineMimeType(String type, GremlinScriptEngineFactory factory)Registers aGremlinScriptEngineFactoryto handle a mime type.voidregisterEngineName(String name, GremlinScriptEngineFactory factory)Registers aGremlinScriptEngineFactoryto handle a language name.voidsetBindings(Bindings bindings)Stores the specifiedBindingsas a global for allGremlinScriptEngineobjects created by it.
 
- 
- 
- 
Constructor Detail- 
DefaultGremlinScriptEngineManagerpublic DefaultGremlinScriptEngineManager() The effect of calling this constructor is the same as callingDefaultGremlinScriptEngineManager(Thread.currentThread().getContextClassLoader()).
 - 
DefaultGremlinScriptEngineManagerpublic DefaultGremlinScriptEngineManager(ClassLoader loader) This constructor loads the implementations ofGremlinScriptEngineFactoryvisible to the givenClassLoaderusing theServiceLoadermechanism. If loader isnull, the script engine factories that are bundled with the platform and that are in the usual extension directories (installed extensions) are loaded.
 
- 
 - 
Method Detail- 
getCustomizerspublic List<Customizer> getCustomizers(String scriptEngineName) Description copied from interface:GremlinScriptEngineManagerGet the list ofCustomizerinstances filtered by thescriptEngineName.- Specified by:
- getCustomizersin interface- GremlinScriptEngineManager
 
 - 
addPluginpublic void addPlugin(GremlinPlugin plugin) Description copied from interface:GremlinScriptEngineManagerAddGremlinPlugininstances to customize newly createdGremlinScriptEngineinstances.- Specified by:
- addPluginin interface- GremlinScriptEngineManager
 
 - 
setBindingspublic void setBindings(Bindings bindings) Stores the specifiedBindingsas a global for allGremlinScriptEngineobjects created by it. If the bindings are to be updated by multiple threads it is recommended that aConcurrentBindingsinstance is supplied.- Specified by:
- setBindingsin interface- GremlinScriptEngineManager
- Throws:
- IllegalArgumentException- if bindings is null.
 
 - 
getBindingspublic Bindings getBindings() Gets the bindings of theBindingsin global scope.- Specified by:
- getBindingsin interface- GremlinScriptEngineManager
 
 - 
putpublic void put(String key, Object value) Sets the specified key/value pair in the global scope. The key may not be null or empty.- Specified by:
- putin interface- GremlinScriptEngineManager
- Throws:
- IllegalArgumentException- if key is null or empty.
 
 - 
getpublic Object get(String key) Gets the value for the specified key in the global scope.- Specified by:
- getin interface- GremlinScriptEngineManager
 
 - 
getEngineByNamepublic GremlinScriptEngine getEngineByName(String shortName) Looks up and creates aGremlinScriptEnginefor a given name. The algorithm first searches for aGremlinScriptEngineFactorythat has been registered as a handler for the specified name using theregisterEngineExtension(String, GremlinScriptEngineFactory)method. If one is not found, it searches the set ofGremlinScriptEngineFactoryinstances stored by the constructor for one with the specified name. If aScriptEngineFactoryis found by either method, it is used to create instance ofGremlinScriptEngine.- Specified by:
- getEngineByNamein interface- GremlinScriptEngineManager
- Parameters:
- shortName- The short name of the- GremlinScriptEngineimplementation returned by the- ScriptEngineFactory.getNames()method.
- Returns:
- A GremlinScriptEnginecreated by the factory located in the search. Returnsnullif no such factory was found. The global scope of this manager is applied to the newly createdGremlinScriptEngine
- Throws:
- NullPointerException- if shortName is- null.
 
 - 
getEngineByExtensionpublic GremlinScriptEngine getEngineByExtension(String extension) Look up and create aGremlinScriptEnginefor a given extension. The algorithm used bygetEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given extension usingregisterEngineExtension(String, GremlinScriptEngineFactory).- Specified by:
- getEngineByExtensionin interface- GremlinScriptEngineManager
- Returns:
- The engine to handle scripts with this extension.  Returns nullif not found.
- Throws:
- NullPointerException- if extension is- null.
 
 - 
getEngineByMimeTypepublic GremlinScriptEngine getEngineByMimeType(String mimeType) Look up and create aGremlinScriptEnginefor a given mime type. The algorithm used bygetEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given mime type usingregisterEngineMimeType(String, GremlinScriptEngineFactory).- Specified by:
- getEngineByMimeTypein interface- GremlinScriptEngineManager
- Parameters:
- mimeType- The given mime type
- Returns:
- The engine to handle scripts with this mime type.  Returns nullif not found.
- Throws:
- NullPointerException- if mime-type is- null.
 
 - 
getEngineFactoriespublic List<GremlinScriptEngineFactory> getEngineFactories() Returns a list whose elements are instances of all theGremlinScriptEngineFactoryclasses found by the discovery mechanism.- Specified by:
- getEngineFactoriesin interface- GremlinScriptEngineManager
- Returns:
- List of all discovered GremlinScriptEngineFactoryobjects.
 
 - 
registerEngineNamepublic void registerEngineName(String name, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle a language name. Overrides any such association found using the discovery mechanism.- Specified by:
- registerEngineNamein interface- GremlinScriptEngineManager
- Parameters:
- name- The name to be associated with the- GremlinScriptEngineFactory
- factory- The class to associate with the given name.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 - 
registerEngineMimeTypepublic void registerEngineMimeType(String type, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle a mime type. Overrides any such association found using the discovery mechanism.- Specified by:
- registerEngineMimeTypein interface- GremlinScriptEngineManager
- Parameters:
- type- The mime type to be associated with the- GremlinScriptEngineFactory.
- factory- The class to associate with the given mime type.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 - 
registerEngineExtensionpublic void registerEngineExtension(String extension, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle an extension. Overrides any such association found using the discovery mechanism.- Specified by:
- registerEngineExtensionin interface- GremlinScriptEngineManager
- Parameters:
- extension- The extension type to be associated with the- GremlinScriptEngineFactory
- factory- The class to associate with the given extension.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 
- 
 
-