Package javax.validation

Examples of javax.validation.ConstraintDefinitionException


    }
    else {
      method = getMethod.run();
    }
    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


      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 static void validGroups(Annotation annotation) {
        // Ensure that it has a groups() method...
        Method groupsMethod = SecureActions.getMethod(annotation.annotationType(), "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(), "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(), "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

    }
    else {
      method = getMethod.run();
    }
    if (method == null) {
      throw new ConstraintDefinitionException(
          "Overriden constraint does not define an attribute with name " + overridesAttribute.name()
      );
    }
    Class<?> returnTypeOfOverridenConstraint = method.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 );
    }
  }
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.