Package org.codehaus.groovy.jsr223
Class GroovyScriptEngineFactory
java.lang.Object
org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
- All Implemented Interfaces:
ScriptEngineFactory
A factory class conforming to JSR-223 which is used to instantiate
Groovy
ScriptEngines and also exposes metadata describing
Groovy's engine class.
Adapted from original by Mike Grogan and A. Sundararajan-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the display name of this script engine implementation.Note that the scripting.dev.java.net engine had this backwards.Returns the file extensions recognized by this engine.This is also different from scripting.dev.java.net which used an initial lowercase.Returns the version of the Groovy language available at runtime.getMethodCallSyntax(String obj, String method, String... args) Formats a Groovy method call using the supplied receiver, method name, and arguments.Returns the MIME types associated with Groovy scripts.getNames()Returns the short and display names accepted when locating this engine.getOutputStatement(String toDisplay) Produces a Groovy statement that prints the supplied text.getParameter(String key) Resolves a standard JSR-223 metadata key for this engine.getProgram(String... statements) Joins multiple Groovy statements into a single program.Creates a new Groovy script engine backed by this factory.
-
Constructor Details
-
GroovyScriptEngineFactory
public GroovyScriptEngineFactory()
-
-
Method Details
-
getEngineName
Returns the display name of this script engine implementation.- Specified by:
getEngineNamein interfaceScriptEngineFactory- Returns:
- the engine name reported through the JSR-223 API
-
getEngineVersion
Note that the scripting.dev.java.net engine had this backwards. The engine version refers to this engine implementation. Whereas language version refers to the groovy implementation (which is obtained from the runtime).- Specified by:
getEngineVersionin interfaceScriptEngineFactory
-
getLanguageName
This is also different from scripting.dev.java.net which used an initial lowercase. But these are proper names and should be capitalized.- Specified by:
getLanguageNamein interfaceScriptEngineFactory
-
getLanguageVersion
Returns the version of the Groovy language available at runtime.- Specified by:
getLanguageVersionin interfaceScriptEngineFactory- Returns:
- the runtime Groovy version
-
getExtensions
Returns the file extensions recognized by this engine.- Specified by:
getExtensionsin interfaceScriptEngineFactory- Returns:
- an immutable list of supported script file extensions
-
getMimeTypes
Returns the MIME types associated with Groovy scripts.- Specified by:
getMimeTypesin interfaceScriptEngineFactory- Returns:
- an immutable list of supported MIME types
-
getNames
Returns the short and display names accepted when locating this engine.- Specified by:
getNamesin interfaceScriptEngineFactory- Returns:
- an immutable list of supported engine names
-
getParameter
Resolves a standard JSR-223 metadata key for this engine.- Specified by:
getParameterin interfaceScriptEngineFactory- Parameters:
key- the metadata key to resolve- Returns:
- the metadata value associated with
key - Throws:
IllegalArgumentException- ifkeyis not supported by this factory
-
getScriptEngine
Creates a new Groovy script engine backed by this factory.- Specified by:
getScriptEnginein interfaceScriptEngineFactory- Returns:
- a fresh
GroovyScriptEngineImplinstance
-
getMethodCallSyntax
Formats a Groovy method call using the supplied receiver, method name, and arguments.- Specified by:
getMethodCallSyntaxin interfaceScriptEngineFactory- Parameters:
obj- the expression identifying the receiver objectmethod- the method name to callargs- the argument expressions to include in the invocation- Returns:
- a Groovy expression that invokes
methodonobj
-
getOutputStatement
Produces a Groovy statement that prints the supplied text.- Specified by:
getOutputStatementin interfaceScriptEngineFactory- Parameters:
toDisplay- the text to render- Returns:
- a
printlnstatement with embedded quotes and backslashes escaped
-
getProgram
Joins multiple Groovy statements into a single program.- Specified by:
getProgramin interfaceScriptEngineFactory- Parameters:
statements- the statements to concatenate in source order- Returns:
- a newline-delimited Groovy program
-