Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


            if (valueExpression != null) {
                ValueExpressionAnalyzer valueExpressionAnalyzer = new ValueExpressionAnalyzer(valueExpression);
                ValueReference vref = valueExpressionAnalyzer.getValueReference(context.getELContext());
                if (vref != null) { // valueExpressionAnalyzer can return a null value. The condition prevents a NPE
                    BeanDescriptor constraintsForClass = validator.getConstraintsForClass(vref.getBase().getClass());
                    PropertyDescriptor d = constraintsForClass.getConstraintsForProperty((String) vref.getProperty());
                    return (d != null) && d.hasConstraints();
                }
            }
            return false;
        }
View Full Code Here


        Assert.assertTrue(
              bookBeanDescriptor.getConstraintsForProperty("doesNotExist") == null);
        //property with no constraint
        Assert.assertTrue(
              bookBeanDescriptor.getConstraintsForProperty("description") == null);
        PropertyDescriptor propertyDescriptor =
              bookBeanDescriptor.getConstraintsForProperty("title");
        Assert.assertEquals(2, propertyDescriptor.getConstraintDescriptors().size());
        Assert.assertTrue("title".equals(propertyDescriptor.getPropertyName()));
        //assuming the implementation returns the NotEmpty constraint first
        Iterator<ConstraintDescriptor<?>> iter =
              propertyDescriptor.getConstraintDescriptors().iterator();
        ConstraintDescriptor constraintDescriptor = null;
        while (iter.hasNext()) {
            constraintDescriptor = iter.next();
            if (constraintDescriptor.getAnnotation().annotationType()
                  .equals(NotNull.class)) {
                break;
            }

        }
        Assert.assertTrue(constraintDescriptor != null);
        Assert.assertTrue(constraintDescriptor.getGroups().size() == 1); //"first"
        Assert.assertEquals(NotNullValidator.class,
              constraintDescriptor.getConstraintValidatorClasses().get(0));
        //assuming the implementation returns the Size constraint first
        propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("subtitle");
        Iterator<ConstraintDescriptor<?>> iterator =
              propertyDescriptor.getConstraintDescriptors().iterator();
        constraintDescriptor = iterator.next();
        Assert.assertTrue(
              constraintDescriptor.getAnnotation().annotationType().equals(Size.class));
        Assert.assertTrue(
              ((Integer) constraintDescriptor.getAttributes().get("max")) == 30);
        Assert.assertTrue(constraintDescriptor.getGroups().size() == 1);
        propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("author");
        Assert.assertTrue(propertyDescriptor.getConstraintDescriptors().size() == 1);
        Assert.assertTrue(propertyDescriptor.isCascaded());
    }
View Full Code Here

        Validator validator = getValidator();
       
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Person.class );
        Assert.assertEquals("Incorrect class returned", Person.class, beanDescriptor.getElementClass());
       
        PropertyDescriptor nameDescriptor = beanDescriptor.getConstraintsForProperty("name");
        Assert.assertEquals("Incorrect class returned", String.class, nameDescriptor.getElementClass());
    }
View Full Code Here

     * {@link ConstraintFinder#lookingAt(javax.validation.metadata.Scope)}.
     */
    public void testConstraintFinderLookingAt() {
        Validator validator = getValidator();
       
        PropertyDescriptor nameDescriptor = validator.getConstraintsForClass( Woman.class ).getConstraintsForProperty("name");
        Set<ConstraintDescriptor<?>> constraints = nameDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
        Assert.assertEquals("Incorrect number of descriptors", 1, constraints.size());
       
        constraints = nameDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
        Assert.assertEquals("Incorrect number of descriptors", 0, constraints.size());
        TestUtils.failOnModifiable(constraints, "constraintFinder constraintDescriptors");
        //verify that changes to one ConstraintFinder don't affect the base:
        constraints = nameDescriptor.getConstraintDescriptors();
        Assert.assertEquals("Incorrect number of descriptors", 1, constraints.size());
    }
View Full Code Here

        return validatorFactory.getValidator(context);
    }

    Collection<ValidatorDescriptor> processBeanAttribute(FacesContext context, ValueDescriptor descriptor, String msg,
        Class<?>... groups) {
        PropertyDescriptor constraintsForProperty = getValidator(context).getConstraintsForClass(descriptor.getBeanType())
            .getConstraintsForProperty(descriptor.getName());
        if (null != constraintsForProperty) {
            ConstraintFinder propertyConstraints = constraintsForProperty.findConstraints();
            if (null != groups && groups.length > 0) {
                // Filter groups, if required
                propertyConstraints = propertyConstraints.unorderedAndMatchingGroups(groups);
            }
            Set<ConstraintDescriptor<?>> constraints = propertyConstraints // or the requested list of groups)
View Full Code Here

  public ConstraintIterator(Validator validator, Property property, Class<?>... groups)
  {
    BeanDescriptor beanDesc = validator.getConstraintsForClass(property.getOwner());
    if (beanDesc != null)
    {
      PropertyDescriptor propDesc = beanDesc.getConstraintsForProperty(property.getName());
      if (propDesc != null)
      {
        // TODO use hasConstraintDesc to optimize...?
        Set<ConstraintDescriptor<?>> constraints = propDesc.findConstraints()
          .unorderedAndMatchingGroups(groups)
          .getConstraintDescriptors();
        if (constraints != null)
        {
          stack.add(constraints.iterator());
View Full Code Here

        final String currentProperty = beanValidationContext.getCurrentProperty();

        if (currentProperty == null) return;
       
        final ValidationInfo validationInfo = getValidationInfo(beanValidationContext, currentProperty, validator);
        final PropertyDescriptor propertyDescriptor = validationInfo.getPropertyDescriptor();

        if (propertyDescriptor == null) return;

        for (final ConstraintDescriptor<?> descriptor : propertyDescriptor.getConstraintDescriptors())
        {
            Class<? extends Annotation> annotationType = descriptor.getAnnotation().annotationType();

            ClientConstraintDescriptor clientConstraintDescriptor = clientValidatorSource.getConstraintDescriptor(annotationType);
View Full Code Here

        String currentProperty = beanValidationContext.getCurrentProperty();

        if (currentProperty == null) return;
       
        final ValidationInfo validationInfo = getValidationInfo(beanValidationContext, currentProperty, validator);
        final PropertyDescriptor propertyDescriptor = validationInfo.getPropertyDescriptor();

        if (propertyDescriptor == null) return;

        final Set<ConstraintViolation<Object>> violations = validator.validateValue(
                (Class<Object>) validationInfo.getBeanType(), validationInfo.getPropertyName(),
View Full Code Here

                beanDescriptor = validator.getConstraintsForClass(beanType);
            }
        }

        final String propertyName = path[path.length - 1];
        PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(propertyName);
        return new ValidationInfo(beanType, propertyName, propertyDescriptor);
    }
View Full Code Here

        Validator validator = getValidator();
       
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Person.class );
        Assert.assertEquals("Incorrect class returned", Person.class, beanDescriptor.getElementClass());
       
        PropertyDescriptor nameDescriptor = beanDescriptor.getConstraintsForProperty("name");
        Assert.assertEquals("Incorrect class returned", String.class, nameDescriptor.getElementClass());
    }
View Full Code Here

TOP

Related Classes of javax.validation.metadata.PropertyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.