net.sf.saffron.util
Class MainApp

java.lang.Object
  |
  +--net.sf.saffron.util.MainApp

public abstract class MainApp
extends Object

Abstract base class for a Java application invoked from the command-line.

Example usage:

public class MyClass extends MainApp {
     public static void main(String[] args) {
         new MyClass(args).run();
     }
     public void mainImpl() {
         System.out.println("Hello, world!");
     }
 }

Since:
Aug 31, 2003
Version:
$Id: //open/saffron/src/net/sf/saffron/util/MainApp.java#2 $
Author:
jhyde

Field Summary
protected  String[] args_
           
private  int exitCode_
           
private  OptionsList options_
           
 
Constructor Summary
protected MainApp(String[] args)
           
 
Method Summary
 void handle(Throwable throwable)
          Handles an error.
protected  void initializeOptions()
          Initializes the application.
abstract  void mainImpl()
          Does the work of the application.
 void parseOptions(OptionsList.OptionHandler values)
           
 void run()
          Does the work of the application, handles any errors, then calls System.exit(int) to terminate the application.
 void setExitCode(int exitCode)
          Sets the code which this program will return to the operating system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

args_

protected final String[] args_

options_

private OptionsList options_

exitCode_

private int exitCode_
Constructor Detail

MainApp

protected MainApp(String[] args)
Method Detail

mainImpl

public abstract void mainImpl()
                       throws Exception
Does the work of the application. Derived classes must implement this method; they can throw any exception they like, and run() will clean up after them.

Exception

run

public final void run()
Does the work of the application, handles any errors, then calls System.exit(int) to terminate the application.


setExitCode

public void setExitCode(int exitCode)
Sets the code which this program will return to the operating system.

Parameters:
exitCode - Exit code
See Also:
System.exit(int)

handle

public void handle(Throwable throwable)
Handles an error. Derived classes may override this method to provide their own error-handling.

Parameters:
throwable - Error to handle.

parseOptions

public void parseOptions(OptionsList.OptionHandler values)

initializeOptions

protected void initializeOptions()
Initializes the application.


SourceForge.net_Logo