/** * Creates an instance of the validation exception. * * @param propertyDescriptor the descriptor of the property raising the * exception. * @param constraints the property constraints that failed to be met. * @param value the value of the property that does not meet the constraints. * If the value is not serializable, its string representation is * stored. * @return the created exception instance. */ public static final PropertyValidationException invalid( final PropertyDescriptor propertyDescriptor, final List<? extends PropertyConstraint<?>> constraints, final Object value) { return new PropertyValidationException(new PropertyValidationMessageBean( propertyDescriptor, constraints, value)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void groupValidation(final PropertyDescriptor descriptor, final Object value, final Class<?>[] groups) { final List<PropertyConstraint<?>> constraints = new ArrayList<PropertyConstraint<?>>(); for (final Class<?> group : groups) { for (final PropertyConstraint constraint : descriptor.getConstraints()) { try { constraint.validate(descriptor, value, group); } catch (final PropertyValidationException e) { final List<? extends PropertyConstraint<?>> eConstraints = e.getMessageBean().getConstraints(); constraints.addAll(eConstraints); } } // After each group check if we have to got to the next ... if (!constraints.isEmpty()) { throw PropertyValidationException.invalid(descriptor, constraints, value); } } }
/** * Default constructor. * * @param original the original property validation exception without the * origin information. * @param source the source where the property value has been defined. */ public PropertyValidationWithSourceMessageBean( final PropertyValidationException original, final PropertyLocation source) { super(ConfigurationCode.INVALID_CONFIGURATION_WITH_SOURCE, original, original.getMessageBean().getPropertyDescriptor(), original .getMessageBean().getConstraints(), original.getMessageBean() .getValue()); this.source = source; }
@Override public final void validate(final PropertyDescriptor propertyDescriptor, final T value, final Class<?> group) throws PropertyValidationException { final boolean valid = isValid(value, group); if (!valid) { throw PropertyValidationException.invalid(propertyDescriptor, Collections.singletonList(this), value); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void defaultValidation(final PropertyDescriptor descriptor, final Object value) { final List<PropertyConstraint<?>> constraints = new ArrayList<PropertyConstraint<?>>(); for (final PropertyConstraint constraint : descriptor.getConstraints()) { try { if (!(adminMode && constraint.isMandatoryConstraint())) { constraint.validate(descriptor, value); } } catch (final PropertyValidationException e) { final List<? extends PropertyConstraint<?>> eConstraints = e.getMessageBean().getConstraints(); constraints.addAll(eConstraints); } } if (!constraints.isEmpty()) { throw PropertyValidationException.invalid(descriptor, constraints, value); } }
new PropertyValidationMessageBean(descriptor, descriptor.getConstraints(), plainValue); throw new PropertyValidationException(message);
new PropertyValidationMessageBean(descriptor, descriptor.getConstraints(), plainValue); throw new PropertyValidationException(message);