Top Constructors Methods
org.python.jsr223

public Class PyScriptEngineFactory

extends Object
implements ScriptEngineFactory
Class Inheritance
All Implemented Interfaces
javax.script.ScriptEngineFactory
Imports
java.util.Arrays, .Collections, .List, javax.script.ScriptEngine, .ScriptEngineFactory, org.python.Version, org.python.core.Py

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getEngineName()

Implements javax.script.ScriptEngineFactory.getEngineName.

Returns the full name of the ScriptEngine.

public String
getEngineVersion()

Implements javax.script.ScriptEngineFactory.getEngineVersion.

Returns the version of the ScriptEngine.

public List<String>
getExtensions()

Implements javax.script.ScriptEngineFactory.getExtensions.

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

public String
getLanguageName()

Implements javax.script.ScriptEngineFactory.getLanguageName.

Returns the name of the scripting language supported by this ScriptEngine.

public String
getLanguageVersion()

Implements javax.script.ScriptEngineFactory.getLanguageVersion.

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

public String
getMethodCallSyntax(String
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.
obj
,
String
The name of the method to invoke.
m
,
String...
names of the arguments in the method call.
args
)

Implements javax.script.ScriptEngineFactory.getMethodCallSyntax.

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

public List<String>
getMimeTypes()

Implements javax.script.ScriptEngineFactory.getMimeTypes.

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

public List<String>
getNames()

Implements javax.script.ScriptEngineFactory.getNames.

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

public String
getOutputStatement(String
The String to be displayed by the returned statement.
toDisplay
)

Implements javax.script.ScriptEngineFactory.getOutputStatement.

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

public Object
getParameter(String
The name of the parameter
key
)

Implements javax.script.ScriptEngineFactory.getParameter.

Returns the value of an attribute whose meaning may be implementation-specific.

public String
getProgram(String...
The statements to be executed. May be return values of calls to the getMethodCallSyntax and getOutputStatement methods.
statements
)

Implements javax.script.ScriptEngineFactory.getProgram.

Returns a valid scripting language executable program with given statements.

public ScriptEngine
getScriptEngine()

Implements javax.script.ScriptEngineFactory.getScriptEngine.

Returns an instance of the ScriptEngine associated with this ScriptEngineFactory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PyScriptEngineFactoryback to summary
public PyScriptEngineFactory()

Method Detail

getEngineNameback to summary
public String getEngineName()

Implements javax.script.ScriptEngineFactory.getEngineName.

Doc from javax.script.ScriptEngineFactory.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:String

The name of the engine implementation.

getEngineVersionback to summary
public String getEngineVersion()

Implements javax.script.ScriptEngineFactory.getEngineVersion.

Doc from javax.script.ScriptEngineFactory.getEngineVersion.

Returns the version of the ScriptEngine.

Returns:String

The ScriptEngine implementation version.

getExtensionsback to summary
public List<String> getExtensions()

Implements javax.script.ScriptEngineFactory.getExtensions.

Doc from javax.script.ScriptEngineFactory.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:List<String>

The list of extensions.

getLanguageNameback to summary
public String getLanguageName()

Implements javax.script.ScriptEngineFactory.getLanguageName.

Doc from javax.script.ScriptEngineFactory.getLanguageName.

Returns the name of the scripting language supported by this ScriptEngine.

Returns:String

The name of the supported language.

getLanguageVersionback to summary
public String getLanguageVersion()

Implements javax.script.ScriptEngineFactory.getLanguageVersion.

Doc from javax.script.ScriptEngineFactory.getLanguageVersion.

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

Returns:String

The version of the supported language.

getMethodCallSyntaxback to summary
public String getMethodCallSyntax(String obj, String m, String... args)

Implements javax.script.ScriptEngineFactory.getMethodCallSyntax.

Doc from javax.script.ScriptEngineFactory.getMethodCallSyntax.

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 implementation 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 += ",";
         }
     }
     ret += ")";
     return ret;
}
 
Parameters
obj:String

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:String

The name of the method to invoke.

args:String[]

names of the arguments in the method call.

Returns:String

The String used to invoke the method in the syntax of the scripting language.

getMimeTypesback to summary
public List<String> getMimeTypes()

Implements javax.script.ScriptEngineFactory.getMimeTypes.

Doc from javax.script.ScriptEngineFactory.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:List<String>

The list of mime types.

getNamesback to summary
public List<String> getNames()

Implements javax.script.ScriptEngineFactory.getNames.

Doc from javax.script.ScriptEngineFactory.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"}.

Returns:List<String>

an immutable list of short names

getOutputStatementback to summary
public String getOutputStatement(String toDisplay)

Implements javax.script.ScriptEngineFactory.getOutputStatement.

Doc from javax.script.ScriptEngineFactory.getOutputStatement.

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 implementation for a Perl engine might be;


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

The String to be displayed by the returned statement.

Returns:String

The string used to display the String in the syntax of the scripting language.

getParameterback to summary
public Object getParameter(String key)

Implements javax.script.ScriptEngineFactory.getParameter.

Doc from javax.script.ScriptEngineFactory.getParameter.

Returns the value of an attribute whose meaning may be implementation-specific. Keys for which the value is defined in all implementations are:

  • ScriptEngine.ENGINE
  • ScriptEngine.ENGINE_VERSION
  • ScriptEngine.LANGUAGE
  • ScriptEngine.LANGUAGE_VERSION
  • ScriptEngine.NAME

The values for these keys are the Strings returned by getEngineName, getEngineVersion, getLanguageName, getLanguageVersion for the first four keys respectively. For NAME, one of the Strings returned by getNames is returned.

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:

  • null - The engine implementation is not thread safe, and cannot be used to execute scripts concurrently on multiple threads.
  • "MULTITHREADED" - The engine implementation is internally thread-safe and scripts may execute concurrently although effects of script execution on one thread may be visible to scripts on other threads.
  • "THREAD-ISOLATED" - The implementation satisfies the requirements of "MULTITHREADED", and also, the engine maintains independent values for symbols in scripts executing on different threads.
  • "STATELESS" - The implementation satisfies the requirements of "THREAD-ISOLATED". In addition, script executions do not alter the mappings in the Bindings which is the engine scope of the ScriptEngine. In particular, the keys in the Bindings and their associated values are the same before and after the execution of the script.


Implementations may define implementation-specific keys.
Parameters
key:String

The name of the parameter

Returns:Object

The value for the given parameter. Returns null if no value is assigned to the key.

getProgramback to summary
public String getProgram(String... statements)

Implements javax.script.ScriptEngineFactory.getProgram.

Doc from javax.script.ScriptEngineFactory.getProgram.

Returns a valid scripting language executable program with given statements. For instance an implementation for a PHP engine might be:

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

The statements to be executed. May be return values of calls to the getMethodCallSyntax and getOutputStatement methods.

Returns:String

The Program

getScriptEngineback to summary
public ScriptEngine getScriptEngine()

Implements javax.script.ScriptEngineFactory.getScriptEngine.

Doc from javax.script.ScriptEngineFactory.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:ScriptEngine

A new ScriptEngine instance.