Package org.hibernate.validator.metadata

Examples of org.hibernate.validator.metadata.AggregatedMethodMetaData


  private <T> void validateParametersInContext(MethodValidationContext<T> validationContext, T object, Object[] parameterValues, GroupChain groupChain) {

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );

    //assert that there are no illegal method parameter constraints
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( validationContext.getMethod() );
    methodMetaData.assertCorrectnessOfMethodParameterConstraints();

    if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
      groupChain.assertDefaultGroupSequenceIsExpandable( beanMetaData.getDefaultGroupSequence( object ) );
    }
View Full Code Here


    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    Method method = validationContext.getMethod();

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( method );

    // 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( object );
    }
    else {
      groupList = Arrays.<Class<?>>asList( group.getGroup() );
    }

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

      int numberOfViolationsOfCurrentGroup = 0;

      for ( int i = 0; i < parameterValues.length; i++ ) {

        //ignore this parameter if this validation is for a single parameter and this is not the right one
        if ( validationContext.getParameterIndex() != null && !validationContext.getParameterIndex()
            .equals( i ) ) {
          continue;
        }

        Object value = parameterValues[i];
        String parameterName = methodMetaData.getParameterMetaData( i ).getParameterName();

        // validate constraints at parameter itself
        ValueContext<T, Object> valueContext = ValueContext.getLocalExecutionContext(
            object, PathImpl.createPathForMethodParameter( method, parameterName ), i, parameterName
        );
        valueContext.setCurrentValidatedValue( value );
        valueContext.setCurrentGroup( oneGroup );

        numberOfViolationsOfCurrentGroup += validateParameterForGroup(
            validationContext, valueContext, methodMetaData.getParameterMetaData( i )
        );
        if ( validationContext.shouldFailFast() ) {
          return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
        }
      }

      //stop processing after first group with errors occurred
      if ( numberOfViolationsOfCurrentGroup > 0 ) {
        break;
      }
    }

    // validate parameter beans annotated with @Valid if required
    for ( int i = 0; i < parameterValues.length; i++ ) {

      //ignore this parameter if this validation is for a single parameter and this is not the right one
      if ( validationContext.getParameterIndex() != null && !validationContext.getParameterIndex().equals( i ) ) {
        continue;
      }

      Object value = parameterValues[i];
      ParameterMetaData parameterMetaData = methodMetaData.getParameterMetaData( i );
      String parameterName = parameterMetaData.getParameterName();

      if ( parameterMetaData.isCascading() && value != null ) {

        ValueContext<Object, ?> cascadingvalueContext = ValueContext.getLocalExecutionContext(
View Full Code Here

    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    Method method = validationContext.getMethod();

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( method );

    // 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.getGroup() );
    }

    //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<T, V> valueContext = ValueContext.getLocalExecutionContext(
          bean, PathImpl.createPathForMethodReturnValue( method )
      );
      valueContext.setCurrentValidatedValue( value );
      valueContext.setCurrentGroup( oneGroup );

      numberOfViolationsOfCurrentGroup +=
          validateReturnValueForGroup(
              validationContext, valueContext, methodMetaData
          );
      if ( validationContext.shouldFailFast() ) {
        return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
      }

      //stop processing after first group with errors occurred
      if ( numberOfViolationsOfCurrentGroup > 0 ) {
        break;
      }
    }

    // cascaded validation if required
    if ( methodMetaData.isCascading() && value != null ) {

      ValueContext<V, Object> cascadingvalueContext = ValueContext.getLocalExecutionContext(
          value, PathImpl.createPathForMethodReturnValue( method )
      );
      cascadingvalueContext.setCurrentGroup( group.getGroup() );
View Full Code Here

  private <T> void validateParametersInContext(MethodValidationContext<T> validationContext, T object, Object[] parameterValues, GroupChain groupChain) {

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );

    //assert that there are no illegal method parameter constraints
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( validationContext.getMethod() );
    methodMetaData.assertCorrectnessOfMethodParameterConstraints();

    if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
      groupChain.assertDefaultGroupSequenceIsExpandable( beanMetaData.getDefaultGroupSequence( object ) );
    }
View Full Code Here

    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    Method method = validationContext.getMethod();

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( method );

    // 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( object );
    }
    else {
      groupList = Arrays.<Class<?>>asList( group.getGroup() );
    }

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

      int numberOfViolationsOfCurrentGroup = 0;

      for ( int i = 0; i < parameterValues.length; i++ ) {

        //ignore this parameter if this validation is for a single parameter and this is not the right one
        if ( validationContext.getParameterIndex() != null && !validationContext.getParameterIndex()
            .equals( i ) ) {
          continue;
        }

        Object value = parameterValues[i];
        String parameterName = methodMetaData.getParameterMetaData( i ).getParameterName();

        // validate constraints at parameter itself
        ValueContext<T, Object> valueContext = ValueContext.getLocalExecutionContext(
            object, PathImpl.createPathForMethodParameter( method, parameterName ), i, parameterName
        );
        valueContext.setCurrentValidatedValue( value );
        valueContext.setCurrentGroup( oneGroup );

        numberOfViolationsOfCurrentGroup += validateParameterForGroup(
            validationContext, valueContext, methodMetaData.getParameterMetaData( i )
        );
        if ( validationContext.shouldFailFast() ) {
          return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
        }
      }

      //stop processing after first group with errors occurred
      if ( numberOfViolationsOfCurrentGroup > 0 ) {
        break;
      }
    }

    // validate parameter beans annotated with @Valid if required
    for ( int i = 0; i < parameterValues.length; i++ ) {

      //ignore this parameter if this validation is for a single parameter and this is not the right one
      if ( validationContext.getParameterIndex() != null && !validationContext.getParameterIndex().equals( i ) ) {
        continue;
      }

      Object value = parameterValues[i];
      ParameterMetaData parameterMetaData = methodMetaData.getParameterMetaData( i );
      String parameterName = parameterMetaData.getParameterName();

      if ( parameterMetaData.isCascading() && value != null ) {

        ValueContext<Object, ?> cascadingvalueContext = ValueContext.getLocalExecutionContext(
View Full Code Here

    int numberOfViolationsBefore = validationContext.getFailingConstraints().size();

    Method method = validationContext.getMethod();

    BeanMetaData<T> beanMetaData = getBeanMetaData( validationContext.getRootBeanClass() );
    AggregatedMethodMetaData methodMetaData = beanMetaData.getMetaDataFor( method );

    // 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.getGroup() );
    }

    //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<T, V> valueContext = ValueContext.getLocalExecutionContext(
          bean, PathImpl.createPathForMethodReturnValue( method )
      );
      valueContext.setCurrentValidatedValue( value );
      valueContext.setCurrentGroup( oneGroup );

      numberOfViolationsOfCurrentGroup +=
          validateReturnValueForGroup(
              validationContext, valueContext, methodMetaData
          );
      if ( validationContext.shouldFailFast() ) {
        return validationContext.getFailingConstraints().size() - numberOfViolationsBefore;
      }

      //stop processing after first group with errors occurred
      if ( numberOfViolationsOfCurrentGroup > 0 ) {
        break;
      }
    }

    // cascaded validation if required
    if ( methodMetaData.isCascading() && value != null ) {

      ValueContext<V, Object> cascadingvalueContext = ValueContext.getLocalExecutionContext(
          value, PathImpl.createPathForMethodReturnValue( method )
      );
      cascadingvalueContext.setCurrentGroup( group.getGroup() );
View Full Code Here

TOP

Related Classes of org.hibernate.validator.metadata.AggregatedMethodMetaData

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.