/** * Validate a single property only. Performs all validations * for this property. */ public static <VL extends ValidationListener> void validateProperty(ValidationContext<VL> context) { for (Validation validation : context.getMetaProperty().getValidations()) { validation.validate(context); } } }
protected <T extends ValidationListener> void validateMinLength(ValidationContext<T> context) { Integer maxLength = (Integer) context.getMetaProperty().getFeature(Features.Property.MIN_LENGTH); if (maxLength == null) return; if (context.getPropertyValue() == null) return; final Object value = context.getPropertyValue(); int length = 0; if (value instanceof String) { length = ((String) value).length(); } else if (value instanceof Collection<?>) { length = ((Collection<?>) value).size(); } if (length < maxLength) { context.getListener().addError(MIN_LENGTH, context); } }
protected <T extends ValidationListener> void validateTimeLag(ValidationContext<T> context) { String lag = (String) context.getMetaProperty().getFeature(TIME_LAG); if (lag == null) return; if (context.getPropertyValue() == null) return; long date = ((Date) context.getPropertyValue()).getTime(); long now = System.currentTimeMillis(); if (XMLMetaValue.TIMELAG_Future.equals(lag)) { if (date < now) { context.getListener().addError(TIME_LAG, context); } } else if (XMLMetaValue.TIMELAG_Past.equals(lag)) { if (date > now) { context.getListener().addError(TIME_LAG, context); } } else { throw new IllegalArgumentException("unknown timelag " + lag + " at " + context); } }
protected <T extends ValidationListener> void validateMaxLength(ValidationContext<T> context) { Integer maxLength = (Integer) context.getMetaProperty().getFeature(Features.Property.MAX_LENGTH); if (maxLength == null) return; if (context.getPropertyValue() == null) return; final Object value = context.getPropertyValue(); int length = 0; if (value instanceof String) { length = ((String) value).length(); } else if (value instanceof Collection<?>) { length = ((Collection<?>) value).size(); } if (length > maxLength) { context.getListener().addError(MAX_LENGTH, context); } }
protected <T extends ValidationListener> void validateRegExp(ValidationContext<T> context) { final MetaProperty meta = context.getMetaProperty(); final String regExp = (String) meta.getFeature(REG_EXP); if (regExp == null) return; if (context.getPropertyValue() == null) return; final String value = String.valueOf(context.getPropertyValue()); try { Pattern pattern = (Pattern) meta.getFeature(REG_EXP_PATTERN); if (pattern == null) { pattern = Pattern.compile(regExp); meta.putFeature(REG_EXP_PATTERN, pattern); } if (!pattern.matcher(value).matches()) { context.getListener().addError(REG_EXP, context); } } catch (PatternSyntaxException e) { throw new IllegalArgumentException("regular expression malformed. regexp " + regExp + " at " + context, e); } }
protected <T extends ValidationListener> void validateMandatory(ValidationContext<T> context) { if (context.getMetaProperty().isMandatory()) { if (context.getPropertyValue() == null) { context.getListener().addError(MANDATORY, context); } } }
protected <T extends ValidationListener> void validateMaxValue(ValidationContext<T> context) { @SuppressWarnings("unchecked") Comparable<Object> maxValue = (Comparable<Object>) context.getMetaProperty().getFeature(MAX_VALUE); if (maxValue == null || context.getPropertyValue() == null) return; if (compare(context, maxValue, context.getPropertyValue()) < 0) { context.getListener().addError(MAX_VALUE, context); } }
protected <T extends ValidationListener> void validateMinValue(ValidationContext<T> context) { @SuppressWarnings("unchecked") Comparable<Object> minValue = (Comparable<Object>) context.getMetaProperty().getFeature(MIN_VALUE); if (minValue == null || context.getPropertyValue() == null) return; if (compare(context, minValue, context.getPropertyValue()) > 0) { context.getListener().addError(MIN_VALUE, context); } }
/** * {@inheritDoc} */ @Override protected void complete() { super.complete(); if (validationContext.getMetaProperty() != null) { return; } if (validationContext.getMetaBean() instanceof DynamicMetaBean) { validationContext.setMetaBean(validationContext.getMetaBean().resolveMetaBean( ObjectUtils.defaultIfNull(validationContext.getBean(), rawType))); } } }
/** * If we currently have a property, navigate the context such that the property becomes the bean, in preparation for * another property. * * @param validationContext */ public void moveDownIfNecessary() { MetaProperty mp = validationContext.getMetaProperty(); if (mp != null) { if (mp.getMetaBean() == null) { throw new UnknownPropertyException(String.format("Property %s.%s is not cascaded", mp .getParentMetaBean().getId(), mp.getName())); } validationContext.moveDown(mp, new NullSafePropertyAccess(validationContext.getMetaBean().getBeanClass(), mp.getName())); } }
if (propPath == null) propPath = gcontext.getPropertyPath(); } else { if (context.getMetaProperty() == null) value = context.getBean(); else value = context.getPropertyValue(); message = messageTemplate;