/** * Checks if the long or short form is part of the command line options. * * @param shortForm * @param longForm * @return */ protected boolean hasOption(String shortForm, String longForm) { return getCommandLine().hasOption(shortForm) || getCommandLine().hasOption(longForm); }
/** * Converts command line arguments into integer action values. This makes writing switch * statements for choosing actions very easy. Pass in the short and long options, the * action that should be assigned and the command line. If the command option is present, * the action will be set. * <p/> * <p>The only supplied default is {@link #NO_ACTION} </p> * * @param flag * @param longFlag * @param action */ protected void checkAction(String flag, String longFlag, int action) { if (getCommandLine().hasOption(flag) || getCommandLine().hasOption(longFlag)) { if (getAction() != NO_ACTION) { throw new RuntimeException("Error: attempted to reset the action"); } setAction(action); } }
/** * Sets up the configuration and runtime environment. This is called typically in the constructors before anything * else is called. Always call super on this method if you override it! At the end of this method, the configuration * node has been found and set for you to call in your {@link #getLoader()} method. */ public void initialize() throws Exception { // do not put logging messages (e.g. info) in this method since the actual // logger can't be loaded until the configuration file is found. All logging // messages before it is loaded will end up in the default log file, not // where the user wants them. if (getConfigFile() == null) { throw new MyConfigurationException("Error: no configuration file"); } if (getConfigFile().length() == 0) { throw new MyConfigurationException("Error:No configuration found."); } String cfgName = null; if (hasOption(CONFIG_NAME_OPTION, CONFIG_NAME_LONG_OPTION)) { cfgName = getCommandLine().getOptionValue(CONFIG_NAME_OPTION); } setConfigurationNode(ConfigUtil.findConfiguration(getConfigFile(), cfgName, getComponentName())); }
setLogfileName(getCommandLine().getOptionValue(LOG_FILE_LONG_OPTION)); setConfigFile(getCommandLine().getOptionValue(CONFIG_FILE_OPTION));