public class ScriptJob extends SerializableJob implements ConsoleOwner
The named beans property allow values to be passed to and from the script.
Script output is captured in a console that is visible from Oddjob Explorer in addition to any output properties.
<oddjob> <job> <script id="s" language="JavaScript">print ("hello world\n");</script> </job> </oddjob>
<oddjob> <job> <sequential> <jobs> <script id="s" language="JavaScript"> <input> <buffer> var snack = fruit; </buffer> </input> <beans> <value key="fruit" value="apple"/> </beans> </script> <echo id="e">${s.variables(fruit)}</echo> </jobs> </sequential> </job> </oddjob>
<oddjob> <job> <sequential> <jobs> <script id="s" language="JavaScript"> <input> <buffer> vars.set('today', new java.util.Date()); </buffer> </input> <beans> <value key="vars" value="${v}"/> </beans> </script> <variables id="v"> <formattedToday> <format date="${v.today}" format="yyyyMMdd"/> </formattedToday> </variables> </jobs> </sequential> </job> </oddjob>
<oddjob> <job> <sequential> <jobs> <script id="substr" language="JavaScript"> <input> <buffer>function substr(string, from, to) { return string.substring(from, to); }</buffer> </input> </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>
<oddjob> <job> <script language="JavaScript" resultVariable="result" resultForState="true"> <input> <buffer> var result = 1; </buffer> </input> </script> </job> </oddjob>
<oddjob> <job> <script language="JavaScript" resultVariable="result" resultForState="true"> <input> <buffer> var result = 1; </buffer> </input> </script> </job> </oddjob>
<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>
Constructor and Description |
---|
ScriptJob() |
Modifier and Type | Method and Description |
---|---|
protected int |
_execute() |
LogArchive |
consoleLog()
Provide the console archive.
|
protected int |
execute()
Execute this job.
|
java.lang.Object |
getBeans(java.lang.String name)
Get the named bean.
|
java.lang.ClassLoader |
getClassLoader() |
java.util.function.Function<java.lang.Object,java.lang.Object> |
getFunction(java.lang.String name) |
java.io.InputStream |
getInput()
Get the input.
|
javax.script.Invocable |
getInvocable() |
java.lang.String |
getLanguage()
Get the language.
|
java.lang.Object |
getResult() |
java.lang.String |
getResultVariable() |
java.lang.String |
getScript() |
java.io.OutputStream |
getStderr() |
java.io.InputStream |
getStdin() |
java.io.OutputStream |
getStdout() |
java.lang.Object |
getVariables(java.lang.String key) |
boolean |
isRedirectStderr() |
boolean |
isResultForState() |
void |
setBeans(java.lang.String name,
java.lang.Object value)
Add a named bean.
|
void |
setClassLoader(java.lang.ClassLoader classLoader) |
void |
setInput(java.io.InputStream input)
Set the input.
|
void |
setLanguage(java.lang.String language)
Defines the language (required).
|
void |
setRedirectStderr(boolean redirectStderr) |
void |
setResultForState(boolean resultForState) |
void |
setResultVariable(java.lang.String resultVariable) |
void |
setScript(java.lang.String script) |
void |
setStderr(java.io.OutputStream stderr) |
void |
setStdin(java.io.InputStream stdin) |
void |
setStdout(java.io.OutputStream stdout) |
fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onReset, onStop, run, sleep, softReset, stateHandler, stop
configure, getName, logger, logger, loggerName, save, setName, toString
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addStateListener, lastStateEvent, removeStateListener
protected int execute() throws java.io.IOException
SimpleJob
protected int _execute() throws java.io.IOException
java.io.IOException
public LogArchive consoleLog()
ConsoleOwner
consoleLog
in interface ConsoleOwner
public void setLanguage(java.lang.String language)
language
- the scripting language name for the script.public java.lang.String getLanguage()
public java.lang.Object getBeans(java.lang.String name)
name
- The name of the beanpublic void setBeans(java.lang.String name, java.lang.Object value)
name
- The name of the bean.value
- The bean.public java.io.InputStream getInput()
public void setInput(java.io.InputStream input)
input
- The input.public java.lang.String getScript()
public void setScript(java.lang.String script)
public javax.script.Invocable getInvocable()
public java.util.function.Function<java.lang.Object,java.lang.Object> getFunction(java.lang.String name)
public boolean isRedirectStderr()
public void setRedirectStderr(boolean redirectStderr)
public java.io.InputStream getStdin()
public void setStdin(java.io.InputStream stdin)
public java.io.OutputStream getStdout()
public void setStdout(java.io.OutputStream stdout)
public java.io.OutputStream getStderr()
public void setStderr(java.io.OutputStream stderr)
public java.lang.Object getVariables(java.lang.String key)
Property: variables
Description: Provide access to variables declared within the script.
public java.lang.String getResultVariable()
public void setResultVariable(java.lang.String resultVariable)
public boolean isResultForState()
public void setResultForState(boolean resultForState)
public java.lang.Object getResult()
public java.lang.ClassLoader getClassLoader()
@Inject public void setClassLoader(java.lang.ClassLoader classLoader)