44 * |
44 * |
45 * @author Ing. František Kučera (frantovo.cz) |
45 * @author Ing. František Kučera (frantovo.cz) |
46 */ |
46 */ |
47 public class CLIStarter implements ConfigurationProvider { |
47 public class CLIStarter implements ConfigurationProvider { |
48 |
48 |
|
49 public static final int EXIT_SUCCESS = 0; // doc:success |
|
50 public static final int EXIT_UNEXPECTED_ERROR = 1; // doc:unexpected error (probably bug) |
|
51 public static final int EXIT_SQL_ERROR = 3; // doc:SQL error |
|
52 public static final int EXIT_CLI_PARSE_ERROR = 4; // doc:CLI options parse error |
|
53 public static final int EXIT_CLI_VALIDATE_ERROR = 5; // doc:CLI options validation error |
|
54 public static final int EXIT_CONFIGURATION_ERROR = 6; // doc:configuration error |
|
55 public static final int EXIT_FORMATTING_ERROR = 7; // doc:formatting error |
49 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
56 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
50 private static final int EXIT_SUCCESS = 0; |
|
51 private static final int EXIT_EXPECTED_ERROR = 3; |
|
52 private static final int EXIT_SQL_ERROR = 4; |
|
53 private CLIOptions options; |
57 private CLIOptions options; |
54 private Configuration configuration; |
58 private Configuration configuration; |
55 |
59 |
56 public static void main(String[] args) { |
60 public static void main(String[] args) { |
57 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
61 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
58 int exitCode = EXIT_EXPECTED_ERROR; |
62 int exitCode; |
59 |
63 |
60 if (args.length == 0) { |
64 if (args.length == 0) { |
61 args = new String[]{CLIParser.Tokens.INFO_HELP}; |
65 args = new String[]{CLIParser.Tokens.INFO_HELP}; |
62 } |
66 } |
63 |
67 |
70 starter.process(); |
74 starter.process(); |
71 log.log(Level.FINE, "All done"); |
75 log.log(Level.FINE, "All done"); |
72 exitCode = EXIT_SUCCESS; |
76 exitCode = EXIT_SUCCESS; |
73 } catch (CLIParserException e) { |
77 } catch (CLIParserException e) { |
74 log.log(Level.SEVERE, "Unable to parse CLI options", e); |
78 log.log(Level.SEVERE, "Unable to parse CLI options", e); |
|
79 exitCode = EXIT_CLI_PARSE_ERROR; |
75 } catch (InvalidOptionsException e) { |
80 } catch (InvalidOptionsException e) { |
76 log.log(Level.SEVERE, "Invalid CLI options", e); |
81 log.log(Level.SEVERE, "Invalid CLI options", e); |
77 for (InvalidOptionsException.OptionProblem p : e.getProblems()) { |
82 for (InvalidOptionsException.OptionProblem p : e.getProblems()) { |
78 LogRecord r = new LogRecord(Level.SEVERE, "Option problem: {0}"); |
83 LogRecord r = new LogRecord(Level.SEVERE, "Option problem: {0}"); |
79 r.setThrown(p.getException()); |
84 r.setThrown(p.getException()); |
80 r.setParameters(new Object[]{p.getDescription()}); |
85 r.setParameters(new Object[]{p.getDescription()}); |
81 log.log(r); |
86 log.log(r); |
82 } |
87 } |
|
88 exitCode = EXIT_CLI_VALIDATE_ERROR; |
83 } catch (ConfigurationException e) { |
89 } catch (ConfigurationException e) { |
84 log.log(Level.SEVERE, "Configuration problem", e); |
90 log.log(Level.SEVERE, "Configuration problem", e); |
|
91 exitCode = EXIT_CONFIGURATION_ERROR; |
85 } catch (SQLException e) { |
92 } catch (SQLException e) { |
86 log.log(Level.SEVERE, "SQL problem", e); |
93 log.log(Level.SEVERE, "SQL problem", e); |
87 exitCode = EXIT_SQL_ERROR; |
94 exitCode = EXIT_SQL_ERROR; |
88 } catch (FormatterException e) { |
95 } catch (FormatterException e) { |
89 log.log(Level.SEVERE, "Formatting problem", e); |
96 log.log(Level.SEVERE, "Formatting problem", e); |
|
97 exitCode = EXIT_FORMATTING_ERROR; |
90 } |
98 } |
91 |
99 |
92 System.exit(exitCode); |
100 System.exit(exitCode); |
93 } |
101 } |
94 |
102 |