public final class ArtifactScriptEngineFactory
extends java.lang.Object
implements javax.script.ScriptEngineFactory
ArtifactScriptEngineFactory is a ScriptEngineFactory that manages a ScriptEngine called Artifact that evaluates a super-set of Java source code.
The ScriptEngine provided compiles the source code into CompiledScripts and loads them, using the context ClassLoader. It caches the CompiledScripts using a normalized version of the source code provided for that
CompiledScript. By doing so, no re-compilation will be performed when you add whitespace in other places than String literals.
To demonstrate its use, here is an example:
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByExtension("java");
scriptEngine.eval("System.out.println(\"Hello, World!\"); return true;");
As you can see in the example above, you can return a result. Although you can, it's not necessary. If nothing is returned by you, null will be returned by default.
If a variable starts with a dollar sign ($), followed by a variable name (a Java identifier), that variable will be substituted for a variable in the ScriptContext and cast to its type. Lets say you have a variable $string
that refers to a variable called "string" in the ScriptContext, and that variable is of type String. A call such as $string.length() would return the length of the String variable. Note, however, that this
assumes the variable already exists in the ScriptContext prior to the evaluation of the current script. Adding a variable to the ScriptContext and then using this variable substitution mechanism to get that variable in the same
script won't work. The reason for this, is that the variable substitution is performed prior to the evaluation of the script itself.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ENGINE_NAME
A
String denoting the name of the ScriptEngine Artifact. |
| Constructor and Description |
|---|
ArtifactScriptEngineFactory()
Constructs a new
ArtifactScriptEngineFactory instance. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getEngineName()
Returns a
String with the name of the ScriptEngine. |
java.lang.String |
getEngineVersion()
Returns a
String with the version of the ScriptEngine. |
java.util.List<java.lang.String> |
getExtensions()
Returns a
List with extensions. |
java.lang.String |
getLanguageName()
Returns a
String with the name of the language. |
java.lang.String |
getLanguageVersion()
Returns a
String with the version of the language. |
java.lang.String |
getMethodCallSyntax(java.lang.String object,
java.lang.String method,
java.lang.String... args)
Returns an empty
String at this time. |
java.util.List<java.lang.String> |
getMimeTypes()
Returns a
List with mime-types. |
java.util.List<java.lang.String> |
getNames()
Returns a
List with names. |
java.lang.String |
getOutputStatement(java.lang.String toDisplay)
Returns an empty
String at this time. |
java.lang.Object |
getParameter(java.lang.String key)
Returns an
Object value based on a String key. |
java.lang.String |
getProgram(java.lang.String... statements)
Returns an empty
String at this time. |
javax.script.ScriptEngine |
getScriptEngine()
Returns the
ScriptEngine. |
public static final java.lang.String ENGINE_NAME
String denoting the name of the ScriptEngine Artifact.public ArtifactScriptEngineFactory()
ArtifactScriptEngineFactory instance.public java.util.List<java.lang.String> getExtensions()
List with extensions.
The currently supported extensions are ".java" and "java".
getExtensions in interface javax.script.ScriptEngineFactoryList with extensionspublic java.util.List<java.lang.String> getMimeTypes()
List with mime-types.
There are currently no supported mime-types.
getMimeTypes in interface javax.script.ScriptEngineFactoryList with mime-typespublic java.util.List<java.lang.String> getNames()
List with names.
The currently supported names are "artifact" and "java".
getNames in interface javax.script.ScriptEngineFactoryList with namespublic java.lang.Object getParameter(java.lang.String key)
Object value based on a String key.
The key may be null.
getParameter in interface javax.script.ScriptEngineFactorykey - the key to return a value fromObject value based on a String keypublic javax.script.ScriptEngine getScriptEngine()
ScriptEngine.
It may be cached.
getScriptEngine in interface javax.script.ScriptEngineFactoryScriptEnginepublic java.lang.String getEngineName()
String with the name of the ScriptEngine.
The name is "Artifact".
getEngineName in interface javax.script.ScriptEngineFactoryString with the name of the ScriptEnginepublic java.lang.String getEngineVersion()
String with the version of the ScriptEngine.
The current version is "1.0.0".
getEngineVersion in interface javax.script.ScriptEngineFactoryString with the version of the ScriptEnginepublic java.lang.String getLanguageName()
String with the name of the language.
The name is "Java".
getLanguageName in interface javax.script.ScriptEngineFactoryString with the name of the languagepublic java.lang.String getLanguageVersion()
String with the version of the language.
The current version is "8".
getLanguageVersion in interface javax.script.ScriptEngineFactoryString with the version of the languagepublic java.lang.String getMethodCallSyntax(java.lang.String object,
java.lang.String method,
java.lang.String... args)
String at this time.getMethodCallSyntax in interface javax.script.ScriptEngineFactoryobject - a String with an objectmethod - a String with a methodargs - a String array with parameter argumentsString at this timepublic java.lang.String getOutputStatement(java.lang.String toDisplay)
String at this time.getOutputStatement in interface javax.script.ScriptEngineFactorytoDisplay - a String to displayString at this timepublic java.lang.String getProgram(java.lang.String... statements)
String at this time.getProgram in interface javax.script.ScriptEngineFactorystatements - a String array with statementsString at this time