bind property allows values to be passed to a script
so that they are available as variables.
Setting the property bindSession binds all Oddjob's beans
so that they are available as variables. This is equivalent to the variables
available #{} expressions.
variables mapped property may be used to access the variable
by name. The {@export } property will export a variable to the oddjob
session. The {@exportAll } property will export all variables into the
oddjob session. The result of a function can be accessed with the
result property. Some scripts don't return a result, in which case
the resultVariable property can be used to take the result from
a variable. If the resultForState property is true then the
result will be used to set the Completion State from the variable, 0 for
Success, otherwise Failure.
stdin
stdout, stderr and redirectStderr.
In Oddjob Explorer, a scripts output is captured in the console tab for
that job.
| beans | Deprecated. |
| bind | A named bean which is made available to the script. |
| bindSession | Make all Oddjob's components available to the script as bindings. |
| classLoader | ClassLoader to load the Script Engine. |
| export | Export bindings from the engine into the session using the given name. |
| exportAll | Export all bindings from the engine into Oddjob's session. |
| function | Adapts a script function type to a Java Function. |
| input | The script provided as input from file or buffer etc. |
| invocable | Allow a scripted function to be evaluated from elsewhere in Oddjob. |
| language | The name of the language the script is in. |
| name | A name, can be any text. |
| redirectStderr | Combine stdin and stderr. |
| result | The result of executing the script or the script
variable chosen as the result variable with the resultVariable
property. |
| resultForState | If true then use the result to determine the completion state of the job. |
| resultVariable | The variable in the script that will be used to provide the result. |
| script | The script provided as text. |
| stderr | An output to where stderr of the script will be written. |
| stdin | An input stream which will act as stdin for the script. |
| stdout | An output to where stdout for the script will be written. |
| stop | This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops. |
| variable | Provide access to variables declared within the script. |
| variables | Deprecated. |
| Example 1 | Hello World. |
| Example 2 | Variables from and to Oddjob. |
| Example 3 | Binding and exporting to Oddjob's session. |
| Example 4 | Using a script to set a property on a Job elsewhere in Oddjob. |
| Example 5 | Invoking a script to provide a substring function. |
| Example 6 | Setting the script job to not complete. |
| Example 7 | Defining Java Functions in JavaScript. |
| Configured By | ELEMENT |
| Access | READ_WRITE |
Deprecated. Use bind instead.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No. |
A named bean which is made available to the script.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. |
Make all Oddjob's components available to the script as bindings.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No. Automatically set to the current Oddjob class loader. |
ClassLoader to load the Script Engine.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No. |
Export bindings from the engine into the session using the given name. The first entry is the name of the binding, the second is the name. Repeating the name is tedious so the '.' character can be used to specify the same name as the binding.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. |
Export all bindings from the engine into Oddjob's session.
| Access | READ_ONLY |
| Required | Read Only. |
Adapts a script function type to a Java Function. This isn't really necessary with Nashorn as there is a built in Conversion to do this. May be useful for other script engines.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | Yes, if script isn't. |
The script provided as input from file or buffer etc.
| Access | READ_ONLY |
| Required | Read only. |
Allow a scripted function to be evaluated from elsewhere in Oddjob.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. Defaults to JavaScript. |
The name of the language the script is in.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. |
A name, can be any text.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. |
Combine stdin and stderr.
| Access | READ_ONLY |
The result of executing the script or the script
variable chosen as the result variable with the resultVariable
property.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No, defaults to false. |
If true then use the result to determine the completion state of the job. If the result is not a number this property will have no affect. If the result is a number and 0 the job will COMPLETE, any other value and the job will be INCOMPLETE.
| Configured By | ATTRIBUTE |
| Access | READ_WRITE |
| Required | No. |
The variable in the script that will be used to provide the result. The property is designed for use with scripting languages who's execution does not produce a result. If, however the script does produce a result and this property is set, the variable will override the scripts return value.
| Configured By | TEXT |
| Access | READ_WRITE |
| Required | Yes, if input isn't. |
The script provided as text.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No, defaults to none. |
An output to where stderr of the script will be written.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No, defaults to none. |
An input stream which will act as stdin for the script.
| Configured By | ELEMENT |
| Access | READ_WRITE |
| Required | No, defaults to none. |
An output to where stdout for the script will be written.
| Access | READ_ONLY |
| Required | Read Only. |
This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.
| Access | READ_ONLY |
| Required | Read Only. |
Provide access to variables declared within the script.
| Access | READ_ONLY |
| Required | Read Only. |
Deprecated. Use variable instead.
Hello World.
<oddjob>
<job>
<script id="script" language="JavaScript">print ("Hello, World!");</script>
</job>
</oddjob>
Variables from and to Oddjob.
<oddjob>
<job>
<sequential>
<jobs>
<variables id="vars">
<fruit>
<value value="Apple"/>
</fruit>
</variables>
<script id="script" language="JavaScript">
<bind>
<value key="fruit" value="${vars.fruit}"/>
</bind>var snack = fruit;
</script>
<echo id="echo">snack=${script.variable(snack)}
fruit=${script.variable(fruit)}</echo>
</jobs>
</sequential>
</job>
</oddjob>
Binding and exporting to Oddjob's session. The Variables
job uses Identify to insert the 'Apple' into Oddjob's session with the
name fruit. bindSession causes this to be available to script,
where it is assigned to the 'snack' variable. The script also defines
an add function. The exportAll property causes both these to
be exported to Oddjob. The two echo jobs show how these variables are
now available in Oddjob's session. When the script job is reset, the
variables are removed from the session.
<oddjob>
<job>
<sequential>
<jobs>
<variables id="vars">
<fruitVar>
<identify id="fruit">
<value>
<value value="#{'Apple'}"/>
</value>
</identify>
</fruitVar>
</variables>
<script bindSession="true" exportAll="true" id="script" language="JavaScript">function add(x, y) {
return x + y
}
snack = fruit;
</script>
<echo id="echoSnack" name="Snack Is">$${snack} is '${snack}' and ##{snack} is '#{typeof snack == 'undefined' ? 'undefined' : snack}'</echo>
<echo id="echoSum" name="Add Numbers">##add(2, 3) is #{add(2, 3)}</echo>
</jobs>
</sequential>
</job>
</oddjob>
Using a script to set a property on a Job elsewhere in Oddjob.
<oddjob>
<job>
<sequential>
<jobs>
<script id="s" language="JavaScript">
<bind>
<value key="vars" value="${v}"/>
</bind>vars.set('today', new java.util.Date());
</script>
<variables id="v">
<formattedToday>
<format date="${v.today}" format="yyyyMMdd"/>
</formattedToday>
</variables>
</jobs>
</sequential>
</job>
</oddjob>
Invoking a script to provide a substring function.
<oddjob>
<job>
<sequential>
<jobs>
<script id="substr" language="JavaScript">function substr(string, from, to) {
return string.substring(from, to);
}</script>
<properties id="properties">
<values>
<value key="text.before" value="Apples and Oranges"/>
<invoke function="substr" key="text.after">
<parameters>
<value value="${text.before}"/>
<value value="0"/>
<value value="6"/>
</parameters>
<source>
<value value="${substr.invocable}"/>
</source>
</invoke>
</values>
</properties>
</jobs>
</sequential>
</job>
</oddjob>
Setting the script job to not complete. The result of the script is used to set the state. 0 for Success, anything else for Incomplete.
<oddjob>
<job>
<script language="JavaScript" resultForState="true" resultVariable="result">var result = 1;</script>
</job>
</oddjob>
Defining Java Functions in JavaScript.
<oddjob>
<job>
<sequential>
<jobs>
<script id="funcs">function addTwo(x) { return new java.lang.Integer(x + 2)}
function multiplyByTwo(x) { return new java.lang.Integer(x * 2)}
</script>
<echo id="add">#{funcs.getFunction('addTwo').apply(5)}</echo>
<echo id="multiply">#{funcs.getFunction('multiplyByTwo').apply(3)}</echo>
</jobs>
</sequential>
</job>
</oddjob>