Package javax.validation

Examples of javax.validation.UnexpectedTypeException


        if (types.isEmpty()) {
            StringBuilder buf =
                new StringBuilder().append("No validator could be found for type ").append(stringForType(targetType))
                    .append(". See: @").append(anno.annotationType().getSimpleName()).append(" at ").append(
                        stringForLocation(owner, access));
            throw new UnexpectedTypeException(buf.toString());
        } else if (types.size() > 1) {
            StringBuilder buf = new StringBuilder();
            buf.append("Ambiguous validators for type ");
            buf.append(stringForType(targetType));
            buf.append(". See: @").append(anno.annotationType().getSimpleName()).append(" at ").append(
                stringForLocation(owner, access));
            buf.append(". Validators are: ");
            boolean comma = false;
            for (Type each : types) {
                if (comma)
                    buf.append(", ");
                comma = true;
                buf.append(each);
            }
            throw new UnexpectedTypeException(buf.toString());
        }
    }
View Full Code Here


            throw new ConstraintDeclarationException(
                "Could not validate " + StartBeforeEnd.class.getSimpleName()
                + ". No field found in " + type.getName() + " for " + name);
        }
        if(f.getType() != Date.class) {
            throw new UnexpectedTypeException(
                "Could not validate " + StartBeforeEnd.class.getSimpleName()
                + ". Field found in " + type.getName() + " for " + name + " is not a " + Date.class.getName());
        }
        return f;
    }
View Full Code Here

        }
        else {
          className = clazz.getName();
        }
      }
      throw new UnexpectedTypeException( "No validator could be found for type: " + className );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validator classes which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

        }
        else {
          className = clazz.getName();
        }
      }
      throw new UnexpectedTypeException( "No validator could be found for type: " + className );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validator classes which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

            ServiceLocator habitat = dom.getHabitat();
            boolean result = true;
            boolean disableGlobalMessage = true;
            for (RemoteKeyInfo remoteKeyInfo : remoteKeys) {
                if (remoteKeyInfo.method.getParameterTypes().length > 0) {
                    throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.getter",
                            "The RemoteKey annotation must be on a getter method."));
                }
                try {
                    Object value = remoteKeyInfo.method.invoke(config);
                    if (value instanceof String) {
                        String key = (String) value;
                        ConfigBeanProxy component = habitat.getService(remoteKeyInfo.annotation.type(), key);
                        if (component == null) {
                            result = false;
                            if (remoteKeyInfo.annotation.message().isEmpty()) {
                                disableGlobalMessage = false;
                            } else {
                                cvc.buildConstraintViolationWithTemplate(remoteKeyInfo.annotation.message())
                                        .addNode(Dom.convertName(remoteKeyInfo.method.getName()))
                                        .addConstraintViolation();
                            }
                        }
                    } else {
                        throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.string",
                            "The RemoteKey annotation must identify a method that returns a String."));
                    }
                } catch (Exception ex) {
                    return false;
                }
View Full Code Here

      ConstraintDescriptor<A> constraint, Class<?> targetType)
      throws UnexpectedTypeException {
    List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses
        = constraint.getConstraintValidatorClasses();
    if (constraintValidatorClasses.isEmpty()) {
      throw new UnexpectedTypeException("No ConstraintValidator found for  "
          + constraint.getAnnotation());
    }
    ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> best = getValidatorForType(
        targetType, constraintValidatorClasses);
    if (best.isEmpty()) {
      throw new UnexpectedTypeException("No " + constraint.getAnnotation()
          + " ConstraintValidator for type " + targetType);
    }
    if (best.size() > 1) {
      throw new UnexpectedTypeException("More than one maximally specific "
          + constraint.getAnnotation() + " ConstraintValidator for type "
          + targetType + ", found " + Ordering.usingToString().sortedCopy(best));
    }
    return Iterables.get(best, 0);
  }
View Full Code Here

        }
        else {
          className = clazz.getName();
        }
      }
      throw new UnexpectedTypeException( "No validator could be found for type: " + className );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validator classes which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

    return valueClass;
  }

  private void verifyResolveWasUnique(Type valueClass, List<Type> assignableClasses) {
    if ( assignableClasses.size() == 0 ) {
      throw new UnexpectedTypeException( "No validator could be found for type: " + valueClass );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validators which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

    return validatorTypes.get( suitableTypes.get( 0 ) );
  }

  private void verifyResolveWasUnique(Type valueClass, List<Type> assignableClasses) {
    if ( assignableClasses.size() == 0 ) {
      throw new UnexpectedTypeException( "No validator could be found for type: " + valueClass );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validator classes which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

        }
        else {
          className = clazz.getName();
        }
      }
      throw new UnexpectedTypeException( "No validator could be found for type: " + className );
    }
    else if ( assignableClasses.size() > 1 ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "There are multiple validator classes which could validate the type " );
      builder.append( valueClass );
      builder.append( ". The validator classes are: " );
      for ( Type clazz : assignableClasses ) {
        builder.append( clazz );
        builder.append( ", " );
      }
      builder.delete( builder.length() - 2, builder.length() );
      throw new UnexpectedTypeException( builder.toString() );
    }
  }
View Full Code Here

TOP

Related Classes of javax.validation.UnexpectedTypeException

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.