Class Application
- java.lang.Object
-
- com.gengoai.application.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
andCommandLineParser
to reduce the boilerplate of application configuration and command line parsing. The command line parser is constructed during the call torun(String[])
and has it options set to fields in the application defined using theOption
annotation.Applications provide access to all arguments on the command line through
getAllArguments()
and to positional (non-parsed) objects throughgetPositionalArgs()
. Application flow begins with a call torun(String[])
which loads the config files and parses the command line and then callssetup()
to setup the application, and finallyRunnable.run()
implementing the run logic. Note that additional config packages can be loaded by defining additional packages ingetDependentPackages()
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Application.Description
Provides a helpful description about the purpose of the application to display in the application's help
-
Constructor Summary
Constructors Constructor Description Application()
Application(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String[]
getAllArguments()
Get all arguments passed to the application.Set<String>
getDependentPackages()
Gets the set of dependent packages whose config needs to be loadedString
getName()
Gets the name of the applicationString[]
getPositionalArgs()
Gets the command line arguments that were not specified as part of the command line parservoid
run(String[] args)
Runs the application by first parsing the command line arguments and initializing the config.abstract void
setup()
Runs specialized code to setup the application before theRunnable.run()
command is called.
-
-
-
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 theRunnable.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.
-
-