[1] | 1 | package de.ugoe.cs.eventbench;
|
---|
| 2 |
|
---|
[247] | 3 | import java.io.IOException;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import joptsimple.OptionException;
|
---|
| 7 | import joptsimple.OptionParser;
|
---|
| 8 | import joptsimple.OptionSet;
|
---|
| 9 | import joptsimple.OptionSpec;
|
---|
[207] | 10 | import de.ugoe.cs.eventbench.log4j.Log4JLogger;
|
---|
[188] | 11 | import de.ugoe.cs.eventbench.swt.MainWindow;
|
---|
[1] | 12 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
[171] | 13 | import de.ugoe.cs.util.console.Console;
|
---|
[1] | 14 | import de.ugoe.cs.util.console.TextConsole;
|
---|
| 15 |
|
---|
[171] | 16 | /**
|
---|
| 17 | * <p>
|
---|
| 18 | * Start-up class of the application.
|
---|
| 19 | * </p>
|
---|
| 20 | * <p>
|
---|
| 21 | * It sets up and starts the {@link Console}.
|
---|
| 22 | * </p>
|
---|
| 23 | *
|
---|
| 24 | * @author Steffen Herbold
|
---|
| 25 | * @version 1.0
|
---|
| 26 | */
|
---|
[1] | 27 | public class Runner {
|
---|
| 28 |
|
---|
[247] | 29 | public enum UITYPE {
|
---|
| 30 | text, swt
|
---|
| 31 | };
|
---|
[396] | 32 |
|
---|
| 33 | public enum LOG4JTYPE {
|
---|
| 34 | enable, disable
|
---|
| 35 | }
|
---|
[247] | 36 |
|
---|
[1] | 37 | /**
|
---|
[171] | 38 | * <p>
|
---|
| 39 | * Main method of the application.
|
---|
| 40 | * </p>
|
---|
| 41 | *
|
---|
[1] | 42 | * @param args
|
---|
[171] | 43 | * if parameters are defined, they are interpreted as commands
|
---|
| 44 | * for the {@link Console} and executed before the user can use
|
---|
| 45 | * the console; can be used to perform batch operations
|
---|
[1] | 46 | */
|
---|
| 47 | public static void main(String[] args) {
|
---|
[171] | 48 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 49 | "de.ugoe.cs.eventbench.commands");
|
---|
| 50 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 51 | "de.ugoe.cs.eventbench.windows.commands");
|
---|
| 52 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 53 | "de.ugoe.cs.eventbench.web.commands");
|
---|
[196] | 54 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 55 | "de.ugoe.cs.eventbench.efg.commands");
|
---|
[299] | 56 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 57 | "de.ugoe.cs.eventbench.jfc.commands");
|
---|
[396] | 58 | //new Log4JLogger();
|
---|
[247] | 59 |
|
---|
| 60 | OptionParser parser = new OptionParser();
|
---|
[396] | 61 | OptionSpec<LOG4JTYPE> log4j = parser.accepts("log4j", "Allowed values: enable, disable").withRequiredArg()
|
---|
| 62 | .ofType(LOG4JTYPE.class).defaultsTo(LOG4JTYPE.enable);
|
---|
[247] | 63 | OptionSpec<UITYPE> ui = parser.accepts("ui", "Allowed values: text, swt").withRequiredArg()
|
---|
| 64 | .ofType(UITYPE.class).defaultsTo(UITYPE.text);
|
---|
| 65 | OptionSet options = parser.parse(args);
|
---|
| 66 |
|
---|
| 67 | List<String> startupCommands = options.nonOptionArguments();
|
---|
| 68 | try {
|
---|
[396] | 69 | switch (options.valueOf(log4j)) {
|
---|
| 70 | case enable:
|
---|
| 71 | new Log4JLogger();
|
---|
| 72 | break;
|
---|
| 73 | case disable:
|
---|
| 74 | // do nothing
|
---|
| 75 | break;
|
---|
| 76 | default:
|
---|
| 77 | throw new AssertionError("reached source code that should be unreachable impossible");
|
---|
[112] | 78 | }
|
---|
[396] | 79 |
|
---|
| 80 | switch (options.valueOf(ui)) {
|
---|
| 81 | case text:
|
---|
| 82 | TextConsole textConsole = new TextConsole();
|
---|
| 83 | for (String command : startupCommands) {
|
---|
| 84 | CommandExecuter.getInstance().exec(command);
|
---|
| 85 | }
|
---|
| 86 | textConsole.run(true);
|
---|
| 87 | break;
|
---|
| 88 | case swt:
|
---|
| 89 | MainWindow mainWindow = new MainWindow(startupCommands);
|
---|
| 90 | mainWindow.open();
|
---|
| 91 | break;
|
---|
| 92 | default:
|
---|
| 93 | throw new AssertionError("reached source code that should be unreachable impossible");
|
---|
| 94 | }
|
---|
[247] | 95 | } catch (OptionException e) {
|
---|
| 96 | System.err.println("Invalid Parameters: " + e.getMessage());
|
---|
| 97 | try {
|
---|
| 98 | parser.printHelpOn(System.out);
|
---|
| 99 | } catch (IOException e1) {
|
---|
| 100 | // ignore exception.
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
[1] | 103 | }
|
---|
| 104 |
|
---|
| 105 | }
|
---|