Class AbstractScriptingEngine

    • Field Detail

      • SCRIPT_DIRECTORY

        public static final String SCRIPT_DIRECTORY
        the property for the directory containing the scripts.
        See Also:
        Constant Field Values
      • COMMAND_PROCESSOR

        public static final String COMMAND_PROCESSOR
        the property for the AbstractCommandProcessor-derived class.
        See Also:
        Constant Field Values
      • ALTERNATIVE_COMMAND_PROCESSOR

        public static final String ALTERNATIVE_COMMAND_PROCESSOR
        the property for the alternative AbstractCommandProcessor-derived class.
        See Also:
        Constant Field Values
      • m_History

        protected List<String> m_History
        the history of all (successfully run) commands since instantiation.
      • m_Recording

        protected boolean m_Recording
        whether the commands are currently being recorded.
      • m_Recorded

        protected List<String> m_Recorded
        the currently recorded commands.
      • m_ScriptingInfoListeners

        protected HashSet<ScriptingInfoListener> m_ScriptingInfoListeners
        the listeners for changes in commands being run, etc.
      • m_LastError

        protected String m_LastError
        the last last error that was encountered.
      • m_LoggingEnabled

        protected boolean m_LoggingEnabled
        whether logging is enabled.
      • m_ProcessingThread

        protected ScriptingEngineThread m_ProcessingThread
        the thread to use for executing the commands.
    • Constructor Detail

      • AbstractScriptingEngine

        protected AbstractScriptingEngine()
        Initializes the engine.
    • Method Detail

      • updatePrefix

        protected void updatePrefix()
        Updates the prefix of the console object output streams.
      • getDefaultDatabaseConnection

        protected abstract AbstractDatabaseConnection getDefaultDatabaseConnection()
        Returns the default database connection.
        Returns:
        the default database connection
      • getProcessor

        public AbstractCommandProcessor getProcessor()
        Returns the command processor to use. Initializes it if necessary.
        Returns:
        the processor
      • getProcessingThread

        public ScriptingEngineThread getProcessingThread()
        Returns the thread for processing the scripting commands.
        Returns:
        the thread
      • isEmpty

        public boolean isEmpty()
        Returns whether there are no commands in the queue currently.
        Returns:
        true if no commands wait to be processed
      • isProcessing

        public boolean isProcessing()
        Returns whether a command is currently being processed.
        Returns:
        true if a command is currently being processed
      • stop

        public void stop()
        Stops the execution of the script (will also attempt to stop the currently running step).
      • addToHistory

        public void addToHistory​(String cmd)
        Adds the command to the history.
        Parameters:
        cmd - the command to add
      • getCommandHistory

        public List<String> getCommandHistory()
        Returns the complete history of commands.
        Returns:
        the history of commands
      • startRecording

        public void startRecording()
        Starts the recording of commands.
      • stopRecording

        public void stopRecording()
        Stops the recording of commands.
      • isRecording

        public boolean isRecording()
        Whether commands are currently being recorded.
        Returns:
        true if the commands are currently being recorded
      • hasRecording

        public boolean hasRecording()
        Returns whether there are any commands in the recording buffer.
        Returns:
        true if commands were recorded
      • getRecordedCommands

        public List<String> getRecordedCommands()
        Returns the last recorded commands.
        Returns:
        the commands
      • clear

        public void clear()
        Removes all commands from the queue.
      • add

        public void add​(ScriptingCommand command)
        Adds the given command to the queue.
        Parameters:
        command - the command to add
      • add

        public void add​(BasePanel panel,
                        String cmd,
                        ScriptingCommandCode code)
        Adds the given command to the queue.
        Parameters:
        panel - the affected base panel
        cmd - the command to execute
        code - the code to execute after the command finishes
      • add

        public void add​(BasePanel panel,
                        String command)
        Adds the given command to the queue.
        Parameters:
        panel - the affected base panel
        command - the command to add
      • add

        public void add​(BasePanel panel,
                        String[] commands)
        Adds the given commands to the queue.
        Parameters:
        panel - the affected base panel
        commands - the commands to add
      • add

        public void add​(BasePanel panel,
                        List<String> commands)
        Adds the given commands to the queue.
        Parameters:
        panel - the affected base panel
        commands - the commands to add
      • add

        public void add​(BasePanel panel,
                        File commandFile)
        Adds the commands from the given file to the queue.
        Parameters:
        panel - the affected base panel
        commandFile - the file with the commands to add
      • addScriptingInfoListener

        public void addScriptingInfoListener​(ScriptingInfoListener l)
        Adds the scripting info listener to the internal list.
        Parameters:
        l - the listener to add
      • removeScriptingInfoListener

        public void removeScriptingInfoListener​(ScriptingInfoListener l)
        Removes the scripting info listener from the internal list.
        Parameters:
        l - the listener to remove
      • notifyScriptingInfoListeners

        public void notifyScriptingInfoListeners​(String cmd)
        Notifies all scripting info listeners.
        Parameters:
        cmd - the command, if any
      • hasLastError

        public boolean hasLastError()
        Returns whether there was an error during the last run.
        Specified by:
        hasLastError in interface ErrorProvider
        Returns:
        true if an error was encountered during the last run
      • setLastError

        public void setLastError​(String value)
        Sets the last error.
        Parameters:
        value - the error
      • getLastError

        public String getLastError()
        Returns the last error that was encountered, or null if no error occurred.
        Specified by:
        getLastError in interface ErrorProvider
        Returns:
        the error string or null if no error occurred
      • check

        public static boolean check​(String cmd)
        Checks whether the given string represents a command and not a comment or empty line.
        Parameters:
        cmd - the command to check
        Returns:
        true if proper command
      • filter

        public static String[] filter​(String[] cmds)
        Filters all comments and empty lines.
        Parameters:
        cmds - the commands to process
        Returns:
        the "cleansed" commands
      • filter

        public static List<String> filter​(List<String> cmds)
        Filters all comments and empty lines.
        Parameters:
        cmds - the commands to process
        Returns:
        the "cleansed" commands
      • load

        public static List<String> load​(File file)
        Returns the content of the given file, null in case of an error.
        Parameters:
        file - the file to load
        Returns:
        the content/lines of the file
      • save

        public static boolean save​(String[] script,
                                   File file)
        Saves the script content in the given file.
        Parameters:
        script - the script to save
        file - the file to save the content to
        Returns:
        true if successfully saved
      • save

        public static boolean save​(List<String> script,
                                   File file)
        Saves the script content in the given file.
        Parameters:
        script - the script to save
        file - the file to save the content to
        Returns:
        true if successfully saved
      • getDefinitionKey

        protected abstract String getDefinitionKey()
        Returns the properties key to use for retrieving the properties.
        Returns:
        the key
      • getProperties

        protected abstract Properties getProperties()
        Provides access to the properties object.
        Returns:
        the properties
      • getScriptsHome

        public String getScriptsHome()
        Returns the scripts home directory. $HOME/.gcms/scripts
        Returns:
        the scripts directory
      • getAvailableScripts

        public List<String> getAvailableScripts()
        Returns the available scripts in the scripts home directory.
        Returns:
        a list of available scripts
        See Also:
        getScriptsHome()
      • getAvailableScripts

        protected static List<String> getAvailableScripts​(String home)
        Returns the available scripts in the scripts home directory.
        Parameters:
        home - the scripts home
        Returns:
        a list of available scripts
        See Also:
        getScriptsHome()