Class Application

  • All Implemented Interfaces:
    Serializable, Runnable
    Direct Known Subclasses:
    CommandLineApplication

    public abstract class Application
    extends Object
    implements Runnable, Serializable

    Generic interface for building applications that use Mango's Config and CommandLineParser to reduce the boilerplate of application configuration and command line parsing. The command line parser is constructed during the call to run(String[]) and has it options set to fields in the application defined using the Option annotation.

    Applications provide access to all arguments on the command line through getAllArguments() and to positional (non-parsed) objects through getPositionalArgs(). Application flow begins with a call to run(String[]) which loads the config files and parses the command line and then calls setup() to setup the application, and finally Runnable.run() implementing the run logic. Note that additional config packages can be loaded by defining additional packages in getDependentPackages()

    A Description annotation can be added to a class to provide a short description of what the program does and will be displayed as part of the help screen.

    Author:
    David B. Bracewell
    See Also:
    Serialized Form
    • Constructor Detail

      • Application

        public Application()
      • Application

        public Application​(String name)
    • Method Detail

      • getAllArguments

        public final String[] getAllArguments()

        Get all arguments passed to the application.

        Returns:
        the array of arguments passed to the application
      • getDependentPackages

        public Set<String> getDependentPackages()
        Gets the set of dependent packages whose config needs to be loaded
        Returns:
        the dependent packages
      • getName

        public final String getName()
        Gets the name of the application
        Returns:
        The name of the application
      • getPositionalArgs

        public final String[] getPositionalArgs()

        Gets the command line arguments that were not specified as part of the command line parser

        Returns:
        Arguments not specified in the command line parser
      • run

        public final void run​(String[] args)

        Runs the application by first parsing the command line arguments and initializing the config. The process then runs the setup() method to perform any special user-defined setup (e.g. gui initialization for JavaFX or swing) and then finally runs the Runnable.run() command which performs the application logic and is specific to each implementation.

        Parameters:
        args - the command line arguments
      • setup

        public abstract void setup()
                            throws Exception

        Runs specialized code to setup the application before the Runnable.run() command is called.

        Throws:
        Exception - Something went wrong during setup.