Package org.springmodules.validation.bean.conf

Examples of org.springmodules.validation.bean.conf.ValidationConfigurationException


     */
    protected void handlePropertyDefinition(Element propertyDefinition, Class clazz, MutableBeanValidationConfiguration configuration) {
        String propertyName = propertyDefinition.getAttribute(NAME_ATTR);
        if (!StringUtils.hasText(propertyName)) {
            logger.error("Could not parse property element. Missing or empty 'name' attribute");
            throw new ValidationConfigurationException("Could not parse property element. Missing 'name' attribute");
        }

        PropertyDescriptor propertyDescriptor = BeanUtils.getPropertyDescriptor(clazz, propertyName);
        if (propertyDescriptor == null) {
            logger.error("Property '" + propertyName + "' does not exist in class '" + clazz.getName() + "'");
        }

        if (propertyDefinition.hasAttribute(CASCADE_ATTR) && "true".equals(propertyDefinition.getAttribute(CASCADE_ATTR)))
        {
            CascadeValidation cascadeValidation = new CascadeValidation(propertyName);
            if (propertyDefinition.hasAttribute(CASCADE_CONDITION_ATTR)) {
                String conditionExpression = propertyDefinition.getAttribute(CASCADE_CONDITION_ATTR);
                cascadeValidation.setApplicabilityCondition(conditionExpressionParser.parse(conditionExpression));
            }
            configuration.addCascadeValidation(cascadeValidation);
        }

        NodeList nodes = propertyDefinition.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            Element ruleDefinition = (Element) node;
            PropertyValidationElementHandler handler = handlerRegistry.findPropertyHandler(ruleDefinition, clazz, propertyDescriptor);
            if (handler == null) {
                logger.error("Could not handle element '" + ruleDefinition.getTagName() +
                    "'. Please make sure the proper validation rule definition handler is registered");
                throw new ValidationConfigurationException("Could not handle element '" + ruleDefinition.getTagName() + "'");
            }
            handler.handle(ruleDefinition, propertyName, configuration);
        }
    }
View Full Code Here


    protected Validator constructValidator(String className) {
        try {
            Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
            if (!Validator.class.isAssignableFrom(clazz)) {
                throw new ValidationConfigurationException("class '" + className + "' is not a Validator implementation");
            }
            return (Validator) clazz.newInstance();
        } catch (ClassNotFoundException e) {
            throw new ValidationConfigurationException("Could not load validator class '" + className + "'");
        } catch (IllegalAccessException e) {
            throw new ValidationConfigurationException("Could not instantiate validator '" + className +
                "'. Make sure it has a default constructor.");
        } catch (InstantiationException e) {
            throw new ValidationConfigurationException("Could not instantiate validator '" + className +
                "'. Make sure it has a default constructor.");
        }
    }
View Full Code Here

            if (isFunctionDefinition(child)) {
                registerFunction(child, functionByName);
            } else if (isDateParserDefinition(child)) {
                registerDateParser(child, dateParsers);
            } else {
                throw new ValidationConfigurationException("unknown element '" + child.getTagName() + "'");
            }
        }

        builder.addPropertyValue("customFunctions", functionByName);
        builder.addPropertyValue("dateParsers", dateParsers);
View Full Code Here

    protected void registerFunction(Element functionDefinition, Map functionByName) {
        String name = functionDefinition.getAttribute(NAME_ATTR);
        String className = functionDefinition.getAttribute(CLASS_ATTR);
        if (!StringUtils.hasText(name) || !StringUtils.hasText(className)) {
            throw new ValidationConfigurationException("Both '" + NAME_ATTR + "' and '" + CLASS_ATTR +
                "' attributes of element '" + FUNCTION_ELEMENT + "' are required");
        }
        functionByName.put(name, className);
    }
View Full Code Here

    protected void registerDateParser(Element dateParserDefinition, Map patternByRegexp) {
        String regexp = dateParserDefinition.getAttribute(REGEXP_ATTR);
        String pattern = dateParserDefinition.getAttribute(PATTERN_ATTR);
        if (!StringUtils.hasText(regexp) || !StringUtils.hasText(pattern)) {
            throw new ValidationConfigurationException("Both '" + REGEXP_ATTR + "' and '" +
                PATTERN_ATTR + "' attributes of element '" + DATE_PARSER_ELEMENT + "' are required");
        }
        patternByRegexp.put(regexp, pattern);
    }
View Full Code Here

    }

    protected Resource createResource(Element resourceDefinition) {
        String path = resourceDefinition.getAttribute(LOCATION_ATTR);
        if (!StringUtils.hasText(path)) {
            throw new ValidationConfigurationException("Resoruce path is required and cannot be empty");
        }
        return new DefaultResourceLoader().getResource(path);
    }
View Full Code Here

            if (PropertyValidationElementHandler.class.isInstance(handler)) {
                propertyHandlers.add(handler);
            } else if (ClassValidationElementHandler.class.isInstance(handler)) {
                classHandlers.add(handler);
            } else {
                throw new ValidationConfigurationException("class '" + className + "' is not a property hanlder nor a class handler");
            }
        }
        registryBuilder.addPropertyValue(
            "extraPropertyHandlers",
            propertyHandlers.toArray(new PropertyValidationElementHandler[propertyHandlers.size()])
View Full Code Here

        Class<?> clazz;
        try {
            clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
            return clazz.newInstance();
        } catch (ClassNotFoundException cnfe) {
            throw new ValidationConfigurationException("Could not load class '" + className + "'", cnfe);
        } catch (IllegalAccessException iae) {
            throw new ValidationConfigurationException("Could not instantiate class '" + className + "'", iae);
        } catch (InstantiationException ie) {
            throw new ValidationConfigurationException("Could not instantiate class '" + className + "'", ie);
        }
    }
View Full Code Here

TOP

Related Classes of org.springmodules.validation.bean.conf.ValidationConfigurationException

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.