uk.ac.starlink.task
Class TerminalInvoker

java.lang.Object
  extended by uk.ac.starlink.task.TerminalInvoker

public class TerminalInvoker
extends 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
TerminalInvoker(String toolname, Map<String,Task> taskmap)
          Creates a new invoker based on the given class with a given name.
 
Method Summary
static String getTaskUsage(Task task)
          Returns a usage string for a given task.
 void invoke(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(String toolname,
                       Map<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(String[] args)
            throws 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:
Exception

getTaskUsage

public static 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


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.