public static void convertToRuntimeException(Throwable t) { GeneralConfigException.<RuntimeException>convertException(t); }
private Set<V> factorSetInstance() { try { return set.newInstance(); } catch (Exception e) { GeneralConfigException.convertToRuntimeException(e); } return null; } }
protected boolean validateAndReturnIfEmpty(String name, T value) { if (ConfigUtil.isEmpty(value)) { if (required) { throw new ValidationConfigException("Required parameter value is empty: " + name); } return true; } return false; } //------------------------------------------------------------------------------------------
private void readAndValidateParameter (Param param) { try { param.readValue(); param.validate(); } catch (GeneralConfigException ex) { throw ex; } catch (Exception ex) { throw new GeneralConfigException("Configured value for '" + param.getName() + "' is invalid!", ex); } } //==================================================================================================================
@Override public void validate(String name, String value) { if (validateAndReturnIfEmpty(name, value)) { return; } try { URL url = new URL(value); } catch (MalformedURLException e) { throw new ValidationConfigException("'" + value + "' is not a valid URL (Parameter: " + name + ")"); } } //------------------------------------------------------------------------------------------
@Override public T readValue(String name) { // invoke method to get value try { Class clazz = invoker.getClass(); Object instance = invoker; if (invoker.getClass() == Class.class) { clazz = (Class)invoker; instance = null; } return (T)clazz.getMethod(methodName, argsClass).invoke(instance, args); } catch (Throwable e) { GeneralConfigException.convertToRuntimeException(e); // throw exception as Runtime exception } return null; // should not get here }
@Override public void validate(String name, String value) { if (validateAndReturnIfEmpty(name, value)) { return; } URL url = ConfigUtil.getResource(value); if (url == null) { throw new ValidationConfigException("File '" + value + "' cannot be found (Parameter: " + name + ")"); } } //------------------------------------------------------------------------------------------
@Override public void validate(String name, String value) { if (validateAndReturnIfEmpty(name, value)) { return; } String errMsg = null; // validate the hexadecimal value if (maxValue > -1) { errMsg = validateHexValue(value, maxValue); } else { errMsg = validateHexValue(value, maxLength, lengthInBits, exactLength); } if (errMsg != null) { throw new ValidationConfigException(errMsg + " (Parameter: " + name + ")"); } } //------------------------------------------------------------------------------------------