Skip navigation links

Package org.macroing.cel4j.artifact

Provides a ScriptEngine implementation called Artifact that evaluates a super-set of Java source code.

See: Description

Package org.macroing.cel4j.artifact Description

Provides a ScriptEngine implementation 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.

Skip navigation links