Package javax.validation

Examples of javax.validation.ConstraintDefinitionException


     */
    private static void validGroups(Annotation annotation) {
        // Ensure that it has a groups() method...
        Method groupsMethod = SecureActions.getMethod(annotation.annotationType(), Jsr303MetaBeanFactory.ANNOTATION_GROUPS);
        if ( groupsMethod == null ) {
            throw new ConstraintDefinitionException("Constraint definition " + annotation + " has no groups() method");
        }
       
        // ...whose default value is an empty array
        Object defaultGroupsValue = groupsMethod.getDefaultValue();
        if ( defaultGroupsValue instanceof Class<?>[] ) {
            if ( ((Class[]) defaultGroupsValue).length != 0 ) {
                throw new ConstraintDefinitionException("Default value for groups() must be an empty array");
            }
        }
        else {
            throw new ConstraintDefinitionException("Return type for groups() must be of type Class<?>[]");
        }
    }
View Full Code Here


     */
    private static void validPayload(Annotation annotation) {
        // Ensure that it has a payload() method...
        Method payloadMethod = SecureActions.getMethod(annotation.annotationType(), Jsr303MetaBeanFactory.ANNOTATION_PAYLOAD);
        if ( payloadMethod == null ) {
            throw new ConstraintDefinitionException("Constraint definition " + annotation + " has no payload() method");
        }
       
        // ...whose default value is an empty array
        Object defaultPayloadValue = payloadMethod.getDefaultValue();
        if ( defaultPayloadValue instanceof Class<?>[] ) {
            if ( ((Class[]) defaultPayloadValue).length != 0 ) {
                throw new ConstraintDefinitionException("Default value for payload() must be an empty array");
            }
        }
        else {
            throw new ConstraintDefinitionException("Return type for payload() must be of type Class<? extends Payload>[]");
        }
    }
View Full Code Here

     */
    private static void validMessage(Annotation annotation) {
        // Ensure that it has a message() method...
        Method messageMethod = SecureActions.getMethod(annotation.annotationType(), Jsr303MetaBeanFactory.ANNOTATION_MESSAGE);
        if ( messageMethod == null ) {
            throw new ConstraintDefinitionException("Constraint definition " + annotation + " has no message() method");
        }
       
        // ...whose default value is a String
        Object defaultMessageValue = messageMethod.getDefaultValue();
        if ( !(defaultMessageValue instanceof String) ) {
            throw new ConstraintDefinitionException("Return type for message() must be of type String");
        }
    }
View Full Code Here

    private static void validAttributes(Annotation annotation) {
        Method[] methods = 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

  }

  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(Class<? extends Annotation> annotationType) {
    final Method[] methods = ReflectionHelper.getDeclaredMethods( 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

    try {
      final Method method = ReflectionHelper.getMethod( annotationType, "payload" );
      if ( method == null ) {
        String msg = 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 = annotationType
            .getName() + " contains Constraint annotation, but the payload " +
            "parameter default value is not the empty array.";
        throw new ConstraintDefinitionException( msg );
      }
    }
    catch ( ClassCastException e ) {
      String msg = annotationType.getName() + " contains Constraint annotation, but the " +
          "payload parameter is of wrong type.";
      throw new ConstraintDefinitionException( msg, e );
    }
  }
View Full Code Here

    try {
      final Method method = ReflectionHelper.getMethod( annotationType, "groups" );
      if ( method == null ) {
        String msg = 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 = annotationType
            .getName() + " contains Constraint annotation, but the groups " +
            "parameter default value is not the empty array.";
        throw new ConstraintDefinitionException( msg );
      }
    }
    catch ( ClassCastException e ) {
      String msg = annotationType.getName() + " contains Constraint annotation, but the " +
          "groups parameter is of wrong type.";
      throw new ConstraintDefinitionException( msg, e );
    }
  }
View Full Code Here

    try {
      final Method method = ReflectionHelper.getMethod( annotationType, "message" );
      if ( method == null ) {
        String msg = annotationType.getName() + " contains Constraint annotation, but does " +
            "not contain a message parameter.";
        throw new ConstraintDefinitionException( msg );
      }
      if ( method.getReturnType() != String.class ) {
        String msg = annotationType.getName() + " contains Constraint annotation, but the message parameter " +
            "is not of type java.lang.String.";
        throw new ConstraintDefinitionException( msg );
      }
    }
    catch ( ClassCastException e ) {
      String msg = annotationType.getName() + " contains Constraint annotation, but the " +
          "groups parameter is of wrong type.";
      throw new ConstraintDefinitionException( msg, 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.