/** Finds the constructor for an option handler. */ private static Constructor<? extends OptionHandler> getConstructor(Class<? extends OptionHandler> handlerClass) { try { return handlerClass.getConstructor(CmdLineParser.class, OptionDef.class, Setter.class); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(Messages.NO_CONSTRUCTOR_ON_HANDLER.format(handlerClass)); } }
public String format( Object... args ) { return formatWithLocale(Locale.getDefault(),args); } }
public String formatWithLocale( Locale locale, Object... args ) { ResourceBundle localized = ResourceBundle.getBundle(Messages.class.getName(), locale); return MessageFormat.format(localized.getString(name()),args); }
/** Finds the constructor for an option handler. */ private static Constructor<? extends OptionHandler> getConstructor(Class<? extends OptionHandler> handlerClass) { try { return handlerClass.getConstructor(CmdLineParser.class, OptionDef.class, Setter.class); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(Messages.NO_CONSTRUCTOR_ON_HANDLER.format(handlerClass)); } }
public String formatWithLocale( Locale locale, Object... args ) { ResourceBundle localized = ResourceBundle.getBundle(Messages.class.getName(), locale); return MessageFormat.format(localized.getString(name()),args); }
public String format( Object... args ) { return formatWithLocale(Locale.getDefault(),args); } }
/** * Registers a user-defined {@link OptionHandler} class with args4j. * * <p> * This method allows users to extend the behavior of args4j by writing * their own {@link OptionHandler} implementation. * * @param valueType * The specified handler is used when the field/method annotated by {@link Option} * is of this type. * @param handlerClass * This class must have the constructor that has the same signature as * {@link OptionHandler#OptionHandler(CmdLineParser, OptionDef, Setter)} * @throws NullPointerException if {@code valueType} or {@code handlerClass} is {@code null}. * @throws IllegalArgumentException if {@code handlerClass} is not a subtype of {@code OptionHandler}. */ public void registerHandler( Class valueType, Class<? extends OptionHandler> handlerClass ) { checkNonNull(valueType, "valueType"); checkNonNull(handlerClass, "handlerClass"); if(!OptionHandler.class.isAssignableFrom(handlerClass)) throw new IllegalArgumentException(Messages.NO_OPTIONHANDLER.format()); handlers.put(valueType, new DefaultConstructorHandlerFactory(handlerClass)); }
public String formatWithLocale( Locale locale, Object... args ) { ResourceBundle localized = ResourceBundle.getBundle(Messages.class.getName(), locale); return MessageFormat.format(localized.getString(name()),args); }
public String format( Object... args ) { return formatWithLocale(Locale.getDefault(),args); } }
private String createDefaultValuePart(OptionHandler handler) { if (parserProperties.getShowDefaults() && !handler.option.required() && handler.setter instanceof Getter) { String v = handler.printDefaultValue(); if (v!=null) return " " + Messages.DEFAULT_VALUE.format(v); } return ""; }
public String formatWithLocale( Locale locale, Object... args ) { ResourceBundle localized = ResourceBundle.getBundle(Messages.class.getName(), locale); return MessageFormat.format(localized.getString(name()),args); }
public String format( Object... args ) { return formatWithLocale(Locale.getDefault(),args); } }
/** * Registers a user-defined {@link OptionHandler} class with args4j. * * <p> * This method allows users to extend the behavior of args4j by writing * their own {@link OptionHandler} implementation. * * @param valueType * The specified handler is used when the field/method annotated by {@link Option} * is of this type. * @param handlerClass * This class must have the constructor that has the same signature as * {@link OptionHandler#OptionHandler(CmdLineParser, OptionDef, Setter)} * @throws NullPointerException if {@code valueType} or {@code handlerClass} is {@code null}. * @throws IllegalArgumentException if {@code handlerClass} is not a subtype of {@code OptionHandler}. */ public void registerHandler( Class valueType, Class<? extends OptionHandler> handlerClass ) { checkNonNull(valueType, "valueType"); checkNonNull(handlerClass, "handlerClass"); if(!OptionHandler.class.isAssignableFrom(handlerClass)) throw new IllegalArgumentException(Messages.NO_OPTIONHANDLER.format()); handlers.put(valueType, new DefaultConstructorHandlerFactory(handlerClass)); }
private void checkOptionNotInMap(String name) throws IllegalAnnotationError { checkNonNull(name, "name"); if(findOptionByName(name)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_OPTION.format(name)); } }
private void checkOptionNotInMap(String name) throws IllegalAnnotationError { checkNonNull(name, "name"); if(findOptionByName(name)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_OPTION.format(name)); } }
private String createDefaultValuePart(OptionHandler handler) { if (parserProperties.getShowDefaults() && !handler.option.required() && handler.setter instanceof Getter) { String v = handler.printDefaultValue(); if (v!=null) return " " + Messages.DEFAULT_VALUE.format(v); } return ""; }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
public void parse(InputSource xml, CmdLineParser parser, Object bean) { try { Config config = Config.parse(xml); for(ConfigElement ce : config.options) { Option option = new OptionImpl(ce); parser.addOption(Setters.create(parser, findMethodOrField(bean, ce.field, ce.method),bean), option); } for (ConfigElement ce : config.arguments) { Argument argument = new ArgumentImpl(ce); parser.addArgument(Setters.create(parser, findMethodOrField(bean, ce.field, ce.method),bean), argument); } } catch (Exception e) { throw new RuntimeException(Messages.METADATA_ERROR.format(), e); } }
public void parse(InputSource xml, CmdLineParser parser, Object bean) { try { Config config = Config.parse(xml); for(ConfigElement ce : config.options) { Option option = new OptionImpl(ce); parser.addOption(Setters.create(parser, findMethodOrField(bean, ce.field, ce.method),bean), option); } for (ConfigElement ce : config.arguments) { Argument argument = new ArgumentImpl(ce); parser.addArgument(Setters.create(parser, findMethodOrField(bean, ce.field, ce.method),bean), argument); } } catch (Exception e) { throw new RuntimeException(Messages.METADATA_ERROR.format(), e); } }