Package javax.validation

Examples of javax.validation.ConstraintDefinitionException


                annotatedElt++;
            }
        }

        if (annotatedElt == 0 && param >= 1 && constraintValidation.getValidationAppliesTo() != null) { // pure cross param
            throw new ConstraintDefinitionException("pure cross parameter constraints shouldn't get validationAppliesTo attribute");
        } else {
            if (param >= 1 && annotatedElt >= 1 && constraintValidation.getValidationAppliesTo() == null) { // generic and cross param
                throw new ConstraintDefinitionException("cross parameter AND generic constraints should get validationAppliesTo attribute");
            } else if (param == 0 && constraintValidation.getValidationAppliesTo() != null) { // pure generic
                throw new ConstraintDefinitionException("pure generic constraints shouldn't get validationAppliesTo attribute");
            }
        }

        return new Pair(annotatedElt, param);
    }
View Full Code Here


        return new Pair(annotatedElt, param);
    }

    private void buildValidationAppliesTo(final Method method) throws InvocationTargetException, IllegalAccessException {
        if (!TypeUtils.isAssignable(method.getReturnType(), ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getType())) {
            throw new ConstraintDefinitionException("Return type for validationAppliesTo() must be of type " + ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getType());
        }
        final Object validationAppliesTo = method.invoke(constraintValidation.getAnnotation());
        if (ConstraintTarget.class.isInstance(validationAppliesTo)) {
            constraintValidation.setValidationAppliesTo(ConstraintTarget.class.cast(validationAppliesTo));
        } else {
            throw new ConstraintDefinitionException("validationAppliesTo type is " + ConstraintTarget.class.getName());
        }
    }
View Full Code Here

        }
    }

    private void buildGroups(final Method method) throws IllegalAccessException, InvocationTargetException {
        if (!TypeUtils.isAssignable(method.getReturnType(), ConstraintAnnotationAttributes.GROUPS.getType())) {
            throw new ConstraintDefinitionException("Return type for groups() must be of type " + ConstraintAnnotationAttributes.GROUPS.getType());
        }

        final Object raw = method.invoke(constraintValidation.getAnnotation());
        Class<?>[] garr;
        if (raw instanceof Class<?>) {
            garr = new Class[] { (Class<?>) raw };
        } else if (raw instanceof Class<?>[]) {
            garr = (Class<?>[]) raw;
            if (Object[].class.cast(method.getDefaultValue()).length > 0) {
                throw new ConstraintDefinitionException("Default value for groups() must be an empty array");
            }
        } else {
            garr = null;
        }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private void buildPayload(final Method method) throws IllegalAccessException, InvocationTargetException {
        if (!TypeUtils.isAssignable(method.getReturnType(), ConstraintAnnotationAttributes.PAYLOAD.getType())) {
            throw new ConstraintDefinitionException("Return type for payload() must be of type " + ConstraintAnnotationAttributes.PAYLOAD.getType());
        }
        if (Object[].class.cast(method.getDefaultValue()).length > 0) {
            throw new ConstraintDefinitionException("Default value for payload() must be an empty array");
        }

        Class<? extends Payload>[] payload_raw =
            (Class<? extends Payload>[]) method.invoke(constraintValidation.getAnnotation());
        Set<Class<? extends Payload>> payloadSet;
View Full Code Here

          .getMethod( overridesAttribute.name() )
          .getReturnType();
      if ( !returnTypeOfOverridenConstraint.equals( m.getReturnType() ) ) {
        String message = "The overiding type of a composite constraint must be identical to the overwridden one. Expected " + returnTypeOfOverridenConstraint
            .getName() + " found " + m.getReturnType();
        throw new ConstraintDefinitionException( message );
      }
    }
    catch ( NoSuchMethodException nsme ) {
      throw new ConstraintDefinitionException(
          "Overriden constraint does not define an attribute with name " + overridesAttribute.name()
      );
    }
  }
View Full Code Here

  private void assertNoParameterStartsWithValid(Annotation annotation) {
    Method[] methods = annotation.getClass().getMethods();
    for ( Method m : methods ) {
      if ( m.getName().startsWith( "valid" ) ) {
        String msg = "Parameters starting with 'valid' are not allowed in a constraint.";
        throw new ConstraintDefinitionException( msg );
      }
    }
  }
View Full Code Here

          .getDefaultValue();
      if ( defaultPayload.length != 0 ) {
        String msg = annotation.annotationType()
            .getName() + " contains Constraint annotation, but the payload " +
            "paramter default value is not the empty array.";
        throw new ConstraintDefinitionException( msg );
      }
    }
    catch ( ClassCastException e ) {
      String msg = annotation.annotationType().getName() + " contains Constraint annotation, but the " +
          "payload parameter is of wrong type.";
      throw new ConstraintDefinitionException( msg );
    }
    catch ( NoSuchMethodException nsme ) {
      String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
          "not contain a payload parameter.";
      throw new ConstraintDefinitionException( msg );
    }
  }
View Full Code Here

          .getDefaultValue();
      if ( defaultGroups.length != 0 ) {
        String msg = annotation.annotationType()
            .getName() + " contains Constraint annotation, but the groups " +
            "paramter default value is not the empty array.";
        throw new ConstraintDefinitionException( msg );
      }
    }
    catch ( ClassCastException e ) {
      String msg = annotation.annotationType().getName() + " contains Constraint annotation, but the " +
          "groups parameter is of wrong type.";
      throw new ConstraintDefinitionException( msg );
    }
    catch ( NoSuchMethodException nsme ) {
      String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
          "not contain a groups parameter.";
      throw new ConstraintDefinitionException( msg );
    }
  }
View Full Code Here

      ReflectionHelper.getAnnotationParameter( annotation, "message", String.class );
    }
    catch ( Exception e ) {
      String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
          "not contain a message parameter.";
      throw new ConstraintDefinitionException( msg );
    }
  }
View Full Code Here

        validator.initialize(annotation);
      } catch (RuntimeException e) {
        // Either a "legit" problem initializing the validator or a
        // ClassCastException if the validator associated annotation is
        // not a supertype of the validated annotation.
        throw new ConstraintDefinitionException(
            "Incorrect validator [" + validator.getClass().getCanonicalName() + "] for annotation " +
                annotation.annotationType().getCanonicalName(), e);
      }
    }
  }
View Full Code Here

TOP

Related Classes of javax.validation.ConstraintDefinitionException

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.