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


        }
        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",
                            "ReferenceConstraint annotaion must be on getter method only."));
                }
                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",
                            "Remote key must be String."));
                    }
                } catch (Exception ex) {
                    return false;
                }
View Full Code Here

          //todo: log that the validator cValidator was skipped b/c of a validation error
        }     
      }
    } else if(descriptor.getComposingConstraints().isEmpty()) {
      //empty constraint validation, fail
      throw new UnexpectedTypeException("No validator was found for " + descriptor.getAnnotation().annotationType().getName() + " with type " + value.getClass().getName());
    }
   
    //composed violation
    Set<ConstraintViolation<T>> composedViolations = new HashSet<ConstraintViolation<T>>();
   
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 validatorsTypes.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 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

            if (key.size() > 1) {
                final String message = "Factory returned " + key.size() + " validators";
                if (ParametersAccess.class.isInstance(access)) { // cross parameter
                    throw new ConstraintDefinitionException(message);
                }
                throw new UnexpectedTypeException(message);
            }

            @SuppressWarnings("unchecked")
            final ConstraintValidator<A, ? super T> validator = (ConstraintValidator<A, ? super T>) factory.getInstance(key.iterator().next());
            if (validator == null) {
View Full Code Here

            final String message = "No validator could be found for type " + stringForType(targetType)
                + ". See: @" + anno.annotationType().getSimpleName() + " at " + stringForLocation(owner, access);
            if (Object[].class.equals(targetType)) { // cross parameter
                throw new ConstraintDefinitionException(message);
            }
            throw new UnexpectedTypeException(message);
        } 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

            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",
                            "ReferenceConstraint annotaion must be on getter method only."));
                }
                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",
                            "Remote key must be String."));
                    }
                } catch (Exception ex) {
                    return false;
                }
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.