com.syncbuilder.app
Class BasicAppSkeleton

java.lang.Object
  |
  +--com.syncbuilder.app.BasicAppSkeleton
Direct Known Subclasses:
SyncAppSkeleton

public class BasicAppSkeleton
extends java.lang.Object

This class is a skeleton for any command-line application. It uses an extremely powerful command-line parser (derived from GNU getopt), and it can control the flow of the entire initialization sequence of the app.

It can also turn almost any command-line app into a simple GUI app. Every application which you create with this skeleton will contain two standard options:
-gui will turn on the GUI interface.
-help will display usage information.


Field Summary
protected  java.util.Hashtable _arguments
           
protected  boolean _has_gui
           
 int extra_args
           
protected  java.util.Vector options
           
 
Constructor Summary
BasicAppSkeleton()
           
 
Method Summary
protected  void _displayUsage()
           
protected  void _inquireParameters()
          Determine the missing parameters, either through the default-values, or by asking the user.
protected  void _parseArguments(java.lang.String[] args, Index extra_args)
          Parse the arguments from the command line, and fill them into a Hashtable.
 void addCustomOptions()
          Add new custom options to the list of options.
protected  void addFixedOptions()
          This one will be invoked by runApp before addCustomOptions().
 void appMain()
          The custom-code for your application goes here.
 void displayMessage(java.lang.String msg, java.lang.String action)
          Use this method to display messages that require the immediate attention of the user.
 boolean getFlagOpt(java.lang.String name)
          Get the boolean value of an option
 int getNumericalOpt(java.lang.String name)
          Get the numerical value of an option
 java.lang.String getProgramInfo()
          Return a String which contains information about the program.
 java.lang.String getStringOpt(java.lang.String name)
          Get the String value of an option
 void runApp(java.lang.String[] args)
          Invoke this method to run the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

options

protected java.util.Vector options

_arguments

protected java.util.Hashtable _arguments

extra_args

public int extra_args

_has_gui

protected boolean _has_gui
Constructor Detail

BasicAppSkeleton

public BasicAppSkeleton()
Method Detail

addCustomOptions

public void addCustomOptions()
Add new custom options to the list of options. These are in addition to the hard-coded options, which means mostly the --help option.

This method will typically be overwritten by your specialization. Your code will have to add specializations of the LongOpt class to the end of the options Vector.

Example:

options.addElement(new NumericalOpt("minimum", "The minimum value", 3, true, 0, 5));

Parameters:
options - the options, as a Vector of LongOpt objects
See Also:
LongOpt, NumericalOpt, StringOpt, FlagOpt

appMain

public void appMain()
             throws java.lang.Exception
The custom-code for your application goes here. It will be invoked by the skeleton after the required options have been asked from the user.

getProgramInfo

public java.lang.String getProgramInfo()
Return a String which contains information about the program.

You will almost always overwrite this method in order to return information about your program.


runApp

public void runApp(java.lang.String[] args)
Invoke this method to run the application. It will eventually call your appMain() method, which should contain the main portion of the program.

runApp handles all the command-line parsing for you. It will also display help-texts if appropriate. It will only call your code if all the parameters are valid.


getNumericalOpt

public int getNumericalOpt(java.lang.String name)
Get the numerical value of an option

getStringOpt

public java.lang.String getStringOpt(java.lang.String name)
Get the String value of an option

getFlagOpt

public boolean getFlagOpt(java.lang.String name)
Get the boolean value of an option

displayMessage

public void displayMessage(java.lang.String msg,
                           java.lang.String action)
Use this method to display messages that require the immediate attention of the user. This method will block until the user has acknowledged the message.
Parameters:
msg - the text of the message
action - a description of what happens when the user acknowledges the message (e.g. continue).

_parseArguments

protected void _parseArguments(java.lang.String[] args,
                               Index extra_args)
Parse the arguments from the command line, and fill them into a Hashtable.
You will typically not over-ride this method.
Parameters:
args - the args-array contains the command-line parameters
extra_args - if this is != null it will be filled with the index of the first extra-argument after the last command-line parameter

_inquireParameters

protected void _inquireParameters()
Determine the missing parameters, either through the default-values, or by asking the user.

_displayUsage

protected void _displayUsage()

addFixedOptions

protected void addFixedOptions()
This one will be invoked by runApp before addCustomOptions(). It does the same thing. This method should be used by base classes for certain types of command-line apps, whereas addCustomOptions() is meant for use by the final application.
See Also:
addCustomOptions()


This material is Copyrighted (C) 1999 by Tilo Christ. All Rights Reserved.