Package cbsw

Class AbstractCommand

  • Direct Known Subclasses:
    Command, Command

    public abstract class AbstractCommand
    extends java.lang.Object

    This class encapsulates a static method invoked through Java reflection.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.swing.JButton button  
      java.lang.String data
      The target method parameters.
      protected java.util.HashMap<java.lang.String,​java.lang.String> dataMap
      A map of key/value pairs passed to the command.
      java.lang.String label
      The label that appears on the button associated with the command.
      protected javax.swing.JTextField statusTF  
      protected boolean stopOnFail
      Flag to control behaviour on a FAIL response.
      java.lang.String targetClass
      The static method's class.
      java.lang.String targetMethod
      The method to call.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractCommand()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clearStatus()
      Clears the text field.
      static java.lang.Object exec​(java.lang.Class<?> targetClass, java.lang.String targetMethod, java.lang.String[] targetArgs)
      Calls a static method by Java reflection.
      static java.lang.Object exec​(java.lang.Class<?> targetClass, java.lang.String targetMethod, java.util.HashMap<java.lang.String,​java.lang.String> targetArgs)
      Calls a static method by Java reflection.
      abstract void go()
      Parses, calls and handles reponses for a command.
      void setButton​(javax.swing.JButton button)
      Registers the button that executes the command.
      void setStatusTextField​(javax.swing.JTextField statusTF)
      Registers a text field used to display messages.
      static java.lang.String shell​(java.lang.String[] args)
      Invokes an OS shell script.
      static java.lang.String shell2​(java.lang.String[] args)
      Invokes an OS shell script.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • label

        public java.lang.String label

        The label that appears on the button associated with the command.

      • targetMethod

        public java.lang.String targetMethod

        The method to call.

      • targetClass

        public java.lang.String targetClass

        The static method's class.

      • stopOnFail

        protected boolean stopOnFail

        Flag to control behaviour on a FAIL response.

      • data

        public java.lang.String data

        The target method parameters.

      • dataMap

        protected java.util.HashMap<java.lang.String,​java.lang.String> dataMap

        A map of key/value pairs passed to the command.

      • statusTF

        protected javax.swing.JTextField statusTF
      • button

        protected javax.swing.JButton button
    • Constructor Detail

      • AbstractCommand

        public AbstractCommand()
    • Method Detail

      • go

        public abstract void go()
                         throws java.lang.Exception

        Parses, calls and handles reponses for a command.

        Throws:
        java.lang.Exception - The exception
      • exec

        public static java.lang.Object exec​(java.lang.Class<?> targetClass,
                                            java.lang.String targetMethod,
                                            java.lang.String[] targetArgs)

        Calls a static method by Java reflection.

        Parameters:
        targetClass - The class of the method.
        targetMethod - The method.
        targetArgs - Command line parameters.
        Returns:
        The command response
      • exec

        public static java.lang.Object exec​(java.lang.Class<?> targetClass,
                                            java.lang.String targetMethod,
                                            java.util.HashMap<java.lang.String,​java.lang.String> targetArgs)

        Calls a static method by Java reflection.

        Parameters:
        targetClass - The class of the method.
        targetMethod - The method.
        targetArgs - Map of parameters.
        Returns:
        The command response
      • shell

        public static java.lang.String shell​(java.lang.String[] args)

        Invokes an OS shell script.

        Creates a process whose stdout is connected to an input channel.

        Process completion is signalled by the process sending a completion response message. This method blocks until it receives the completion response message therefore the process should not write anything other than its completion response to its stdout or this method will return prematurely.

        Parameters:
        args - {0=script-path,1...=command-parameters}
        Returns:
        The command response.
      • shell2

        public static java.lang.String shell2​(java.lang.String[] args)

        Invokes an OS shell script.

        Creates a process whose stdout is connected to an input channel.

        Process completion is signalled by the process sending a completion response message. This method blocks until it receives the completion response message therefore the process should not write anything other than its completion response to its stdout or this method will return prematurely.

        Parameters:
        args - {0=script-path,1...=command-parameters}
        Returns:
        The command response.
      • setStatusTextField

        public void setStatusTextField​(javax.swing.JTextField statusTF)

        Registers a text field used to display messages.

        Parameters:
        statusTF - The text field.
      • setButton

        public void setButton​(javax.swing.JButton button)

        Registers the button that executes the command.

        Parameters:
        button - The button.
      • clearStatus

        public void clearStatus()

        Clears the text field.