Package org.jppf.scripting
Class ScriptDefinition
java.lang.Object
org.jppf.scripting.ScriptDefinition
- All Implemented Interfaces:
Serializable
An easy to use wrapper around the JPPF scripting APIs.
- Author:
- Laurent Cohen
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionScriptDefinition(String language, File file) Initialize this object with the specified language and a script to read from a file.Initialize this object with the specified language, variable bindings and a script to read from a file.ScriptDefinition(String language, Reader reader) Initialize this object with the specified language and a script to read from aReader.Initialize this object with the specified language, variable bindings and a script to read from aReader.ScriptDefinition(String language, String script) Initialize this object with the specified language and a script given as text.Initialize this object with the specified language, variable bindings and a script given as text. -
Method Summary
Modifier and TypeMethodDescriptionaddBinding(String name, Object value) Add the specified variable to the user-defined bindings.evaluate()Execute the script and return its execution result, using the initial variable bindings.Execute the script and return its execution result, using additional bindings.Get the vairable bindings.getId()removeBinding(String name) Remove the specified variable from the user-defined bindings.
-
Constructor Details
-
ScriptDefinition
Initialize this object with the specified language and a script given as text.- Parameters:
language- the script language.script- the script content as text.
-
ScriptDefinition
Initialize this object with the specified language, variable bindings and a script given as text.- Parameters:
language- the script language.script- the script content as text.bindings- optional variable bindings made available to the script at execution time.
-
ScriptDefinition
Initialize this object with the specified language and a script to read from aReader.- Parameters:
language- the script language.reader- aReaderfrom which to read the script content.- Throws:
IOException- if the script content could not be read from the reader.
-
ScriptDefinition
public ScriptDefinition(String language, Reader reader, Map<String, Object> bindings) throws IOExceptionInitialize this object with the specified language, variable bindings and a script to read from aReader.- Parameters:
language- the script language.reader- aReaderfrom which to read the script content.bindings- optional variable bindings made available to the script at execution time.- Throws:
IOException- if the script content could not be read from the reader.
-
ScriptDefinition
Initialize this object with the specified language and a script to read from a file.- Parameters:
language- the script language.file- a file from which to read the script content.- Throws:
IOException- if the script content could not be read from the reader.
-
ScriptDefinition
Initialize this object with the specified language, variable bindings and a script to read from a file.- Parameters:
language- the script language.file- a file from which to read the script content.bindings- optional variable bindings made available to the script at execution time.- Throws:
IOException- if the script content could not be read from the file.
-
ScriptDefinition
- Parameters:
language- the script language.script- the script content as text.id- an identifier which allows reusing the compiled script.bindings- optional variable bindings made available to the script at execution time.
-
-
Method Details
-
getLanguage
- Returns:
- the script language.
-
getScript
- Returns:
- the script content as text.
-
getId
- Returns:
- the identifier which allows reusing the compiled script.
-
getBindings
Get the vairable bindings.- Returns:
- the optional variable bindings made available to the script at execution time.
-
evaluate
Execute the script and return its execution result, using the initial variable bindings.- Returns:
- the script execution result, or
nullif there is no result. - Throws:
JPPFScriptingException- if any error occurs while executing the script.
-
evaluate
Execute the script and return its execution result, using additional bindings.- Parameters:
additionalBindings- bindings to use in addition to the initial bindings specified in the constructor. These optional bindings are only used for a single script execution and are not kept in thisScriptDefintion.- Returns:
- the script execution result, or
nullif there is no result. - Throws:
JPPFScriptingException- if any error occurs while executing the script.
-
addBinding
Add the specified variable to the user-defined bindings.- Parameters:
name- the name of the variable binding to add.value- the value of the variable.- Returns:
- this
ScriptDefintion, for method call chaining.
-
removeBinding
Remove the specified variable from the user-defined bindings.- Parameters:
name- the name of the variable binding to remove.- Returns:
- the value of the variable, or
nullif the variable was not bound.
-