1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.commoncli.option.argument.impl.log;
26
27 import static java.util.logging.Level.parse;
28 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
29 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
30 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.EMPTY_OPTION_ARGUMENT_ERROR;
31 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.NOT_LOG_LEVEL_ARGUMENT_ERROR;
32
33 import java.util.logging.Level;
34
35 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
36 import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
37
38
39
40
41
42
43
44
45
46
47 public class LevelOptionArgumentImpl extends AbstractOptionArgument < Level > {
48
49
50 private static final long serialVersionUID = -456175880858276198L;
51
52
53 private static final String MAIN_USAGE = "VERBOSE_LEVEL";
54
55
56 private static final String USAGE_DESCRIPTION = MAIN_USAGE
57 + " specifies the verbose level. The argument may consist of either a level name or an integer value. Classical values are : \"SEVERE\":1000, \"WARNING\":900, \"INFO\":800, \"CONFIG\":700, \"FINE\":500, \"FINER\":400, \"FINEST\":300. By default, if the verbose option is specified but the level is not set, the value \"INFO\":800 is taken. If not specified, the default value is \"WARNING\":900.";
58
59
60
61
62
63
64
65
66 public LevelOptionArgumentImpl(final boolean optionArgumentIsMandatory) {
67 super(optionArgumentIsMandatory, new StringBuilder(USAGE_DESCRIPTION));
68 }
69
70
71
72
73
74
75 @Override
76 protected String getMainUsageDescription() {
77 return MAIN_USAGE;
78 }
79
80
81
82
83
84
85 @Override
86 public Level parseArgument(final String argument) throws CommandLineException {
87 Level level = null;
88
89 if (isNotEmpty(argument)) {
90 try {
91 level = parse(argument);
92 } catch (final IllegalArgumentException e) {
93 throw new CommandLineException(buildLogString(NOT_LOG_LEVEL_ARGUMENT_ERROR, argument), e);
94 }
95 } else {
96 throw new CommandLineException(EMPTY_OPTION_ARGUMENT_ERROR);
97 }
98
99 return level;
100 }
101 }