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

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


    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() );
      setValidatedValueHandlerToValueContextIfPresent(
          validationContext,
          valueContext,
          executableMetaData.getReturnValueMetaData()
      );

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

    return localContext.getParameterIndex() == null;
  }

  private ExecutableDescriptorImpl getMethodDescriptor() {
    BeanMetaData<?> rootMetaData = getBeanMetaDataManager().getBeanMetaData( getRootBeanClass() );
    ExecutableMetaData methodMetaData = rootMetaData.getMetaDataFor( method );
    BeanDescriptor beanDescriptor = rootMetaData.getBeanDescriptor();

    //TODO HV-571: Avoid these casts
    if ( methodMetaData.getKind() == ConstraintMetaDataKind.METHOD ) {
      return (ExecutableDescriptorImpl) beanDescriptor.getConstraintsForMethod(
          method.getMember().getName(),
          methodMetaData.getParameterTypes()
      );
    }
    else {
      return (ExecutableDescriptorImpl) beanDescriptor.getConstraintsForConstructor(
          methodMetaData.getParameterTypes()
      );
    }
  }
View Full Code Here

                         ValidationOrder validationOrder) {

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

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

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

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

    ExecutableElement executable = validationContext.getExecutable();

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

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

    //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++ ) {
        Object value = parameterValues[i];
        String parameterName = methodMetaData.getParameterMetaData( i ).getName();

        // validate constraints at parameter itself
        ValueContext<T, Object> valueContext;

        if ( object != null ) {
          valueContext = ValueContext.getLocalExecutionContext(
              object, PathImpl.createPathForParameter( executable, parameterName ), i, parameterName
          );
        }
        else {
          valueContext = ValueContext.getLocalExecutionContext(
              object,
              (Class<T>) executable.getMember().getDeclaringClass(),
              PathImpl.createPathForParameter( executable, parameterName ),
              i,
              parameterName
          );
        }
        valueContext.setCurrentValidatedValue( value );
        valueContext.setCurrentGroup( oneGroup );

        numberOfViolationsOfCurrentGroup += validateParameterForGroup(
            validationContext, valueContext, methodMetaData.getParameterMetaData( i )
        );
        if ( shouldFailFast( validationContext ) ) {
          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++ ) {

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

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

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

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

    ExecutableElement executable = validationContext.getExecutable();

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

    // 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<T, V> valueContext;
      if ( bean != null ) {
        valueContext = ValueContext.getLocalExecutionContext(
            bean, PathImpl.createPathForMethodReturnValue( executable )
        );
      }
      else {
        //constructor validation
        valueContext = ValueContext.getLocalExecutionContext(
            (Class<T>) executable.getMember().getDeclaringClass(),
            PathImpl.createPathForMethodReturnValue( executable )
        );
      }

      valueContext.setCurrentValidatedValue( value );
      valueContext.setCurrentGroup( oneGroup );

      numberOfViolationsOfCurrentGroup +=
          validateReturnValueForGroup(
              validationContext, valueContext, methodMetaData
          );
      if ( shouldFailFast( validationContext ) ) {
        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( executable )
      );
      cascadingvalueContext.setCurrentGroup( group.getDefiningClass() );
View Full Code Here

  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 ) {
      // there is no executable metadata - specified object and method do not match
      throw log.getMethodOrConstructorNotDefinedByValidatedTypeException(
          beanMetaData.getBeanClass().getName(),
          validationContext.getExecutable().getMember()
      );
    }

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

        ParameterMetaData parameterMetaData = executableMetaData.getParameterMetaData( i );
        Object value = parameterValues[i];

        if ( value != null ) {
          Class<?> valueType = value.getClass();
          if ( parameterMetaData.getType() instanceof Class && ( (Class<?>) parameterMetaData.getType() ).isPrimitive() ) {
            valueType = ReflectionHelper.unBoxedType( valueType );
          }
          if ( !TypeHelper.isAssignable( parameterMetaData.getType(), valueType ) ) {
            throw log.getParameterTypesDoNotMatchException(
                valueType.getName(),
                parameterMetaData.getType().toString(),
                i,
                validationContext.getExecutable().getMember()
            );
          }
        }

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

        numberOfViolationsOfCurrentGroup += validateConstraintsForGroup(
            validationContext, valueContext, parameterMetaData
        );
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.