public abstract class AbstractMain extends Thread
Menus and prompts are displayed on standard output. The inputMenu
method is called to
render the current menu to standard out. When the user issues a selection on standard output, the
processCommand
method is called to perform whatever required action.
There are also abstract methods that parse command line arguments (processArguments
and
to present the command line syntax (getCommandSyntax
) in the event of a command line
argument error. Any exception thrown by the processArguments method will result in the command
line syntax being displayed, then the system will exit. Subclasses may also call the
errorProcessingArguments
method with a message argument to provide a custom error
message. If the processArguments method throws an exception, the message associated with that
exception will be displayed along with the command line syntax.
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier | Constructor and Description |
---|---|
protected |
AbstractMain(String[] args)
This class takes a list of command line arguments.
|
Modifier and Type | Method and Description |
---|---|
protected void |
errorProcessingArguments(String message)
this method is called if there is a catastrophic error processing arguments.
|
protected abstract String |
getCommandSyntax()
This method will return a string which documents the command line arguments before a system
exit.
|
protected abstract void |
inputMenu()
present the input menu to standard out.
|
protected abstract int |
processArgument(String[] args,
int current)
This will process the current argument, and return the integer indicating the next argument
to be processed.
|
protected void |
processArguments(String[] args)
this method will traverse all arguments calling the processArgument method with each
argument.
|
protected abstract void |
processCommand(String line)
Process the command provided in line.
|
void |
run()
Present a menu indicating the current display and providing an input menu, fetch the next
line, the process the assumed command there.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
protected AbstractMain(String[] args)
args
- the arguments.protected void errorProcessingArguments(String message)
message
- the error message to report before the command line syntax.protected void processArguments(String[] args)
args
- the array of arguments.public void run()
protected abstract void processCommand(String line) throws Exception
line
- the command to process.Exception
protected abstract void inputMenu()
protected abstract String getCommandSyntax()
protected abstract int processArgument(String[] args, int current) throws Exception
args
- the arguments.current
- the index of the current argument.Exception
- if fatal error, throw an exception will cause a system exit.Copyright © 2017. All rights reserved.