Package javax.validation

Examples of javax.validation.ConstraintDeclarationException


  public void initialize(DecimalMin minValue) {
    try {
      this.minValue = new BigDecimal( minValue.value() );
    }
    catch ( NumberFormatException nfe ) {
      throw new ConstraintDeclarationException( minValue.value() + " does not represent a valid BigDemcimal formt" );
    }
  }
View Full Code Here


  public void initialize(DecimalMin minValue) {
    try {
      this.minValue = new BigDecimal( minValue.value() );
    }
    catch ( NumberFormatException nfe ) {
      throw new ConstraintDeclarationException( minValue.value() + " does not represent a valid BigDemcimal formt" );
    }
  }
View Full Code Here

  public void initialize(DecimalMax maxValue) {
    try {
      this.maxValue = new BigDecimal( maxValue.value() );
    }
    catch ( NumberFormatException nfe ) {
      throw new ConstraintDeclarationException( maxValue.value() + " does not represent a valid BigDemcimal formt" );
    }
  }
View Full Code Here

  public void initialize(DecimalMax maxValue) {
    try {
      this.maxValue = new BigDecimal( maxValue.value() );
    }
    catch ( NumberFormatException nfe ) {
      throw new ConstraintDeclarationException( maxValue.value() + " does not represent a valid BigDemcimal formt" );
    }
  }
View Full Code Here

      if ( methodsWithParameterConstraints.isEmpty() ) {
        return null;
      }

      if ( methodsWithParameterConstraints.size() > 1 ) {
        return new ConstraintDeclarationException(
            "Only the root method of an overridden method in an inheritance hierarchy may be annotated with parameter constraints, " +
                "but there are parameter constraints defined at all of the following overridden methods: " +
                methodsWithParameterConstraints
        );
      }

      MethodMetaData constrainedMethod = methodsWithParameterConstraints.iterator().next();

      for ( MethodMetaData oneMethod : allMethods ) {

        if ( !constrainedMethod.getMethod()
            .getDeclaringClass()
            .isAssignableFrom( oneMethod.getMethod().getDeclaringClass() ) ) {
          return new ConstraintDeclarationException(
              "Only the root method of an overridden method in an inheritance hierarchy may be annotated with parameter constraints. " +
                  "The following method itself has no parameter constraints but it is not defined on a sub-type of " +
                  constrainedMethod.getMethod().getDeclaringClass() + ": " + oneMethod
          );
        }
View Full Code Here

            // Search for the overrides to apply
            ConstraintOverrides generalOverride = findOverride(composite.getAnnotation().annotationType(), -1);
            if (generalOverride != null) {
                if (index > 0) {
                    throw new ConstraintDeclarationException("Wrong OverridesAttribute declaration for "
                        + generalOverride.constraintType
                        + ", it needs a defined index when there is a list of constraints");
                }
                generalOverride.applyOn(composite);
            }
View Full Code Here

    private final Class<?> from;

    public GroupConversionDescriptorImpl(final Group from, final Group to) {
        this.from = from.getGroup();
        if (this.from.getAnnotation(GroupSequence.class) != null) {
            throw new ConstraintDeclarationException("from() can't get a group sequence");
        }

        this.to = to.getGroup();
    }
View Full Code Here

            }
            annotations.clear();
        }

        if (!edesc.getGroupConversions().isEmpty() && !edesc.isCascaded()) {
            throw new ConstraintDeclarationException("@Valid is needed for group conversion");
        }
    }
View Full Code Here

                        processAnnotations(consDesc, paramAnnos.getAnnotations(), access, idx, names.get(idx));
                    }
                }

                if (!consDesc.getGroupConversions().isEmpty() && !consDesc.isCascaded()) {
                    throw new ConstraintDeclarationException("@Valid is needed to define a group conversion");
                }

                ensureNotNullDescriptors(cons.getDeclaringClass(), consDesc);
            }
        }
View Full Code Here

                        if (parentDesc != null) {
                            final Iterator<ParameterDescriptor> parentPd = parentDesc.getParameterDescriptors().iterator();
                            for (final ParameterDescriptor pd : methodDesc.getParameterDescriptors()) {
                                final ParameterDescriptor next = parentPd.next();
                                if (pd.getConstraintDescriptors().size() != next.getConstraintDescriptors().size()) {
                                    throw new ConstraintDeclarationException("child shouldn't get more constraint than parent");
                                }
                                if (pd.isCascaded() != next.isCascaded()) { // @Valid
                                    throw new ConstraintDeclarationException("child shouldn't get more constraint than parent");
                                }
                            }
                        } else {
                            ensureMethodDoesntDefineParameterConstraint(methodDesc);
                        }
                    }

                    final Class<?>[] interfaces = method.getDeclaringClass().getInterfaces();
                    final Collection<Method> itfWithThisMethod = new ArrayList<Method>();
                    for (final Class<?> i : interfaces) {
                        final Method m = Reflection.INSTANCE.getDeclaredMethod(i, method.getName(), method.getParameterTypes());
                        if (m != null) {
                            itfWithThisMethod.add(m);
                        }
                    }
                    if (itfWithThisMethod.size() > 1) {
                        for (final Method m : itfWithThisMethod) {
                            ensureNoConvertGroup(m, "ConvertGroup can't be used in parallel interfaces");
                        }
                    } else if (itfWithThisMethod.size() == 1) {
                        ensureNoConvertGroup(itfWithThisMethod.iterator().next(), "ConvertGroup can't be used in interface AND parent class");
                    }

                    int returnValid = 0;
                    if (method.getAnnotation(Valid.class) != null) {
                        returnValid++;
                    }
                    for (final Class<?> clazz : classHierarchy) {
                        final Method overriden = Reflection.INSTANCE.getDeclaredMethod(clazz, method.getName(), method.getParameterTypes());
                        if (overriden != null) {
                            if (overriden.getAnnotation(Valid.class) != null) {
                                returnValid++;
                            }
                        }
                    }
                    if (returnValid > 1 && !(interfaces.length == returnValid && method.getAnnotation(Valid.class) == null)) {
                        throw new ConstraintDeclarationException("@Valid on returned value can't be set more than once");
                    }
                }

                if (getter) {
                    final MetaProperty prop = metaBean.getProperty(Introspector.decapitalize(method.getName().substring(3)));
                    if (prop != null && prop.getFeature(Features.Property.REF_CASCADE) != null) {
                        methodDesc.setCascaded(true);
                    }
                }

                if (!methodDesc.getGroupConversions().isEmpty() && !methodDesc.isCascaded()) {
                    throw new ConstraintDeclarationException("@Valid is needed to define a group conversion");
                }
            }

            for (final Class<?> parent : classHierarchy) {
                final BeanDescriptorImpl desc = BeanDescriptorImpl.class.cast(factoryContext.getValidator().getConstraintsForClass(parent));
View Full Code Here

TOP

Related Classes of javax.validation.ConstraintDeclarationException

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.