org.hyphenType.wrapper
Class StandAloneAppWrapper

java.lang.Object
  extended by org.hyphenType.wrapper.StandAloneAppWrapper
Direct Known Subclasses:
RBGenerator

public class StandAloneAppWrapper
extends Object

A wrapper that can be called instead of a standard main class. When called as a main class, this class will try to find which class is the actual main class of the application. After this actual main class was found, this class will parse the arguments to a options interface and give an instance of the options interface to the actual main class.

Author:
Aurelio Akira M. Matsui

Field Summary
static String ARGUMENT
          The especial argument that explicitly sets which is the main class.
static String KEY
          Manifest files can have a key value pair with this key to explicitly set which is the actual main class.
 
Constructor Summary
StandAloneAppWrapper()
           
 
Method Summary
protected  Options buildOptionsObject(Class<?> mainClass, String[] arguments)
          Ready to be overridden in a subclass.
 void invokeMain(Class<?> mainClass, String[] arguments)
          Invokes the main method of the given class.
 void invokeMain(Class<?> mainClass, String[] arguments, boolean trapThrowable)
          Invokes the main method of the given class.
static void main(Class<?> mainClass, String... arguments)
          A safer main method.
static void main(String... arguments)
          Standard main method.
protected static boolean mainClassInvalid(String mainClassName)
           
static
<E extends Options<?>>
E
options()
          Gives system-wide access to the options object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY

public static final String KEY
Manifest files can have a key value pair with this key to explicitly set which is the actual main class.

See Also:
Constant Field Values

ARGUMENT

public static final String ARGUMENT
The especial argument that explicitly sets which is the main class.

See Also:
Constant Field Values
Constructor Detail

StandAloneAppWrapper

public StandAloneAppWrapper()
Method Detail

main

public static void main(String... arguments)
                 throws Throwable
Standard main method.

Parameters:
arguments - Arguments from the command line.
Throws:
Throwable - Anything that can go wrong.

mainClassInvalid

protected static boolean mainClassInvalid(String mainClassName)

main

public static void main(Class<?> mainClass,
                        String... arguments)
                 throws Throwable
A safer main method. It is safer because this method receives which is the actual main class as a parameter.

Parameters:
mainClass - The main class to execute.
arguments - The arguments, from command line.
Throws:
Throwable - Anything that can go wrong.

invokeMain

public final void invokeMain(Class<?> mainClass,
                             String[] arguments)
                      throws Throwable
Invokes the main method of the given class. It also parses the received arguments and creates an option object. This method will trap all throwables, preventing them to go uncaught to the JVM. Instead, an error message is printed.

Parameters:
mainClass - The main class to be executed.
arguments - The arguments received from the command line.
trapThrowable - If true, this method will prevent throwables from going uncaught to the JVM, which causes the throwable to be printed in user's console.
Throws:
Throwable - Anything that can go wrong.

invokeMain

public final void invokeMain(Class<?> mainClass,
                             String[] arguments,
                             boolean trapThrowable)
                      throws Throwable
Invokes the main method of the given class. It also parses the received arguments and creates an option object.

Parameters:
mainClass - The main class to be executed.
arguments - The arguments received from the command line.
trapThrowable - If true, this method will prevent throwables from going uncaught to the JVM, which causes the throwable to be printed in user's console.
Throws:
Throwable - Anything that can go wrong.

buildOptionsObject

protected Options buildOptionsObject(Class<?> mainClass,
                                     String[] arguments)
                              throws InvalidOptionsInterfaceException,
                                     OptionValuesException,
                                     OptionsExtractorException
Ready to be overridden in a subclass.

Parameters:
mainClass - The options interface type.
arguments - The arguments, as received from the command line.
Returns:
The options object.
Throws:
InvalidOptionsInterfaceException - If the options interface is invalid. There are many reasons why an options interface may be invalid. For a detailed description on the conditions for an options interface to be invalid, please refer to InvalidOptionsInterfaceException
OptionValuesException - If there is anything wrong with the arguments passed. For an in depth description, please refer to OptionsExtractor.options(UserInput, String...) .
OptionsExtractorException

options

public static <E extends Options<?>> E options()
Gives system-wide access to the options object. If you did not use the StandAloneAppWrapper to start your application, this method will return null. Avoid using this method if you use the StandAloneAppWrapper for any purpose else than running the main class.

Type Parameters:
E -
Returns:


Copyright © 2013. All Rights Reserved.