Package adams.core.scripting
Class JepScriptlet
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.scripting.JepScriptlet
-
- All Implemented Interfaces:
adams.core.logging.LoggingLevelHandler
,adams.core.logging.LoggingSupporter
,adams.core.SizeOfHandler
,adams.flow.core.FlowContextHandler
,Serializable
public class JepScriptlet extends adams.core.logging.CustomLoggingLevelObject implements adams.flow.core.FlowContextHandler
Encapsulates Jep/Python scripts.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_ExpandVariables
whether to expand variables.protected boolean
m_Finished
whether the scriplet has been executed.protected adams.flow.core.Actor
m_FlowContext
the flow context.protected adams.core.base.BaseString[]
m_Forwards
the forwards.protected Map<String,Object>
m_ForwardsMap
the forwards map.protected String
m_ID
the ID of the scriptlet.protected adams.flow.control.VariableNameStorageNamePair[]
m_Inputs
the inputs.protected String
m_LastError
the last error.protected adams.flow.control.VariableNameStorageNamePair[]
m_Outputs
the outputs.protected JepScriptingEngineThread
m_Owner
the owning thread (with the interpreter).protected String
m_Script
the script to execute.protected File
m_ScriptFile
the script file to execute.
-
Constructor Summary
Constructors Constructor Description JepScriptlet(String id, File scriptFile)
Initializes the scriptlet.JepScriptlet(String id, File scriptFile, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.JepScriptlet(String id, String script)
Initializes the scriptlet.JepScriptlet(String id, String script, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.JepScriptlet(String id, String script, File scriptFile, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configureLogger()
Initializes the logger.String
execute()
Executes the script.void
fail(String msg)
Sets the error message and that the script has finished to true.boolean
getExpandVariables()
Returns whether ADAMS variables get expanded in the script.adams.flow.core.Actor
getFlowContext()
Returns the flow context, if any.adams.core.base.BaseString[]
getForwards()
Returns the variables to forward.Map<String,Object>
getForwardsMap()
Returns the parameter values to forward as map.String
getID()
Returns the ID of the script.adams.flow.control.VariableNameStorageNamePair[]
getInputs()
Returns the inputs to use (objects to retrieve from storage), if any.String
getLastError()
Returns any error that was encountered.adams.flow.control.VariableNameStorageNamePair[]
getOutputs()
Returns the outputs to use (objects to store back in storage), if any.JepScriptingEngineThread
getOwner()
Returns the owning thread.String
getScriptContent()
Returns the script content.boolean
hasFinished()
Whether the scriptlet has finished execution.boolean
hasLastError()
Checks whether an error is present.void
setFlowContext(adams.flow.core.Actor value)
Sets the flow context.void
setOwner(JepScriptingEngineThread value)
Sets the owning thread.-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Owner
protected JepScriptingEngineThread m_Owner
the owning thread (with the interpreter).
-
m_ID
protected String m_ID
the ID of the scriptlet.
-
m_LastError
protected String m_LastError
the last error.
-
m_Script
protected String m_Script
the script to execute.
-
m_ScriptFile
protected File m_ScriptFile
the script file to execute.
-
m_FlowContext
protected adams.flow.core.Actor m_FlowContext
the flow context.
-
m_ExpandVariables
protected boolean m_ExpandVariables
whether to expand variables.
-
m_Inputs
protected adams.flow.control.VariableNameStorageNamePair[] m_Inputs
the inputs.
-
m_Outputs
protected adams.flow.control.VariableNameStorageNamePair[] m_Outputs
the outputs.
-
m_Forwards
protected adams.core.base.BaseString[] m_Forwards
the forwards.
-
m_Finished
protected boolean m_Finished
whether the scriplet has been executed.
-
-
Constructor Detail
-
JepScriptlet
public JepScriptlet(String id, String script)
Initializes the scriptlet.- Parameters:
id
- the ID of the scriptscript
- the script to execute
-
JepScriptlet
public JepScriptlet(String id, String script, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.- Parameters:
id
- the ID of the scriptscript
- the script to executeinputs
- the inputs for the script (from storage)outputs
- the outputs from the script (to go back into storage)forwards
- the variable values from the script to forward as map
-
JepScriptlet
public JepScriptlet(String id, File scriptFile)
Initializes the scriptlet.- Parameters:
id
- the ID of the scriptscriptFile
- the script file to execute
-
JepScriptlet
public JepScriptlet(String id, File scriptFile, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.- Parameters:
id
- the ID of the scriptscriptFile
- the script file to executeinputs
- the inputs for the script (from storage)outputs
- the outputs from the script (to go back into storage)forwards
- the variable values from the script to forward as map
-
JepScriptlet
public JepScriptlet(String id, String script, File scriptFile, adams.flow.control.VariableNameStorageNamePair[] inputs, adams.flow.control.VariableNameStorageNamePair[] outputs, adams.core.base.BaseString[] forwards, boolean expandVars)
Initializes the scriptlet.- Parameters:
id
- the ID of the scriptscript
- the script to execute, can be nullscriptFile
- the script file to execute, can be nullinputs
- the inputs for the script (from storage)outputs
- the outputs from the script (to go back into storage)forwards
- the variable values from the script to forward as map
-
-
Method Detail
-
configureLogger
protected void configureLogger()
Initializes the logger.- Overrides:
configureLogger
in classadams.core.logging.LoggingObject
-
setOwner
public void setOwner(JepScriptingEngineThread value)
Sets the owning thread.- Parameters:
value
- the owner
-
getOwner
public JepScriptingEngineThread getOwner()
Returns the owning thread.- Returns:
- the owner
-
setFlowContext
public void setFlowContext(adams.flow.core.Actor value)
Sets the flow context.- Specified by:
setFlowContext
in interfaceadams.flow.core.FlowContextHandler
- Parameters:
value
- the actor
-
getFlowContext
public adams.flow.core.Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContext
in interfaceadams.flow.core.FlowContextHandler
- Returns:
- the actor, null if none available
-
getID
public String getID()
Returns the ID of the script.- Returns:
- the ID
-
getScriptContent
public String getScriptContent()
Returns the script content.- Returns:
- the content
-
getInputs
public adams.flow.control.VariableNameStorageNamePair[] getInputs()
Returns the inputs to use (objects to retrieve from storage), if any.- Returns:
- the inputs, can be null
-
getOutputs
public adams.flow.control.VariableNameStorageNamePair[] getOutputs()
Returns the outputs to use (objects to store back in storage), if any.- Returns:
- the outputs, can be null
-
getForwards
public adams.core.base.BaseString[] getForwards()
Returns the variables to forward.- Returns:
- the forwards, can be null
-
getForwardsMap
public Map<String,Object> getForwardsMap()
Returns the parameter values to forward as map.- Returns:
- the map, can be null
-
getExpandVariables
public boolean getExpandVariables()
Returns whether ADAMS variables get expanded in the script.- Returns:
- true if expanded
-
hasFinished
public boolean hasFinished()
Whether the scriptlet has finished execution.- Returns:
- true when finished
-
hasLastError
public boolean hasLastError()
Checks whether an error is present.- Returns:
- true if error present
-
getLastError
public String getLastError()
Returns any error that was encountered.- Returns:
- the error, null if none encountered
-
execute
public String execute()
Executes the script.- Returns:
- null if successful, otherwise error message
-
fail
public void fail(String msg)
Sets the error message and that the script has finished to true.- Parameters:
msg
- the error message to set
-
-