Package org.codehaus.groovy.jsr223

# Class GroovyScriptEngineFactory

java.lang.Object
org.codehaus.groovy.jsr223.GroovyScriptEngineFactory

All Implemented Interfaces:
  `ScriptEngineFactory`

public class GroovyScriptEngineFactory extends Object implements 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
  Constructor
  Description
  `GroovyScriptEngineFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getEngineName()`
  Returns the display name of this script engine implementation.
  `String`
  `getEngineVersion()`
  Note that the scripting.dev.java.net engine had this backwards.
  `List<String>`
  `getExtensions()`
  Returns the file extensions recognized by this engine.
  `String`
  `getLanguageName()`
  This is also different from scripting.dev.java.net which used an initial lowercase.
  `String`
  `getLanguageVersion()`
  Returns the version of the Groovy language available at runtime.
  `String`
  `getMethodCallSyntax(String obj, String method, String... args)`
  Formats a Groovy method call using the supplied receiver, method name, and arguments.
  `List<String>`
  `getMimeTypes()`
  Returns the MIME types associated with Groovy scripts.
  `List<String>`
  `getNames()`
  Returns the short and display names accepted when locating this engine.
  `String`
  `getOutputStatement(String toDisplay)`
  Produces a Groovy statement that prints the supplied text.
  `Object`
  `getParameter(String key)`
  Resolves a standard JSR-223 metadata key for this engine.
  `String`
  `getProgram(String... statements)`
  Joins multiple Groovy statements into a single program.
  `ScriptEngine`
  `getScriptEngine()`
  Creates a new Groovy script engine backed by this factory.

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

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

- ## Constructor Details

  - ### GroovyScriptEngineFactory

    public GroovyScriptEngineFactory()

- ## Method Details

  - ### getEngineName

    public String getEngineName()
    Returns the display name of this script engine implementation.
    Specified by:
      `getEngineName` in interface `ScriptEngineFactory`
    Returns:
      the engine name reported through the JSR-223 API

  - ### getEngineVersion

    public String 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:
      `getEngineVersion` in interface `ScriptEngineFactory`

  - ### getLanguageName

    public String 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:
      `getLanguageName` in interface `ScriptEngineFactory`

  - ### getLanguageVersion

    public String getLanguageVersion()
    Returns the version of the Groovy language available at runtime.
    Specified by:
      `getLanguageVersion` in interface `ScriptEngineFactory`
    Returns:
      the runtime Groovy version

  - ### getExtensions

    public List<String> getExtensions()
    Returns the file extensions recognized by this engine.
    Specified by:
      `getExtensions` in interface `ScriptEngineFactory`
    Returns:
      an immutable list of supported script file extensions

  - ### getMimeTypes

    public List<String> getMimeTypes()
    Returns the MIME types associated with Groovy scripts.
    Specified by:
      `getMimeTypes` in interface `ScriptEngineFactory`
    Returns:
      an immutable list of supported MIME types

  - ### getNames

    public List<String> getNames()
    Returns the short and display names accepted when locating this engine.
    Specified by:
      `getNames` in interface `ScriptEngineFactory`
    Returns:
      an immutable list of supported engine names

  - ### getParameter

    public Object getParameter(String key)
    Resolves a standard JSR-223 metadata key for this engine.
    Specified by:
      `getParameter` in interface `ScriptEngineFactory`
    Parameters:
      `key` - the metadata key to resolve
    Returns:
      the metadata value associated with `key`
    Throws:
      `IllegalArgumentException` - if `key` is not supported by this factory

  - ### getScriptEngine

    public ScriptEngine getScriptEngine()
    Creates a new Groovy script engine backed by this factory.
    Specified by:
      `getScriptEngine` in interface `ScriptEngineFactory`
    Returns:
      a fresh `GroovyScriptEngineImpl` instance

  - ### getMethodCallSyntax

    public String getMethodCallSyntax(String obj, String method, String... args)
    Formats a Groovy method call using the supplied receiver, method name, and arguments.
    Specified by:
      `getMethodCallSyntax` in interface `ScriptEngineFactory`
    Parameters:
      `obj` - the expression identifying the receiver object
      `method` - the method name to call
      `args` - the argument expressions to include in the invocation
    Returns:
      a Groovy expression that invokes `method` on `obj`

  - ### getOutputStatement

    public String getOutputStatement(String toDisplay)
    Produces a Groovy statement that prints the supplied text.
    Specified by:
      `getOutputStatement` in interface `ScriptEngineFactory`
    Parameters:
      `toDisplay` - the text to render
    Returns:
      a `println` statement with embedded quotes and backslashes escaped

  - ### getProgram

    public String getProgram(String... statements)
    Joins multiple Groovy statements into a single program.
    Specified by:
      `getProgram` in interface `ScriptEngineFactory`
    Parameters:
      `statements` - the statements to concatenate in source order
    Returns:
      a newline-delimited Groovy program