Package javax.validation

Examples of javax.validation.ConstraintDefinitionException


      methods = getMethods.run();
    }
    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


        method = getMethod.run();
      }
      if (method == null) {
        String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
          "not contain a payload parameter.";
        throw new ConstraintDefinitionException( msg );
      }
      Class<?>[] defaultPayload = ( Class<?>[] ) method.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 );
    }
  }
View Full Code Here

        method = getMethod.run();
      }
      if (method == null) {
        String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
          "not contain a groups parameter.";
        throw new ConstraintDefinitionException( msg );
      }
      Class<?>[] defaultGroups = ( Class<?>[] ) method.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 );
    }
  }
View Full Code Here

      }
    }
    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

  }

  private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute) {
    final Method method = ReflectionHelper.getMethod( overridesAttribute.constraint(), overridesAttribute.name() );
    if ( method == null ) {
      throw new ConstraintDefinitionException(
          "Overridden constraint does not define an attribute with name " + overridesAttribute.name()
      );
    }
    Class<?> returnTypeOfOverriddenConstraint = method.getReturnType();
    if ( !returnTypeOfOverriddenConstraint.equals( m.getReturnType() ) ) {
      String message = "The overriding type of a composite constraint must be identical to the overridden one. Expected " + returnTypeOfOverriddenConstraint
          .getName() + " found " + m.getReturnType();
      throw new ConstraintDefinitionException( message );
    }
  }
View Full Code Here

    private static void validAttributes(final Annotation annotation) {
        final Method[] methods = run(SecureActions.getDeclaredMethods(annotation.annotationType()));
        for (Method method : methods ){
            // Currently case insensitive, the spec is unclear about this
            if (method.getName().toLowerCase(Locale.ENGLISH).startsWith("valid")) {
                throw new ConstraintDefinitionException(
                    "A constraint annotation cannot have methods which start with 'valid'");
            }
        }
    }
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

                if (method == null) {
                    if (quiet) {
                        _valid = false;
                        return;
                    }
                    throw new ConstraintDefinitionException(String.format("Annotation %1$s has no %2$s() method",
                        constraintType, getAttributeName()));
                }

                if (!TypeUtils.isAssignable(method.getReturnType(), getType())) {
                    if (quiet) {
                        _valid = false;
                        return;
                    }
                    throw new ConstraintDefinitionException(String.format(
                        "Return type for %1$s() must be of type %2$s", getAttributeName(), getType()));
                }
                _defaultValue = method.getDefaultValue();
                if (_defaultValue == null && permitNullDefaultValue) {
                    return;
                }
                if (TypeUtils.isArrayType(getType()) && Array.getLength(_defaultValue) > 0) {
                    if (quiet) {
                        _valid = false;
                        return;
                    }
                    throw new ConstraintDefinitionException(String.format(
                        "Default value for %1$s() must be an empty array", getAttributeName()));
                }
            } finally {
                valid = _valid;
                defaultValue = _defaultValue;
View Full Code Here

  }

  private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute) {
    final Method method = ReflectionHelper.getMethod( overridesAttribute.constraint(), overridesAttribute.name() );
    if ( method == null ) {
      throw new ConstraintDefinitionException(
          "Overridden constraint does not define an attribute with name " + overridesAttribute.name()
      );
    }
    Class<?> returnTypeOfOverriddenConstraint = method.getReturnType();
    if ( !returnTypeOfOverriddenConstraint.equals( m.getReturnType() ) ) {
      String message = "The overriding type of a composite constraint must be identical to the overridden one. Expected " + returnTypeOfOverriddenConstraint
          .getName() + " found " + m.getReturnType();
      throw new ConstraintDefinitionException( message );
    }
  }
View Full Code Here

  private void assertNoParameterStartsWithValid(Annotation annotation) {
    final Method[] methods = ReflectionHelper.getMethods( annotation.annotationType() );
    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

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.