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());
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations