Search in sources :

Example 1 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project wicket by apache.

the class PropertyValidator method onComponentTag.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);
    BeanValidationContext config = BeanValidationConfiguration.get();
    Validator validator = config.getValidator();
    Property property = getProperty();
    // find any tag modifiers that apply to the constraints of the property
    // being validated
    // and allow them to modify the component tag
    Iterator<ConstraintDescriptor<?>> it = new ConstraintIterator(validator, property, getGroups());
    while (it.hasNext()) {
        ConstraintDescriptor<?> desc = it.next();
        ITagModifier modifier = config.getTagModifier(desc.getAnnotation().annotationType());
        if (modifier != null) {
            modifier.modify((FormComponent<?>) component, tag, desc.getAnnotation());
        }
    }
}
Also used : ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor) Validator(javax.validation.Validator) IValidator(org.apache.wicket.validation.IValidator)

Example 2 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyDigits.

private static void applyDigits(Property property, ConstraintDescriptor<?> descriptor) {
    if (Digits.class.equals(descriptor.getAnnotation().annotationType())) {
        @SuppressWarnings("unchecked") ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor;
        int integerDigits = digitsConstraint.getAnnotation().integer();
        int fractionalDigits = digitsConstraint.getAnnotation().fraction();
        @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator();
        if (itor.hasNext()) {
            final Selectable selectable = itor.next();
            if (Column.class.isInstance(selectable)) {
                Column col = (Column) selectable;
                col.setPrecision(integerDigits + fractionalDigits);
                col.setScale(fractionalDigits);
            }
        }
    }
}
Also used : Selectable(org.hibernate.mapping.Selectable) Column(org.hibernate.mapping.Column) Digits(javax.validation.constraints.Digits) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor)

Example 3 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.

the class TypeSafeActivator method applySize.

private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
    if (Size.class.equals(descriptor.getAnnotation().annotationType()) && String.class.equals(propertyDescriptor.getElementClass())) {
        @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
        int max = sizeConstraint.getAnnotation().max();
        @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator();
        if (itor.hasNext()) {
            final Selectable selectable = itor.next();
            Column col = (Column) selectable;
            if (max < Integer.MAX_VALUE) {
                col.setLength(max);
            }
        }
    }
}
Also used : Selectable(org.hibernate.mapping.Selectable) Column(org.hibernate.mapping.Column) Size(javax.validation.constraints.Size) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor)

Example 4 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project minijax by minijax.

the class MinijaxContainerElementTypeDescriptor method build.

public static Set<ContainerElementTypeDescriptor> build(final Class<?> elementClass, final AnnotatedParameterizedType annotatedType) {
    final Set<ContainerElementTypeDescriptor> result = new HashSet<>();
    final Class<?> containerClass = ReflectionUtils.getRawType(annotatedType);
    int argIndex = 0;
    for (final AnnotatedType typeArg : annotatedType.getAnnotatedActualTypeArguments()) {
        final Set<ConstraintDescriptor<?>> constraintDescriptors = new HashSet<>();
        for (final Annotation annotation : typeArg.getAnnotations()) {
            final MinijaxConstraintDescriptor<?> constraintDescriptor = MinijaxConstraintDescriptor.build(typeArg, annotation);
            if (constraintDescriptor != null) {
                constraintDescriptors.add(constraintDescriptor);
            }
        }
        if (!constraintDescriptors.isEmpty()) {
            result.add(new MinijaxContainerElementTypeDescriptor(elementClass, containerClass, argIndex, constraintDescriptors));
        }
        argIndex++;
    }
    return result;
}
Also used : ContainerElementTypeDescriptor(javax.validation.metadata.ContainerElementTypeDescriptor) AnnotatedType(java.lang.reflect.AnnotatedType) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 5 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project wicket by apache.

the class PropertyValidator method findNotNullConstraints.

private List<ConstraintDescriptor<?>> findNotNullConstraints(List<Class<? extends Annotation>> notNullAnnotationTypes) {
    BeanValidationContext config = BeanValidationConfiguration.get();
    Validator validator = config.getValidator();
    Property property = getProperty();
    List<ConstraintDescriptor<?>> constraints = new ArrayList<>();
    Iterator<ConstraintDescriptor<?>> it = new ConstraintIterator(validator, property);
    while (it.hasNext()) {
        ConstraintDescriptor<?> desc = it.next();
        Annotation annotation = desc.getAnnotation();
        Class<? extends Annotation> annotationType = annotation.annotationType();
        if (notNullAnnotationTypes.contains(annotationType)) {
            constraints.add(desc);
        }
    }
    return constraints;
}
Also used : ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor) ArrayList(java.util.ArrayList) Validator(javax.validation.Validator) IValidator(org.apache.wicket.validation.IValidator) Annotation(java.lang.annotation.Annotation)

Aggregations

ConstraintDescriptor (javax.validation.metadata.ConstraintDescriptor)7 Column (org.hibernate.mapping.Column)4 Selectable (org.hibernate.mapping.Selectable)4 Annotation (java.lang.annotation.Annotation)2 Validator (javax.validation.Validator)2 IValidator (org.apache.wicket.validation.IValidator)2 AnnotatedType (java.lang.reflect.AnnotatedType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Digits (javax.validation.constraints.Digits)1 Max (javax.validation.constraints.Max)1 Min (javax.validation.constraints.Min)1 Size (javax.validation.constraints.Size)1 ContainerElementTypeDescriptor (javax.validation.metadata.ContainerElementTypeDescriptor)1