Package javax.validation

Examples of javax.validation.ValidationException


                                      String defaultPackage) {
        List<String> getterNames = new ArrayList<String>();
        for (GetterType getterType : getters) {
            String getterName = getterType.getName();
            if (getterNames.contains(getterName)) {
                throw new ValidationException(getterName +
                      " is defined more than once in mapping xml for bean " +
                      beanClass.getName());
            } else {
                getterNames.add(getterName);
            }
            final Method method = SecureActions.getGetter(beanClass, getterName);
            if (method == null) {
                throw new ValidationException(
                      beanClass.getName() + " does not contain the property  " + getterName);
            }

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


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

            Class<?> clazz = loadClass(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<?,?>>> classes = new ArrayList();
            /*
             If include-existing-validator is set to false,
             ConstraintValidator defined on the constraint annotation are ignored.
              */
            if (validatedByType.isIncludeExistingValidators() != null &&
                  validatedByType.isIncludeExistingValidators()) {
                /*
                 If set to true, the list of ConstraintValidators described in XML
                 are concatenated to the list of ConstraintValidator described on the
                 annotation to form a new array of ConstraintValidator evaluated.
                 */
                classes.addAll(findConstraintValidatorClasses(annotationClass));
            }
            for (JAXBElement<String> validatorClassName : validatedByType.getValue()) {
                Class<? extends ConstraintValidator<?, ?>> validatorClass;
                validatorClass = (Class<? extends ConstraintValidator<?, ?>>) SecureActions
                      .loadClass(validatorClassName.getValue(), this.getClass());


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

                /*
                Annotation based ConstraintValidator come before XML based
                ConstraintValidator in the array. The new list is returned
                by ConstraintDescriptor.getConstraintValidatorClasses().
                 */
                if (!classes.contains(validatorClass)) classes.add(validatorClass);
            }
            if (factory.getConstraintsCache().containsConstraintValidator(annotationClass)) {
                throw new ValidationException("Constraint validator for " +
                      annotationClass.getName() + " already configured.");
            } else {
                factory.getConstraintsCache().putConstraintValidator(annotationClass,
                      classes.toArray(new Class[classes.size()]));
            }
View Full Code Here

                        (Class<? extends T>) cls;
                    return SecureActions.newInstance(implClass);
                }
            } catch (ClassNotFoundException e) {
            }
            throw new ValidationException("Type " + type + " not supported");
        }
    }
View Full Code Here

    public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Method method, Object[] parameters,
        Class<?>... groupArray) {
        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
        if (methodDescriptor == null) {
            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
        }
        return validateParameters(methodDescriptor.getMetaBean(), methodDescriptor.getParameterDescriptors(),
            parameters, groupArray);
    }
View Full Code Here

    public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method, Object parameter,
        int parameterIndex, Class<?>... groupArray) {
        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
        if (methodDescriptor == null) {
            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
        }
        ParameterDescriptorImpl paramDesc =
            (ParameterDescriptorImpl) methodDescriptor.getParameterDescriptors().get(parameterIndex);
        return validateParameter(paramDesc, parameter, groupArray);
    }
View Full Code Here

        Object[] parameters, Class<?>... groupArray) {
        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
        ConstructorDescriptorImpl constructorDescriptor =
            (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
        if (constructorDescriptor == null) {
            throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
        }
        return validateParameters(constructorDescriptor.getMetaBean(), constructorDescriptor.getParameterDescriptors(),
            parameters, groupArray);
    }
View Full Code Here

        Object parameter, int parameterIndex, Class<?>... groupArray) {
        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
        ConstructorDescriptorImpl constructorDescriptor =
            (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
        if (constructorDescriptor == null) {
            throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
        }
        ParameterDescriptorImpl paramDesc =
            (ParameterDescriptorImpl) constructorDescriptor.getParameterDescriptors().get(parameterIndex);
        return validateParameter(paramDesc, parameter, groupArray);
    }
View Full Code Here

    public <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz, Method method, Object returnedValue,
        Class<?>... groupArray) {
        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
        if (methodDescriptor == null) {
            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
        }
        final GroupValidationContext<Object> context =
            createContext(methodDescriptor.getMetaBean(), returnedValue, null, groupArray);
        validateReturnedValueInContext(context, methodDescriptor);
        ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
View Full Code Here

        this.annotation = annotation;
        if (member != null) {
            accessStrategy = createAccessStrategy(member);
            if (accessStrategy == null || accessStrategy.getPropertyName() ==
                  null) { // can happen if method does not follow the bean convention
                throw new ValidationException(
                      "Annotated method does not follow the JavaBeans naming convention: " +
                            member);
            }
        } else {
            this.accessStrategy = null;
View Full Code Here

                edesc = createBeanDescriptor(metaBean);
                metaBean.putFeature(Jsr303Features.Bean.BEAN_DESCRIPTOR, edesc);
            }
            return edesc;
        } catch (RuntimeException ex) {
            throw new ValidationException("error retrieving constraints for "
                + clazz, ex);
        }
    }
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.