-
public interface ScriptEngineFactory
ScriptEngineFactory
is used to describe and instantiateScriptEngines
.
Each class implementingScriptEngine
has a corresponding factory that exposes metadata describing the engine class.
TheScriptEngineManager
uses the service provider mechanism described in the Jar File Specification to obtain instances of allScriptEngineFactories
available in the current ClassLoader.- Since:
- 1.6
-
-
Method Summary
Methods Modifier and Type Method and Description String
getEngineName()
Returns the full name of theScriptEngine
.String
getEngineVersion()
Returns the version of theScriptEngine
.List<String>
getExtensions()
Returns an immutable list of filename extensions, which generally identify scripts written in the language supported by thisScriptEngine
.String
getLanguageName()
Returns the name of the scripting langauge supported by thisScriptEngine
.String
getLanguageVersion()
Returns the version of the scripting language supported by thisScriptEngine
.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.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 theScriptEngine
, which may be used to identify theScriptEngine
by theScriptEngineManager
.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 progam with given statements.ScriptEngine
getScriptEngine()
Returns an instance of theScriptEngine
associated with thisScriptEngineFactory
.
-
-
-
Method Detail
-
getEngineName
String getEngineName()
Returns the full name of theScriptEngine
. 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
String getEngineVersion()
Returns the version of theScriptEngine
.- Returns:
- The
ScriptEngine
implementation version.
-
getExtensions
List<String> getExtensions()
Returns an immutable list of filename extensions, which generally identify scripts written in the language supported by thisScriptEngine
. The array is used by theScriptEngineManager
to implement itsgetEngineByExtension
method.- Returns:
- The list of extensions.
-
getMimeTypes
List<String> getMimeTypes()
Returns an immutable list of mimetypes, associated with scripts that can be executed by the engine. The list is used by theScriptEngineManager
class to implement itsgetEngineByMimetype
method.- Returns:
- The list of mime types.
-
getNames
List<String> getNames()
Returns an immutable list of short names for theScriptEngine
, which may be used to identify theScriptEngine
by theScriptEngineManager
. For instance, an implementation based on the Mozilla Rhino Javascript engine might return list containing {"javascript", "rhino"}.
-
getLanguageName
String getLanguageName()
Returns the name of the scripting langauge supported by thisScriptEngine
.- Returns:
- The name of the supported language.
-
getLanguageVersion
String getLanguageVersion()
Returns the version of the scripting language supported by thisScriptEngine
.- Returns:
- The version of the supported language.
-
getParameter
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:- ScriptEngine.ENGINE
- ScriptEngine.ENGINE_VERSION
- ScriptEngine.NAME
- ScriptEngine.LANGUAGE
- ScriptEngine.LANGUAGE_VERSION
The values for these keys are the Strings returned by
getEngineName
,getEngineVersion
,getName
,getLanguageName
andgetLanguageVersion
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 theTHREADING
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 theBindings
which is the engine scope of theScriptEngine
. In particular, the keys in theBindings
and their associated values are the same before and after the execution of the script.
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.
-
getMethodCallSyntax
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 += ","; } } 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 theput
method ofScriptEngine
, theput
method of anENGINE_SCOPE
Bindings
,or thesetAttribute
method ofScriptContext
. 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.
-
getOutputStatement
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.
-
getProgram
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 thegetMethodCallSyntax
andgetOutputStatement
methods.- Returns:
- The Program
-
getScriptEngine
ScriptEngine getScriptEngine()
Returns an instance of theScriptEngine
associated with thisScriptEngineFactory
. A new ScriptEngine is generally returned, but implementations may pool, share or reuse engines.- Returns:
- A new
ScriptEngine
instance.
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/script/ScriptEngineFactory.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.