/** * 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)); }
/** * 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; }
/** * Returns the validation message provided by the validator. * * @param locale the locale to use for message construction. * @return the validation message provided by the validator. */ @MessageParam("validationMessage") public final String getValidationMessage(final Locale locale) { return createMessage(locale); }
@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); } } }
private String createMessage(final Locale locale) { final StringBuilder buffer = new StringBuilder(); if (constraints != null && !constraints.isEmpty()) { for (final PropertyConstraint<?> constraint : constraints) { buffer.append("\n > ").append( constraint.getViolationMessage(locale, getValue())); } } return buffer.toString(); }
@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);