@Override public String getLocalizedMessage() { if(getCause() == null) { return getMessage(); } return getMessage() + " caused by: " + getCause().getMessage(); } }
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!"); } }
private Logger getRootLogger() throws JPServiceException { try { return (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); } catch (Exception ex) { throw new JPServiceException("RootLogger is not available!", ex); } }
private void checkScopeMaps() throws JPValidationException { if (scopeFileTransformerMap.keySet().stream().anyMatch(k -> scopeFileTransformerMap.containsKey(k))) { throw new JPValidationException("The same scope occurs multiple times in the file transformers."); } if (scopeIdMap.keySet().stream().anyMatch(k -> scopeFileTransformerMap.keySet().stream().filter(k2 -> k == k2).count() > 1)) { throw new JPValidationException("The same scope appeared in the file transformers and the registry transformers."); } if (scopeIdMap.keySet().stream().anyMatch(k -> scopeIdMap.keySet().stream().filter(k2 -> k == k2).count() > 1)) { throw new JPValidationException("The same scope appeared multiple times in the registry."); } }
/** * Returns the property related to the given {@code propertyClass}. * <p> * If the property is never registered but the class is known in the classpath, the method returns the default value. * * @param <C> the property type. * @param propertyClass property class which defines the property. * * @return the property. * * @throws org.openbase.jps.exception.JPNotAvailableException thrown if the given property could not be found. */ public static synchronized <C extends AbstractJavaProperty> C getProperty(Class<C> propertyClass) throws JPNotAvailableException { try { if (propertyClass == null) { throw new JPNotAvailableException(propertyClass, new JPServiceException("Given propertyClass is a Nullpointer!")); } // load if not already done. if (!loadedProperties.containsKey(propertyClass) || loadedProperties.get(propertyClass).neetToBeParsed()) { // init if not already done. if (!initializedProperties.containsKey(propertyClass)) { initProperty(propertyClass); } loadProperty(initializedProperties.get(propertyClass)); } return (C) loadedProperties.get(propertyClass); } catch (JPServiceException ex) { throw new JPNotAvailableException(propertyClass, ex); } }
protected final void parseArguments() throws JPParsingException { try { valueType = ValueType.CommandLine; parsedValue = parse(Collections.unmodifiableList(arguments)); } catch (Exception ex) { logger.error("Could not parse argument[" + identifier + "]!"); logger.info("The valid syntax would be: " + getSyntax() + "\n"); throw new JPParsingException("Could not parse argument[" + identifier + "]!", ex); } parsed = true; }
/** * {@inheritDoc} * * @throws JPValidationException {@inheritDoc} */ @Override protected void validate() throws JPValidationException { super.validate(); for (String s : getValue()) { if (!s.matches(FULL_REGEX)) { throw new JPValidationException("Every argument has to be a unit id and thus match \"" + FULL_REGEX + "\""); } } } }
public static void printError(String message, Throwable cause) { printError(new JPServiceException(message, cause)); }
protected final void checkArgumentCountMax(int max) throws JPBadArgumentException { if (arguments.size() > max) { throw new JPBadArgumentException("To many property arguments!"); } }
/** * {@inheritDoc} * * @throws JPValidationException {@inheritDoc} */ @Override protected void validate() throws JPValidationException { super.validate(); for (String s : getValue()) { if (!s.matches(FULL_REGEX)) { throw new JPValidationException("Every argument has to be a unit id and thus match \"" + FULL_REGEX + "\""); } } } }
/** * Setup JPService for JUnitTests By using the JPService during JUnit Tests it's recommended to call this method after property registration instead using the parsing methods because command line * property handling makes no sense in the context of unit tests.. * <p> * The following properties are activated by default while running JPService in TestMode: * <p> * - JPVerbose is set to true to print more debug messages. * <p> * - JPTestMode is activated. * * @throws JPServiceException */ public static void setupJUnitTestMode() throws JPServiceException { try { registerProperty(JPVerbose.class, true); registerProperty(JPTestMode.class, true); initRegisteredProperties(); } catch (JPValidationException ex) { throw new JPServiceException("Could not setup JPService for UnitTestMode!", ex); } }
protected final void checkArgumentCountMin(int min) throws JPBadArgumentException { if (arguments.size() < min) { throw new JPBadArgumentException("Missing property arguments!"); } }
/** * {@inheritDoc} * * @throws JPValidationException {@inheritDoc} */ @Override public void validate() throws JPValidationException { try { for (File f : getValue().values()) { FileHandler.handle(f, FileType.File, EXISTENCE_HANDLING, AUTO_CREATE_MODE); } } catch (Exception ex) { throw new JPValidationException("There was an invalid file in " + getValue() + "!", ex); } } }
/** * Analyze the input arguments and setup all registered Properties. * <p> * Make sure all desired properties are registered before calling this method. Otherwise the properties will not be listed in the help screen. * * @param args Arguments given by the main method. * * @throws JPServiceException */ public static void parse(final String[] args) throws JPServiceException { argumentsAnalyzed = true; try { printValueModification(args); initRegisteredProperties(args); } catch (Exception ex) { throw new JPServiceException("Could not analyse arguments: " + ex.getMessage(), ex); } handleHelpCall(); }
/** * {@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 public void validate() throws JPValidationException { super.validate(); // during tests the registry generation is skipped because the mock registry is handling the db initialization. if (!JPService.testMode()) { try { BCORegistryLoader.prepareRegistry(getValue()); } catch (CouldNotPerformException ex) { throw new JPValidationException(ex); } } }
@Override public File getParentDirectory() throws JPServiceException { if (JPService.getProperty(JPBCOVarDirectory.class).getValue().exists() || JPService.testMode()) { return JPService.getProperty(JPBCOVarDirectory.class).getValue(); } throw new JPServiceException("Could not auto detect bco var path!"); }
@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); } } }