Package org.hibernate.validator.internal.metadata.aggregated

Examples of org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData


  private <T> void validateParametersInContext(ValidationContext<T> validationContext,
                         Object[] parameterValues,
                         ValidationOrder validationOrder) {
    BeanMetaData<T> beanMetaData = beanMetaDataManager.getBeanMetaData( validationContext.getRootBeanClass() );
    ExecutableMetaData executableMetaData = beanMetaData.getMetaDataFor( validationContext.getExecutable() );

    if ( executableMetaData == null ) {
      // nothing to validate
      return;
    }

    if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
      validationOrder.assertDefaultGroupSequenceIsExpandable(
          beanMetaData.getDefaultGroupSequence(
              validationContext.getRootBean()
          )
      );
    }

    // process first single groups
    Iterator<Group> groupIterator = validationOrder.getGroupIterator();
    while ( groupIterator.hasNext() ) {
      validateParametersForGroup( validationContext, parameterValues, groupIterator.next() );
      if ( shouldFailFast( validationContext ) ) {
        return;
      }
    }

    ValueContext<Object[], ?> cascadingValueContext = ValueContext.getLocalExecutionContext(
        parameterValues,
        executableMetaData.getValidatableParametersMetaData(),
        PathImpl.createPathForExecutable( executableMetaData )
    );

    groupIterator = validationOrder.getGroupIterator();
    while ( groupIterator.hasNext() ) {
View Full Code Here


  private <T> int validateParametersForGroup(ValidationContext<T> validationContext, Object[] parameterValues, Group group) {
    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    BeanMetaData<T> beanMetaData = beanMetaDataManager.getBeanMetaData( validationContext.getRootBeanClass() );
    ExecutableMetaData executableMetaData = beanMetaData.getMetaDataFor( validationContext.getExecutable() );

    // TODO GM: define behavior with respect to redefined default sequences. Should only the
    // sequence from the validated bean be honored or also default sequence definitions up in
    // the inheritance tree?
    // For now a redefined default sequence will only be considered if specified at the bean
    // hosting the validated itself, but no other default sequence from parent types
    List<Class<?>> groupList;
    if ( group.isDefaultGroup() ) {
      groupList = beanMetaData.getDefaultGroupSequence( validationContext.getRootBean() );
    }
    else {
      groupList = Arrays.<Class<?>>asList( group.getDefiningClass() );
    }

    //the only case where we can have multiple groups here is a redefined default group sequence
    for ( Class<?> currentValidatedGroup : groupList ) {
      int numberOfViolationsOfCurrentGroup = 0;

      ValueContext<T, Object> valueContext = getExecutableValueContext(
          validationContext.getRootBean(), executableMetaData, currentValidatedGroup
      );
      valueContext.appendCrossParameterNode();
      valueContext.setCurrentValidatedValue( parameterValues );

      // 1. validate cross-parameter constraints
      numberOfViolationsOfCurrentGroup += validateConstraintsForGroup(
          validationContext, valueContext, executableMetaData.getCrossParameterConstraints()
      );
      if ( shouldFailFast( validationContext ) ) {
        return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
      }

      valueContext = getExecutableValueContext(
          validationContext.getRootBean(), executableMetaData, currentValidatedGroup
      );
      valueContext.setCurrentValidatedValue( parameterValues );

      // 2. validate parameter constraints
      for ( int i = 0; i < parameterValues.length; i++ ) {
        PathImpl originalPath = valueContext.getPropertyPath();
        Object value = parameterValues[i];

        valueContext.appendNode( executableMetaData.getParameterMetaData( i ) );
        valueContext.setCurrentValidatedValue( value );

        numberOfViolationsOfCurrentGroup += validateConstraintsForGroup(
            validationContext, valueContext, executableMetaData.getParameterMetaData( i )
        );
        if ( shouldFailFast( validationContext ) ) {
          return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
        }
View Full Code Here

    return valueContext;
  }

  private <V, T> void validateReturnValueInContext(ValidationContext<T> context, T bean, V value, ValidationOrder validationOrder) {
    BeanMetaData<T> beanMetaData = beanMetaDataManager.getBeanMetaData( context.getRootBeanClass() );
    ExecutableMetaData executableMetaData = beanMetaData.getMetaDataFor( context.getExecutable() );

    if ( executableMetaData == null ) {
      return;
    }

    if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
      validationOrder.assertDefaultGroupSequenceIsExpandable( beanMetaData.getDefaultGroupSequence( bean ) );
    }

    Iterator<Group> groupIterator = validationOrder.getGroupIterator();

    // process first single groups
    while ( groupIterator.hasNext() ) {
      validateReturnValueForGroup( context, bean, value, groupIterator.next() );
      if ( shouldFailFast( context ) ) {
        return;
      }
    }

    ValueContext<V, Object> cascadingValueContext = null;

    if ( value != null ) {
      cascadingValueContext = ValueContext.getLocalExecutionContext(
          value,
          executableMetaData.getReturnValueMetaData(),
          PathImpl.createPathForExecutable( executableMetaData )
      );

      groupIterator = validationOrder.getGroupIterator();
      while ( groupIterator.hasNext() ) {
View Full Code Here

  //TODO GM: if possible integrate with validateParameterForGroup()
  private <T> int validateReturnValueForGroup(ValidationContext<T> validationContext, T bean, Object value, Group group) {
    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    BeanMetaData<T> beanMetaData = beanMetaDataManager.getBeanMetaData( validationContext.getRootBeanClass() );
    ExecutableMetaData executableMetaData = beanMetaData.getMetaDataFor( validationContext.getExecutable() );

    if ( executableMetaData == null ) {
      // nothing to validate
      return 0;
    }

    // TODO GM: define behavior with respect to redefined default sequences. Should only the
    // sequence from the validated bean be honored or also default sequence definitions up in
    // the inheritance tree?
    // For now a redefined default sequence will only be considered if specified at the bean
    // hosting the validated itself, but no other default sequence from parent types

    List<Class<?>> groupList;
    if ( group.isDefaultGroup() ) {
      groupList = beanMetaData.getDefaultGroupSequence( bean );
    }
    else {
      groupList = Arrays.<Class<?>>asList( group.getDefiningClass() );
    }

    //the only case where we can have multiple groups here is a redefined default group sequence
    for ( Class<?> oneGroup : groupList ) {

      int numberOfViolationsOfCurrentGroup = 0;

      // validate constraints at return value itself
      ValueContext<?, Object> valueContext = getExecutableValueContext(
          executableMetaData.getKind() == ElementKind.CONSTRUCTOR ? value : bean,
          executableMetaData,
          oneGroup
      );

      valueContext.setCurrentValidatedValue( value );
      valueContext.appendNode( executableMetaData.getReturnValueMetaData() );

      numberOfViolationsOfCurrentGroup +=
          validateConstraintsForGroup(
              validationContext, valueContext, executableMetaData
          );
View Full Code Here

TOP

Related Classes of org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData

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.