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

      numberOfViolationsOfCurrentGroup +=
          validateConstraintsForGroup(
              validationContext, valueContext, executableMetaData
          );
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[], Object> cascadingValueContext = ValueContext.getLocalExecutionContext(
        parameterValues,
        executableMetaData.getValidatableParametersMetaData(),
        PathImpl.createPathForExecutable( executableMetaData )
    );
    cascadingValueContext.setUnwrapMode( executableMetaData.unwrapMode() );

    groupIterator = validationOrder.getGroupIterator();
    while ( groupIterator.hasNext() ) {
      Group group = groupIterator.next();
      cascadingValueContext.setCurrentGroup( group.getDefiningClass() );
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() );

    if ( parameterValues.length != executableMetaData.getParameterTypes().length ) {
      throw log.getInvalidParameterCountForExecutableException(
          ExecutableElement.getExecutableAsString(
              executableMetaData.getType().toString() + "#" + executableMetaData.getName(),
              executableMetaData.getParameterTypes()
          ), parameterValues.length, executableMetaData.getParameterTypes().length
      );
    }

    // 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() ) {
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 );
      ReturnValueMetaData returnValueMetaData = executableMetaData.getReturnValueMetaData();
      valueContext.appendNode( returnValueMetaData );
      valueContext.setUnwrapMode( returnValueMetaData.unwrapMode() );

      numberOfViolationsOfCurrentGroup +=
          validateConstraintsForGroup(
View Full Code Here

    return false;
  }

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

    if ( methodMetaData.getKind() == ConstraintMetaDataKind.METHOD ) {
      return beanDescriptor.getConstraintsForMethod(
          method.getMember().getName(),
          methodMetaData.getParameterTypes()
      );
    }
    else {
      return 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;

      ValueContext<T, Object> valueContext = getExecutableValueContext(
          object,
          executable, oneGroup
      );
      valueContext.setCurrentValidatedValue( parameterValues );

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

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

        valueContext.appendNode( parameterName );
        valueContext.setParameterIndex( i );
        valueContext.setCurrentValidatedValue( value );

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

        valueContext.setPropertyPath( originalPath );
      }

      // 3. validate cascaded parameter if required
      ValueContext<Object[], ?> cascadingValueContext = ValueContext.getLocalExecutionContext(
          parameterValues,
          methodMetaData.getParameterListMetaData(),
          PathImpl.createPathForExecutable( executable )
      );
      cascadingValueContext.setCurrentGroup( oneGroup );

      validateCascadedConstraints( validationContext, cascadingValueContext );
View Full Code Here

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

    ExecutableElement executable = validationContext.getExecutable();

    BeanMetaData<T> beanMetaData = beanMetaDataManager.getBeanMetaData( validationContext.getRootBeanClass() );
    ExecutableMetaData executableMetaData = 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, Object> valueContext = getExecutableValueContext( bean, executable, oneGroup );

      valueContext.setCurrentValidatedValue( value );
      valueContext.appendNode( PathImpl.RETURN_VALUE_NODE_NAME );

      numberOfViolationsOfCurrentGroup +=
          validateConstraintsForGroup(
              validationContext, valueContext, executableMetaData
          );
      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 ( executableMetaData.isCascading() && value != null ) {

        ValueContext<V, Object> cascadingvalueContext = ValueContext.getLocalExecutionContext(
            value,
            executableMetaData.getReturnValueMetaData(),
            PathImpl.createPathForExecutable( executable )
        );
        cascadingvalueContext.setCurrentGroup( oneGroup );

        validateCascadedConstraints( validationContext, cascadingvalueContext );
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.