CmdLine (Basic)
I. Description
This is the root class of this CmdLine package to provide basic function of interactive interface for command line tool. The following steps are needed to use this class:
- make YourClass as a sub-class of CmdLine
import gov.nih.nlm.nls.stmt.CmdLine.*;
import gov.nih.nlm.nls.stmt.Lib.*;
public class YourClass extends CmdLine
- instantiate YourClass and call Run(args) method in the main method
YourClass yourClass = new YourClass();
yourClass.Run(args);
- override following methods
protected void InitLocalObjs()
=> instantiate local data members
protected void SetToolInfo()
=> set tool info, such as promptStr, tool name, version, config file, etc.
protected void CloseLocalObjs()
=> clean up local data members
protected void ProcessLine(String line)
=> how to process the input line
II. Main Algorithm
public void Run(String[] args)
- if (PreProcess(args) == true)
- Process( );
- PostProcess( );
- else
protected boolean PreProcess(String[] args)
- PreProcess: init data members
- should be override in config or arguments options classes
- check args, if true
- SetToolInfo( );
=> protected method and must be override in YourClass
- SetValues( );
- Set all data members by default
- If (runFlag_ == true)
- InitLocalObjs( );
=> protected method and must be override in YourClass
protected void Process()
- ProcessCore( )
- check runFlag_
- check promptFlag_ to show promptStr_
- read input from line
- check quit option
- ProcessLine(line)
=> protected method and must be override in YourClass
protected void PostProcess()
- CloseLocalObjs( );
=> protected method and must be override in YourClass
protected void HelpMenu()
- Print out help menu
- a protected method
- should be override in config or arguments options classes
III. Abstract Methods
protected abstract void InitLocalObjs();
=> instantiate local data members in the subclass
protected abstract void SetToolInfo();
=> Set tool info (data members from CmdLine), such as tool anme, version, config file, prompt Str, etc.
protected abstract void ProcessLine(String line);
=> algorithm of how to process the input (line)
protected abstract void CloseLocalObjs();
=> Close (clean up) local data members in the subclass