Class TerminalInvoker


  • public class TerminalInvoker
    extends java.lang.Object
    Invokes Task objects in a way suitable for use from the main method, using a command line interface. The Task invoke methods are invoked and may throw any exception; UsageException and ExecutionException will be treated specially (a sanitised error message without stacktrace will be presented to the user).
    Author:
    Mark Taylor (Starlink)
    • Constructor Summary

      Constructors 
      Constructor Description
      TerminalInvoker​(java.lang.String toolname, java.util.Map<java.lang.String,​Task> taskmap)
      Creates a new invoker based on the given class with a given name.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getTaskUsage​(Task task)
      Returns a usage string for a given task.
      void invoke​(java.lang.String[] args)
      Invokes a method from this TerminalInvoker's class.
      • Methods inherited from class java.lang.Object

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

      • TerminalInvoker

        public TerminalInvoker​(java.lang.String toolname,
                               java.util.Map<java.lang.String,​Task> taskmap)
        Creates a new invoker based on the given class with a given name. This should generally be invoked from a main method - in the event of an error it will call System.exit rather than returning.
        Parameters:
        toolname - the name of this tool, used for user messages
        taskmap - map of task names to Task objects
    • Method Detail

      • invoke

        public void invoke​(java.lang.String[] args)
                    throws java.lang.Exception
        Invokes a method from this TerminalInvoker's class. The first element of the args identifies the method to be called - it is a case-insensitive version of the name of a method in the class. Subsequent elements are passed (as an args.length-1 element array of Strings) to the method in question. In the event of any trouble (e.g. unknown task, task method throws an exception) a message is printed to standard error and the JVM exits.
        Parameters:
        args - the arguments identifying what method to call and what arguments to pass to it
        Throws:
        java.lang.Exception
      • getTaskUsage

        public static java.lang.String getTaskUsage​(Task task)
        Returns a usage string for a given task. This contains only a symbolic representation of the parameter names, not the task name itself.
        Parameters:
        task - task
        Returns:
        usage string