public ArgumentParserException(String message, Throwable cause, ArgumentParser parser, Argument arg) { super(formatMessage(message, arg, parser.getConfig()), cause); parser_ = parser; }
public ArgumentParserException(String message, Throwable cause, ArgumentParser parser, Argument arg) { super(formatMessage(message, arg, parser.getConfig()), cause); parser_ = parser; }
public ArgumentParserException(String message, ArgumentParser parser, Argument arg) { super(formatMessage(message, arg, parser.getConfig())); parser_ = parser; }
public ArgumentParserException(String message, ArgumentParser parser, Argument arg) { super(formatMessage(message, arg, parser.getConfig())); parser_ = parser; }
private static String localizeTypeName(ArgumentParser parser, Class<?> type) { try { ResourceBundle typeBundle = ResourceBundle.getBundle( type.getName().replace('.', '/') + "-argparse4j"); return typeBundle.getString("displayName"); } catch (MissingResourceException e) { String simpleTypeName = type.getSimpleName(); return MessageLocalization.localize( parser.getConfig().getResourceBundle(), "type." + simpleTypeName, simpleTypeName); } } }
private static String localizeTypeName(ArgumentParser parser, Class<?> type) { try { ResourceBundle typeBundle = ResourceBundle.getBundle( type.getName().replace('.', '/') + "-argparse4j"); return typeBundle.getString("displayName"); } catch (MissingResourceException e) { String simpleTypeName = type.getSimpleName(); return MessageLocalization.localize( parser.getConfig().getResourceBundle(), "type." + simpleTypeName, simpleTypeName); } } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { for (T t : type_.getEnumConstants()) { if (t.toString().equals(value)) { return t; } } String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), parser, arg); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { for (T t : type_.getEnumConstants()) { if (t.toString().equals(value)) { return t; } } String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), parser, arg); }
private void throwException(ArgumentParser parser, Argument arg, File file, String messageKey) throws ArgumentParserException { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), messageKey), file), parser, arg); }
private void throwException(ArgumentParser parser, Argument arg, File file, String messageKey) throws ArgumentParserException { throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization .localize(parser.getConfig().getResourceBundle(), messageKey), file), parser, arg); }
@Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); }
@Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); }
@Override public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { Path path; try { path = new Path(value); } catch (IllegalArgumentException e) { String localizedTypeName = HadoopExtensionResourceBundle .get(parser.getConfig().getLocale()).getString("path"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization .localize(parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } return path; } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } }
private void throwArgumentParserException(ArgumentParser parser, Argument arg, String value, Throwable t) throws ArgumentParserException { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), t, parser, arg); }
private void throwArgumentParserException(ArgumentParser parser, Argument arg, String value, Throwable t) throws ArgumentParserException { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), t, parser, arg); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { String valueForComparison = toCaseInsensitiveForm(value); for (T t : type_.getEnumConstants()) { // Not using "equalsIgnoreCase(String)" as this will cause tests // "testIgnoresLocaleOfParserForCaseInsensitivity" of the subclasses // to fail. if (toCaseInsensitiveForm(toStringRepresentation(t)) .equals(valueForComparison)) { return t; } } String choices = TextHelper.concat(getStringRepresentations(), 0, ",", "{", "}"); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), parser, arg); }