protected final void checkArgumentCount(int min, int max) throws JPBadArgumentException { int size = arguments.size(); if (size < min) { throw new JPBadArgumentException("Missing property arguments!"); } else if (size > max) { throw new JPBadArgumentException("To many property arguments!"); } }
@Override public String getLocalizedMessage() { if(getCause() == null) { return getMessage(); } return getMessage() + " caused by: " + getCause().getMessage(); } }
protected final void checkArgumentCountMax(int max) throws JPBadArgumentException { if (arguments.size() > max) { throw new JPBadArgumentException("To many property arguments!"); } }
protected final void checkArgumentCountMin(int min) throws JPBadArgumentException { if (arguments.size() < min) { throw new JPBadArgumentException("Missing property arguments!"); } }
@Override protected Class<C> parse(List<String> arguments) throws JPBadArgumentException { String oneArgumentResult = getOneArgumentResult(); Class clazz; try { clazz = getClass().getClassLoader().loadClass(oneArgumentResult); } catch (ClassNotFoundException ex) { throw new JPBadArgumentException("Could not load given Class!", ex); } try { return (Class<C>) clazz; } catch (ClassCastException ex) { throw new JPBadArgumentException("Given Class["+clazz.getName()+"] is not a instance of Class["+detectTypeClass().getName()+"]!", ex); } }
/** * {@inheritDoc} * * @param arguments {@inheritDoc} * @return {@inheritDoc} * @throws JPBadArgumentException {@inheritDoc} */ @Override protected Double parse(List<String> arguments) throws JPBadArgumentException { Double d = super.parse(arguments); if (d > 1.0 || d < 0.0) { throw new JPBadArgumentException("Threshold has to be between 0.0 and 1.0!"); } return d; } }
@Override protected Method parse(List<String> arguments) throws JPBadArgumentException { String oneArgumentResult = getOneArgumentResult(); try { Class<C> relatedClass = JPService.getProperty(jpClass).getValue(); for (Method method : relatedClass.getMethods()) { if (method.getName().equalsIgnoreCase(oneArgumentResult)) { return method; } } throw new JPBadArgumentException("Class["+relatedClass.getClass().getName()+"] does not provide Method["+oneArgumentResult+"]!"); } catch (JPNotAvailableException | SecurityException | JPBadArgumentException ex) { throw new JPBadArgumentException("Could not load given Method["+oneArgumentResult+"]!", ex); } } }
@Override protected Locale parse(List<String> arguments) throws JPBadArgumentException { String oneArgumentResult = getOneArgumentResult(); try { final Locale locale = parseLocale(oneArgumentResult); if (!isValid(locale)) { throw new JPBadArgumentException("Given Language is unknown!"); } return locale; } catch (NullPointerException ex) { throw new JPBadArgumentException("Could not load language!", ex); } }
/** * @param property * * @throws JPBadArgumentException */ private static void parseProperty(final AbstractJavaProperty property) throws JPBadArgumentException { if (property.neetToBeParsed()) { try { property.parseArguments(); } catch (Exception ex) { throw new JPBadArgumentException("Could not parse " + property + "!", ex); } } }
/** * {@inheritDoc} * * @param arguments {@inheritDoc} * @return {@inheritDoc} * @throws JPBadArgumentException {@inheritDoc} */ @Override protected Scope parse(List<String> arguments) throws JPBadArgumentException { String oneArgumentResult = getOneArgumentResult(); try { return new Scope(oneArgumentResult); } catch (IllegalArgumentException ex) { throw new JPBadArgumentException("Given Scope[" + oneArgumentResult + "] is not a Scope.", ex); } } }