public final class NashornScriptEngineFactory extends Object implements ScriptEngineFactory
"nashorn"
, "Nashorn"
, "js"
, "JS"
, "JavaScript"
,
"javascript"
, "ECMAScript"
, and "ecmascript"
;"application/javascript"
, "application/ecmascript"
, "text/javascript"
, and
"text/ecmascript"
;"js"
.getScriptEngine(String[])
will have the passed arguments
accessible as a global variable named "arguments"
.Constructor and Description |
---|
NashornScriptEngineFactory() |
Modifier and Type | Method and Description |
---|---|
String |
getEngineName()
Returns the full name of the
ScriptEngine . |
String |
getEngineVersion()
Returns the version of the
ScriptEngine . |
List<String> |
getExtensions()
Returns an immutable list of filename extensions, which generally identify scripts
written in the language supported by this
ScriptEngine . |
String |
getLanguageName()
Returns the name of the scripting langauge supported by this
ScriptEngine . |
String |
getLanguageVersion()
Returns the version of the scripting language supported by this
ScriptEngine . |
String |
getMethodCallSyntax(String obj,
String method,
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.
|
List<String> |
getMimeTypes()
Returns an immutable list of mimetypes, associated with scripts that
can be executed by the engine.
|
List<String> |
getNames()
Returns an immutable list of short names for the
ScriptEngine , which may be used to
identify the ScriptEngine by the ScriptEngineManager . |
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.
|
Object |
getParameter(String key)
Returns the value of an attribute whose meaning may be implementation-specific.
|
String |
getProgram(String... statements)
Returns a valid scripting language executable program with given statements.
|
ScriptEngine |
getScriptEngine()
Returns an instance of the
ScriptEngine associated with this
ScriptEngineFactory . |
ScriptEngine |
getScriptEngine(ClassFilter classFilter)
Create a new Script engine initialized by given class filter.
|
ScriptEngine |
getScriptEngine(ClassLoader appLoader)
Create a new Script engine initialized by given class loader.
|
ScriptEngine |
getScriptEngine(String... args)
Create a new Script engine initialized by given arguments.
|
ScriptEngine |
getScriptEngine(String[] args,
ClassLoader appLoader)
Create a new Script engine initialized by given arguments.
|
ScriptEngine |
getScriptEngine(String[] args,
ClassLoader appLoader,
ClassFilter classFilter)
Create a new Script engine initialized by given arguments.
|
public String getEngineName()
javax.script.ScriptEngineFactory
ScriptEngine
. For
instance an implementation based on the Mozilla Rhino Javascript engine
might return Rhino Mozilla Javascript Engine.getEngineName
in interface ScriptEngineFactory
public String getEngineVersion()
javax.script.ScriptEngineFactory
ScriptEngine
.getEngineVersion
in interface ScriptEngineFactory
ScriptEngine
implementation version.public List<String> getExtensions()
javax.script.ScriptEngineFactory
ScriptEngine
.
The array is used by the ScriptEngineManager
to implement its
getEngineByExtension
method.getExtensions
in interface ScriptEngineFactory
public String getLanguageName()
javax.script.ScriptEngineFactory
ScriptEngine
.getLanguageName
in interface ScriptEngineFactory
public String getLanguageVersion()
javax.script.ScriptEngineFactory
ScriptEngine
.getLanguageVersion
in interface ScriptEngineFactory
public String getMethodCallSyntax(String obj, String method, String... args)
javax.script.ScriptEngineFactory
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;
}
getMethodCallSyntax
in interface ScriptEngineFactory
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.method
- The name of the method to invoke.args
- names of the arguments in the method call.public List<String> getMimeTypes()
javax.script.ScriptEngineFactory
ScriptEngineManager
class to implement its
getEngineByMimetype
method.getMimeTypes
in interface ScriptEngineFactory
public List<String> getNames()
javax.script.ScriptEngineFactory
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"}.getNames
in interface ScriptEngineFactory
public String getOutputStatement(String toDisplay)
javax.script.ScriptEngineFactory
public String getOutputStatement(String toDisplay) {
return "print(" + toDisplay + ")";
}
getOutputStatement
in interface ScriptEngineFactory
toDisplay
- The String to be displayed by the returned statement.public Object getParameter(String key)
javax.script.ScriptEngineFactory
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:
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.
getParameter
in interface ScriptEngineFactory
key
- The name of the parameternull
if no
value is assigned to the key.public String getProgram(String... statements)
javax.script.ScriptEngineFactory
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 += "?>";
}
getProgram
in interface ScriptEngineFactory
statements
- The statements to be executed. May be return values of
calls to the getMethodCallSyntax
and getOutputStatement
methods.public ScriptEngine getScriptEngine()
javax.script.ScriptEngineFactory
ScriptEngine
associated with this
ScriptEngineFactory
. A new ScriptEngine is generally
returned, but implementations may pool, share or reuse engines.getScriptEngine
in interface ScriptEngineFactory
ScriptEngine
instance.public ScriptEngine getScriptEngine(ClassLoader appLoader)
appLoader
- class loader to be used as script "app" class loader.SecurityException
- if the security manager's checkPermission
denies RuntimePermission("nashorn.setConfig")
public ScriptEngine getScriptEngine(ClassFilter classFilter)
classFilter
- class filter to use.NullPointerException
- if classFilter
is null
SecurityException
- if the security manager's checkPermission
denies RuntimePermission("nashorn.setConfig")
public ScriptEngine getScriptEngine(String... args)
args
- arguments array passed to script engine.NullPointerException
- if args
is null
SecurityException
- if the security manager's checkPermission
denies RuntimePermission("nashorn.setConfig")
public ScriptEngine getScriptEngine(String[] args, ClassLoader appLoader)
args
- arguments array passed to script engine.appLoader
- class loader to be used as script "app" class loader.NullPointerException
- if args
is null
SecurityException
- if the security manager's checkPermission
denies RuntimePermission("nashorn.setConfig")
public ScriptEngine getScriptEngine(String[] args, ClassLoader appLoader, ClassFilter classFilter)
args
- arguments array passed to script engine.appLoader
- class loader to be used as script "app" class loader.classFilter
- class filter to use.NullPointerException
- if args
or classFilter
is null
SecurityException
- if the security manager's checkPermission
denies RuntimePermission("nashorn.setConfig")
Copyright © 2014, 2015, Oracle and/or its affiliates. All rights reserved.