Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


  public void testIncludeAnnotations() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "lastname" );
    assertNotNull( propDescriptor );

    Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors();
    assertEquals( constraintDescriptors.size(), 2, "There should be two constraints" );

    boolean foundNotNullConstraint = false;
    boolean foundPatternConstraint = false;
    for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
View Full Code Here


    return beanDescriptor.getConstraintsForMethod( method.getName(), method.getParameterTypes() ) != null;
  }

  private boolean isGetterConstrained(Method method, BeanDescriptor beanDescriptor) {
    String propertyName = ReflectionHelper.getPropertyName( method );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );
    return propertyDescriptor != null && propertyDescriptor.findConstraints()
        .declaredOn( ElementType.METHOD )
        .hasConstraints();
  }
View Full Code Here

      Property property = ELUtils.getProperty(expression, elContext);
      if (property == null) {
        return false;
      }
      BeanDescriptor beanConstraints = this.validator.getConstraintsForClass(property.getObjectType());
      PropertyDescriptor propertyConstraints = beanConstraints.getConstraintsForProperty(property.getName());
      return isRequired(propertyConstraints.getConstraintDescriptors());
    }
View Full Code Here

               
                if (base != null && property != null) {
                    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(base.getClass());
                   
                    if (beanDescriptor != null) {
                        PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(property.toString());

                        if (propertyDescriptor != null) {
                            return propertyDescriptor.getConstraintDescriptors();
                        }
                    }
                }
            }
        }
View Full Code Here

      }
    }
   
    //get constraints for each property name
    for(String propertyName : propertySet) {
      PropertyDescriptor property = DescriptorFactory.INSTANCE.getPropertyDescriptor(this.backingReflector, propertyName);
     
      //create finder
      ConstraintFinder finder = property.findConstraints()
        .lookingAt(scope)
        .declaredOn(declaredOnTypes.toArray(new ElementType[]{}))
        .unorderedAndMatchingGroups(matchingGroups.toArray(new Class<?>[]{}));
     
      //find and add to results
View Full Code Here

    if(this.backingReflector == null || this.backingReflector.getPropertyNames() == null) {
      return propertyDescriptors;
    }
   
    for(String propertyName : this.backingReflector.getPropertyNames()) {
      PropertyDescriptor descriptor = DescriptorFactory.INSTANCE.getPropertyDescriptor(this.backingReflector, propertyName);
      if(descriptor.hasConstraints() || descriptor.isCascaded()) {
        propertyDescriptors.add(descriptor);
      }
    }   
    return propertyDescriptors;
  }
View Full Code Here

   
    if(!this.backingReflector.getPropertyNames().contains(name)) {
      return null;
    }
   
    PropertyDescriptor descriptor = DescriptorFactory.INSTANCE.getPropertyDescriptor(this.backingReflector, name);
    if(!descriptor.hasConstraints() && !descriptor.isCascaded()) {
      return null;
    }
    return descriptor;
  }
View Full Code Here

   
    if(cachedViolations == null) {
      //get the bean descriptor and the property descriptor
      BeanDescriptor bean = this.getConstraintsForClass(beanType);
     
      PropertyDescriptor property = bean.getConstraintsForProperty(propertyName);
     
      //get constraints for beanType.propertyName
      Set<ConstraintDescriptor<?>> constraints  = property.findConstraints().unorderedAndMatchingGroups(groups).getConstraintDescriptors();

      //if no constraints are found using those groups, then we must take additional measures,
      //namely checking to see if it is a group interface instead of a plain group (see JSR-303
      //section 3.4.4. "Implicit Grouping")
      if(constraints == null || constraints.isEmpty()) {
        for(Class<?> group : groups) {
          //get bean descriptor for class
          BeanDescriptor groupBean = this.getConstraintsForClass(group);
          //get property if it exists on the bean
          PropertyDescriptor groupProperty = groupBean.getConstraintsForProperty(propertyName);
          //if the bean property exists and is constrained, add the constraints
          if(groupProperty != null && groupProperty.hasConstraints()) {
            constraints.addAll(groupProperty.getConstraintDescriptors());
          }
        }
      }
     
      //loop and validate
View Full Code Here

    return beanDescriptor.getConstraintsForMethod( method.getName(), method.getParameterTypes() ) != null;
  }

  private boolean isGetterConstrained(Method method, BeanDescriptor beanDescriptor) {
    String propertyName = ReflectionHelper.getPropertyName( method );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );
    return propertyDescriptor != null && propertyDescriptor.findConstraints()
        .declaredOn( ElementType.METHOD )
        .hasConstraints();
  }
View Full Code Here

    return beanDescriptor.getConstraintsForMethod( method.getName(), method.getParameterTypes() ) != null;
  }

  private boolean isGetterConstrained(Method method, BeanDescriptor beanDescriptor) {
    String propertyName = ReflectionHelper.getPropertyName( method );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );
    return propertyDescriptor != null && propertyDescriptor.findConstraints()
        .declaredOn( ElementType.METHOD )
        .hasConstraints();
  }
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.