This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.script
interface ScriptEngineFactory


Most common way to construct:

ScriptEngine engine = …;

ScriptEngineFactory factory = engine.getFactory();

Based on 27 examples


public interface ScriptEngineFactory

ScriptEngineFactory is used to describe and instantiate ScriptEngines.

Each class implementing ScriptEngine has a corresponding factory that exposes metadata describing the engine class.

The ScriptEngineManager uses the service provider mechanism described in the Jar File Specification to obtain instances of all ScriptEngineFactories available in the current ClassLoader.


Method Summary
 String

          Returns the full name of the ScriptEngine.
 String

          Returns the version of the ScriptEngine.
 List

          Returns an immutable list of filename extensions, which generally identify scripts written in the language supported by this ScriptEngine.
 String

          Returns the name of the scripting langauge supported by this ScriptEngine.
 String

          Returns the version of the scripting language supported by this ScriptEngine.
 String

          Returns a String which can be used to invoke a method of a Java object using the syntax of the supported scripting language.
 List

          Returns an immutable list of mimetypes, associated with scripts that can be executed by the engine.
 List

          Returns an immutable list of short names for the ScriptEngine, which may be used to identify the ScriptEngine by the ScriptEngineManager.
 String

          Returns a String that can be used as a statement to display the specified String using the syntax of the supported scripting language.
 Object

          Returns the value of an attribute whose meaning may be implementation-specific.
 String
getProgram(String[] statements)

          Returns A valid scripting language executable progam with given statements.
 ScriptEngine

          Returns an instance of the ScriptEngine associated with this ScriptEngineFactory.
 

Method Detail

getEngineName

public String getEngineName()
Returns the full name of the ScriptEngine. For instance an implementation based on the Mozilla Rhino Javascript engine might return Rhino Mozilla Javascript Engine.

Returns:
The name of the engine implementation.

getEngineVersion

public String getEngineVersion()
Returns the version of the ScriptEngine.

Returns:
The ScriptEngine implementation version.

getExtensions

public List getExtensions()
Returns an immutable list of filename extensions, which generally identify scripts written in the language supported by this ScriptEngine. The array is used by the ScriptEngineManager to implement its getEngineByExtension method.

Returns:
The list of extensions.

getLanguageName

public String getLanguageName()
Returns the name of the scripting langauge supported by this ScriptEngine.

Returns:
The name of the supported language.

getLanguageVersion

public String getLanguageVersion()
Returns the version of the scripting language supported by this ScriptEngine.

Returns:
The version of the supported language.

getMethodCallSyntax

public String getMethodCallSyntax(String obj,
                                  String m,
                                  String[] args)
Returns a String which can be used to invoke a method of a Java object using the syntax of the supported scripting language. For instance, an implementaton for a Javascript engine might be;

 public String getMethodCallSyntax(String obj,
                                   String m, String... args) {
      String ret = obj;
      ret += "." + m + "(";
      for (int i = 0; i < args.length; i++) {
          ret += args[i];
          if (i == args.length - 1) {
              ret += ")";
          } else {
              ret += ",";
          }
      }
      return ret;
 }

Parameters:
obj - The name representing the object whose method is to be invoked. The name is the one used to create bindings using the put method of ScriptEngine, the put method of an ENGINE_SCOPE Bindings,or the setAttribute method of ScriptContext. The identifier used in scripts may be a decorated form of the specified one.
m - The name of the method to invoke.
args - names of the arguments in the method call.
Returns:
The String used to invoke the method in the syntax of the scripting language.

getMimeTypes

public List getMimeTypes()
Returns an immutable list of mimetypes, associated with scripts that can be executed by the engine. The list is used by the ScriptEngineManager class to implement its getEngineByMimetype method.

Returns:
The list of mime types.

getNames

public List getNames()
Returns an immutable list of short names for the ScriptEngine, which may be used to identify the ScriptEngine by the ScriptEngineManager. For instance, an implementation based on the Mozilla Rhino Javascript engine might return list containing {"javascript", "rhino"}.


getOutputStatement

public String getOutputStatement(String toDisplay)
Returns a String that can be used as a statement to display the specified String using the syntax of the supported scripting language. For instance, the implementaton for a Perl engine might be;


 public String getOutputStatement(String toDisplay) {
      return "print(" + toDisplay + ")";
 }
 

Parameters:
toDisplay - The String to be displayed by the returned statement.
Returns:
The string used to display the String in the syntax of the scripting language.

getParameter

public Object getParameter(String key)
Returns the value of an attribute whose meaning may be implementation-specific. Keys for which the value is defined in all implementations are:

The values for these keys are the Strings returned by getEngineName, getEngineVersion, getName, getLanguageName and getLanguageVersion respectively.

A reserved key, THREADING, whose value describes the behavior of the engine with respect to concurrent execution of scripts and maintenance of state is also defined. These values for the THREADING key are:



Implementations may define implementation-specific keys.

Parameters:
key - The name of the parameter
Returns:
The value for the given parameter. Returns null if no value is assigned to the key.

getProgram

public String getProgram(String[] statements)
Returns A valid scripting language executable progam with given statements. For instance an implementation for a PHP engine might be:


 public String getProgram(String... statements) {
      $retval = "<?\n";
      int len = statements.length;
      for (int i = 0; i < len; i++) {
          $retval += statements[i] + ";\n";
      }
      $retval += "?>";

 }
 

Parameters:
statements - The statements to be executed. May be return values of calls to the getMethodCallSyntax and getOutputStatement methods.
Returns:
The Program

getScriptEngine

public ScriptEngine getScriptEngine()
Returns an instance of the ScriptEngine associated with this ScriptEngineFactory. A new ScriptEngine is generally returned, but implementations may pool, share or reuse engines.

Returns:
A new ScriptEngine instance.


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.