Class 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.
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • 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.
    • Field Detail

      • 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_ForwardsMap

        protected Map<String,​Object> m_ForwardsMap
        the forwards map.
      • 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 script
        script - 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 script
        script - the script to execute
        inputs - 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 script
        scriptFile - 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 script
        scriptFile - the script file to execute
        inputs - 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 script
        script - the script to execute, can be null
        scriptFile - the script file to execute, can be null
        inputs - 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 class adams.core.logging.LoggingObject
      • setOwner

        public void setOwner​(JepScriptingEngineThread value)
        Sets the owning thread.
        Parameters:
        value - the owner
      • setFlowContext

        public void setFlowContext​(adams.flow.core.Actor value)
        Sets the flow context.
        Specified by:
        setFlowContext in interface adams.flow.core.FlowContextHandler
        Parameters:
        value - the actor
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the flow context, if any.
        Specified by:
        getFlowContext in interface adams.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