Class AbstractCommand

java.lang.Object
cbsw.AbstractCommand
Direct Known Subclasses:
Command, Command

public abstract class AbstractCommand extends Object

This class encapsulates a static method invoked through Java reflection.

  • Field Details

    • label

      public String label

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

    • targetMethod

      public String targetMethod

      The method to call.

    • targetClass

      public String targetClass

      The static method's class.

    • stopOnFail

      protected boolean stopOnFail

      Flag to control behaviour on a FAIL response.

    • data

      public String data

      The target method parameters.

    • dataMap

      protected HashMap<String,String> dataMap

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

    • statusTF

      protected JTextField statusTF
    • button

      protected JButton button
  • Constructor Details

    • AbstractCommand

      public AbstractCommand()
  • Method Details

    • go

      public abstract void go() throws Exception

      Parses, calls and handles reponses for a command.

      Throws:
      Exception - The exception
    • exec

      public static Object exec(Class<?> targetClass, String targetMethod, 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 Object exec(Class<?> targetClass, String targetMethod, HashMap<String,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 String shell(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 String shell2(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(JTextField statusTF)

      Registers a text field used to display messages.

      Parameters:
      statusTF - The text field.
    • setButton

      public void setButton(JButton button)

      Registers the button that executes the command.

      Parameters:
      button - The button.
    • clearStatus

      public void clearStatus()

      Clears the text field.