Package javax.validation

Examples of javax.validation.ValidationException


    ConstraintValidator<A, V> constraintValidator;
    constraintValidator = (ConstraintValidator<A, V>) constraintFactory.getInstance(
        validatorClass
    );
    if ( constraintValidator == null ) {
      throw new ValidationException(
          "Constraint factory returned null when trying to create instance of " + validatorClass.getName()
      );
    }
    initializeConstraint( descriptor, constraintValidator );
    return constraintValidator;
View Full Code Here


          constraintValidator) {
    try {
      constraintValidator.initialize( descriptor.getAnnotation() );
    }
    catch ( RuntimeException e ) {
      throw new ValidationException( "Unable to initialize " + constraintValidator.getClass().getName(), e );
    }
  }
View Full Code Here

  public T run() {
    try {
      return constructor.newInstance( initArgs );
    }
    catch ( InstantiationException e ) {
      throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
    }
    catch ( IllegalAccessException e ) {
      throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
    }
    catch ( InvocationTargetException e ) {
      throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
    }
    catch ( RuntimeException e ) {
      throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
    }
  }
View Full Code Here

      Method method = (Method) member;
      try {
        value = method.invoke( object );
      }
      catch ( IllegalAccessException e ) {
        throw new ValidationException( "Unable to access " + method.getName(), e );
      }
      catch ( InvocationTargetException e ) {
        throw new ValidationException( "Unable to access " + method.getName(), e );
      }
    }
    else if ( member instanceof Field ) {
      Field field = (Field) member;
      try {
        value = field.get( object );
      }
      catch ( IllegalAccessException e ) {
        throw new ValidationException( "Unable to access " + field.getName(), e );
      }
    }
    return value;
  }
View Full Code Here

    for ( ConstraintDefinitionType constraintDefinition : constraintDefinitionList ) {
      String annotationClassName = constraintDefinition.getAnnotation();

      Class<?> clazz = getClass( annotationClassName, defaultPackage );
      if ( !clazz.isAnnotation() ) {
        throw new ValidationException( annotationClassName + " is not an annotation" );
      }
      Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) clazz;

      ValidatedByType validatedByType = constraintDefinition.getValidatedBy();
      List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintValidatorClasses = newArrayList();
      if ( validatedByType.isIncludeExistingValidators() != null && validatedByType.isIncludeExistingValidators() ) {
        constraintValidatorClasses.addAll( findConstraintValidatorClasses( annotationClass ) );
      }
      for ( String validatorClassName : validatedByType.getValue() ) {
        Class<? extends ConstraintValidator<?, ?>> validatorClass;
        validatorClass = (Class<? extends ConstraintValidator<?, ?>>) ReflectionHelper.loadClass(
            validatorClassName,
            this.getClass()
        );


        if ( !ConstraintValidator.class.isAssignableFrom( validatorClass ) ) {
          throw new ValidationException( validatorClass + " is not a constraint validator class" );
        }

        constraintValidatorClasses.add( validatorClass );
      }
      constraintHelper.addConstraintValidatorDefinition(
View Full Code Here

    return constraintValidatorDefinitionClasses;
  }

  private void checkClassHasNotBeenProcessed(Set<Class<?>> processedClasses, Class<?> beanClass) {
    if ( processedClasses.contains( beanClass ) ) {
      throw new ValidationException( beanClass.getName() + " has already be configured in xml." );
    }
  }
View Full Code Here

  private void parseFieldLevelOverrides(List<FieldType> fields, Class<?> beanClass, String defaultPackage) {
    List<String> fieldNames = newArrayList();
    for ( FieldType fieldType : fields ) {
      String fieldName = fieldType.getName();
      if ( fieldNames.contains( fieldName ) ) {
        throw new ValidationException( fieldName + " is defined twice in mapping xml for bean " + beanClass.getName() );
      }
      else {
        fieldNames.add( fieldName );
      }
      final boolean containsField = ReflectionHelper.containsDeclaredField( beanClass, fieldName );
      if ( !containsField ) {
        throw new ValidationException( beanClass.getName() + " does not contain the fieldType  " + fieldName );
      }
      final Field field = ReflectionHelper.getDeclaredField( beanClass, fieldName );

      // ignore annotations
      boolean ignoreFieldAnnotation = fieldType.isIgnoreAnnotations() == null ? false : fieldType.isIgnoreAnnotations();
View Full Code Here

  private void parsePropertyLevelOverrides(List<GetterType> getters, Class<?> beanClass, String defaultPackage) {
    List<String> getterNames = newArrayList();
    for ( GetterType getterType : getters ) {
      String getterName = getterType.getName();
      if ( getterNames.contains( getterName ) ) {
        throw new ValidationException( getterName + " is defined twice in mapping xml for bean " + beanClass.getName() );
      }
      else {
        getterNames.add( getterName );
      }
      boolean containsMethod = ReflectionHelper.containsMethodWithPropertyName( beanClass, getterName );
      if ( !containsMethod ) {
        throw new ValidationException( beanClass.getName() + " does not contain the property  " + getterName );
      }
      final Method method = ReflectionHelper.getMethodFromPropertyName( beanClass, getterName );

      // ignore annotations
      boolean ignoreGetterAnnotation = getterType.isIgnoreAnnotations() == null ? false : getterType.isIgnoreAnnotations();
View Full Code Here

      if ( o.getClass().getName().equals( type.getName() ) ) {
        return ( T ) o;
      }
      else {
        String msg = "Wrong parameter type. Expected: " + type.getName() + " Actual: " + o.getClass().getName();
        throw new ValidationException( msg );
      }
    }
    catch ( NoSuchMethodException e ) {
      String msg = "The specified annotation defines no parameter '" + parameterName + "'.";
      throw new ValidationException( msg, e );
    }
    catch ( IllegalAccessException e ) {
      String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
      throw new ValidationException( msg, e );
    }
    catch ( InvocationTargetException e ) {
      String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
      throw new ValidationException( msg, e );
    }
  }
View Full Code Here

    A annotation;
    try {
      annotation = AnnotationFactory.create( annotationDescriptor );
    }
    catch ( RuntimeException e ) {
      throw new ValidationException(
          "Unable to create annotation for configured constraint: " + e.getMessage(), e
      );
    }

    java.lang.annotation.ElementType type = java.lang.annotation.ElementType.TYPE;
View Full Code Here

TOP

Related Classes of javax.validation.ValidationException

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.