You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by ma...@apache.org on 2010/03/17 05:39:14 UTC

svn commit: r924153 [7/13] - in /incubator/bval/trunk: ./ agimatec-jsr303/ agimatec-jsr303/src/ agimatec-jsr303/src/main/ agimatec-jsr303/src/main/java/ agimatec-jsr303/src/main/java/com/ agimatec-jsr303/src/main/java/com/agimatec/ agimatec-jsr303/src/...

Added: incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationMappingParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationMappingParser.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationMappingParser.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationMappingParser.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,485 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package com.agimatec.validation.jsr303.xml;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.util.ConverterUtils;
+import com.agimatec.validation.jsr303.util.SecureActions;
+import com.agimatec.validation.util.FieldAccess;
+import com.agimatec.validation.util.MethodAccess;
+
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.Payload;
+import javax.validation.ValidationException;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.*;
+
+
+/**
+ * Uses JAXB to parse constraints.xml based on validation-mapping-1.0.xsd.<br>
+ * Copyright: Agimatec GmbH, 2009
+ */
+public class ValidationMappingParser {
+    //    private static final Log log = LogFactory.getLog(ValidationMappingParser.class);
+    private static final String VALIDATION_MAPPING_XSD = "META-INF/validation-mapping-1.0.xsd";
+    private static final String[] RESERVED_PARAMS = {"message", "groups", "payload"};
+
+    private final Set<Class> processedClasses;
+    private final AgimatecValidatorFactory factory;
+
+    public ValidationMappingParser(AgimatecValidatorFactory factory) {
+        this.factory = factory;
+        this.processedClasses = new HashSet<Class>();
+    }
+
+    /**
+     * parse files with constraint mappings and collect information in the factory.
+     *  
+     * @param xmlStreams - one or more contraints.xml file streams to parse
+     */
+    public void processMappingConfig(Set<InputStream> xmlStreams) throws ValidationException {
+        for (InputStream xmlStream : xmlStreams) {
+            ConstraintMappingsType mapping = parseXmlMappings(xmlStream);
+
+            String defaultPackage = mapping.getDefaultPackage();
+            processConstraintDefinitions(mapping.getConstraintDefinition(), defaultPackage);
+            for (BeanType bean : mapping.getBean()) {
+                Class<?> beanClass = loadClass(bean.getClazz(), defaultPackage);
+                if (!processedClasses.add(beanClass)) {
+                    // spec: A given class must not be described more than once amongst all
+                    //  the XML mapping descriptors.
+                    throw new ValidationException(
+                          beanClass.getName() + " has already be configured in xml.");
+                }
+                factory.getAnnotationIgnores()
+                      .setDefaultIgnoreAnnotation(beanClass, bean.isIgnoreAnnotations());
+                processClassLevel(bean.getClassType(), beanClass, defaultPackage);
+                processFieldLevel(bean.getField(), beanClass, defaultPackage);
+                processPropertyLevel(bean.getGetter(), beanClass, defaultPackage);
+                processedClasses.add(beanClass);
+            }
+        }
+    }
+
+    /** @param in XML stream to parse using the validation-mapping-1.0.xsd */
+    private ConstraintMappingsType parseXmlMappings(InputStream in) {
+        ConstraintMappingsType mappings;
+        try {
+            JAXBContext jc = JAXBContext.newInstance(ConstraintMappingsType.class);
+            Unmarshaller unmarshaller = jc.createUnmarshaller();
+            unmarshaller.setSchema(getSchema());
+            StreamSource stream = new StreamSource(in);
+            JAXBElement<ConstraintMappingsType> root =
+                  unmarshaller.unmarshal(stream, ConstraintMappingsType.class);
+            mappings = root.getValue();
+        } catch (JAXBException e) {
+            throw new ValidationException("Failed to parse XML deployment descriptor file.",
+                  e);
+        }
+        return mappings;
+    }
+
+    /** @return validation-mapping-1.0.xsd based schema */
+    private Schema getSchema() {
+        return ValidationParser.getSchema(VALIDATION_MAPPING_XSD);
+    }
+
+    private void processClassLevel(ClassType classType, Class<?> beanClass,
+                                   String defaultPackage) {
+        if (classType == null) {
+            return;
+        }
+
+        // ignore annotation
+        if (classType.isIgnoreAnnotations() != null) {
+            factory.getAnnotationIgnores()
+                  .setIgnoreAnnotationsOnClass(beanClass, classType.isIgnoreAnnotations());
+        }
+
+        // group sequence
+        Class<?>[] groupSequence =
+              createGroupSequence(classType.getGroupSequence(), defaultPackage);
+        if (groupSequence != null) {
+            factory.addDefaultSequence(beanClass, groupSequence);
+        }
+
+        // constraints
+        for (ConstraintType constraint : classType.getConstraint()) {
+            MetaConstraint<?, ?> metaConstraint =
+                  createConstraint(constraint, beanClass, null, defaultPackage);
+            factory.addMetaConstraint(beanClass, metaConstraint);
+        }
+    }
+
+    private <A extends Annotation, T> MetaConstraint<?, ?> createConstraint(
+          ConstraintType constraint, Class<T> beanClass, Member member,
+          String defaultPackage) {
+        Class<A> annotationClass =
+              (Class<A>) loadClass(constraint.getAnnotation(), defaultPackage);
+        AnnotationProxyBuilder<A> annoBuilder = new AnnotationProxyBuilder<A>(annotationClass);
+
+        if (constraint.getMessage() != null) {
+            annoBuilder.setMessage(constraint.getMessage());
+        }
+        annoBuilder.setGroups(getGroups(constraint.getGroups(), defaultPackage));
+        annoBuilder.setPayload(getPayload(constraint.getPayload(), defaultPackage));
+
+        for (ElementType elementType : constraint.getElement()) {
+            String name = elementType.getName();
+            checkValidName(name);
+            Class<?> returnType = getAnnotationParameterType(annotationClass, name);
+            Object elementValue = getElementValue(elementType, returnType, defaultPackage);
+            annoBuilder.putValue(name, elementValue);
+        }
+        return new MetaConstraint<T, A>(beanClass, member, annoBuilder.createAnnotation());
+    }
+
+    private void checkValidName(String name) {
+        for (String each : RESERVED_PARAMS) {
+            if (each.equals(name)) {
+                throw new ValidationException(each + " is a reserved parameter name.");
+            }
+        }
+    }
+
+    private <A extends Annotation> Class<?> getAnnotationParameterType(
+          Class<A> annotationClass, String name) {
+        Method m = SecureActions.getMethod(annotationClass, name);
+        if (m == null) {
+            throw new ValidationException("Annotation of type " + annotationClass.getName() +
+                  " does not contain a parameter " + name + ".");
+        }
+        return m.getReturnType();
+    }
+
+    private Object getElementValue(ElementType elementType, Class<?> returnType,
+                                   String defaultPackage) {
+        removeEmptyContentElements(elementType);
+
+        boolean isArray = returnType.isArray();
+        if (!isArray) {
+            if (elementType.getContent().size() != 1) {
+                throw new ValidationException(
+                      "Attempt to specify an array where single value is expected.");
+            }
+            return getSingleValue(elementType.getContent().get(0), returnType, defaultPackage);
+        } else {
+            List<Object> values = new ArrayList<Object>();
+            for (Serializable s : elementType.getContent()) {
+                values.add(getSingleValue(s, returnType.getComponentType(), defaultPackage));
+            }
+            return values.toArray(
+                  (Object[]) Array.newInstance(returnType.getComponentType(), values.size()));
+        }
+    }
+
+    private void removeEmptyContentElements(ElementType elementType) {
+        List<Serializable> contentToDelete = new ArrayList<Serializable>();
+        for (Serializable content : elementType.getContent()) {
+            if (content instanceof String && ((String) content).matches("[\\n ].*")) {
+                contentToDelete.add(content);
+            }
+        }
+        elementType.getContent().removeAll(contentToDelete);
+    }
+
+    private Object getSingleValue(Serializable serializable, Class<?> returnType,
+                                  String defaultPackage) {
+
+        Object returnValue;
+        if (serializable instanceof String) {
+            String value = (String) serializable;
+            returnValue = convertToResultType(returnType, value, defaultPackage);
+        } else if (serializable instanceof JAXBElement &&
+              ((JAXBElement) serializable).getDeclaredType()
+                    .equals(String.class)) {
+            JAXBElement<?> elem = (JAXBElement<?>) serializable;
+            String value = (String) elem.getValue();
+            returnValue = convertToResultType(returnType, value, defaultPackage);
+        } else if (serializable instanceof JAXBElement &&
+              ((JAXBElement) serializable).getDeclaredType()
+                    .equals(AnnotationType.class)) {
+            JAXBElement<?> elem = (JAXBElement<?>) serializable;
+            AnnotationType annotationType = (AnnotationType) elem.getValue();
+            try {
+                Class<Annotation> annotationClass = (Class<Annotation>) returnType;
+                returnValue =
+                      createAnnotation(annotationType, annotationClass, defaultPackage);
+            } catch (ClassCastException e) {
+                throw new ValidationException("Unexpected parameter value");
+            }
+        } else {
+            throw new ValidationException("Unexpected parameter value");
+        }
+        return returnValue;
+
+    }
+
+    private Object convertToResultType(Class<?> returnType, String value,
+                                       String defaultPackage) {
+        /**
+         * Class is represented by the fully qualified class name of the class.
+         * spec: Note that if the raw string is unqualified,
+         * default package is taken into account.
+         */
+        if (returnType.equals(Class.class)) {
+            value = toQualifiedClassName(value, defaultPackage);
+        }
+        return ConverterUtils.fromStringToType(value, returnType);
+    }
+
+    private <A extends Annotation> Annotation createAnnotation(AnnotationType annotationType,
+                                                               Class<A> returnType,
+                                                               String defaultPackage) {
+        AnnotationProxyBuilder<A> metaAnnotation = new AnnotationProxyBuilder<A>(returnType);
+        for (ElementType elementType : annotationType.getElement()) {
+            String name = elementType.getName();
+            Class<?> parameterType = getAnnotationParameterType(returnType, name);
+            Object elementValue = getElementValue(elementType, parameterType, defaultPackage);
+            metaAnnotation.putValue(name, elementValue);
+        }
+        return metaAnnotation.createAnnotation();
+    }
+
+    private Class<?>[] getGroups(GroupsType groupsType, String defaultPackage) {
+        if (groupsType == null) {
+            return new Class[]{};
+        }
+
+        List<Class<?>> groupList = new ArrayList<Class<?>>();
+        for (JAXBElement<String> groupClass : groupsType.getValue()) {
+            groupList.add(loadClass(groupClass.getValue(), defaultPackage));
+        }
+        return groupList.toArray(new Class[groupList.size()]);
+    }
+
+
+    private Class<? extends Payload>[] getPayload(PayloadType payloadType,
+                                                  String defaultPackage) {
+        if (payloadType == null) {
+            return new Class[]{};
+        }
+
+        List<Class<? extends Payload>> payloadList = new ArrayList<Class<? extends Payload>>();
+        for (JAXBElement<String> groupClass : payloadType.getValue()) {
+            Class<?> payload = loadClass(groupClass.getValue(), defaultPackage);
+            if (!Payload.class.isAssignableFrom(payload)) {
+                throw new ValidationException("Specified payload class " + payload.getName() +
+                      " does not implement javax.validation.Payload");
+            } else {
+                payloadList.add((Class<? extends Payload>) payload);
+            }
+        }
+        return payloadList.toArray(new Class[payloadList.size()]);
+    }
+
+    private Class<?>[] createGroupSequence(GroupSequenceType groupSequenceType,
+                                               String defaultPackage) {
+        if (groupSequenceType != null) {
+            Class<?>[] groupSequence = new Class<?>[groupSequenceType.getValue().size()];
+            int i=0;
+            for (JAXBElement<String> groupName : groupSequenceType.getValue()) {
+                Class<?> group = loadClass(groupName.getValue(), defaultPackage);
+                groupSequence[i++] = group;
+            }
+            return groupSequence;
+        } else {
+            return null;
+        }
+    }
+
+    private void processFieldLevel(List<FieldType> fields, Class<?> beanClass,
+                                   String defaultPackage) {
+        List<String> fieldNames = new ArrayList<String>();
+        for (FieldType fieldType : fields) {
+            String fieldName = fieldType.getName();
+            if (fieldNames.contains(fieldName)) {
+                throw new ValidationException(fieldName +
+                      " is defined more than once in mapping xml for bean " +
+                      beanClass.getName());
+            } else {
+                fieldNames.add(fieldName);
+            }
+            final Field field = SecureActions.getDeclaredField(beanClass, fieldName);
+            if (field == null) {
+                throw new ValidationException(
+                      beanClass.getName() + " does not contain the fieldType  " + fieldName);
+            }
+
+            // ignore annotations
+            boolean ignoreFieldAnnotation = fieldType.isIgnoreAnnotations() == null ? false :
+                  fieldType.isIgnoreAnnotations();
+            if (ignoreFieldAnnotation) {
+                factory.getAnnotationIgnores().setIgnoreAnnotationsOnMember(field);
+            }
+
+            // valid
+            if (fieldType.getValid() != null) {
+                factory.addValid(beanClass, new FieldAccess(field));
+            }
+
+            // constraints
+            for (ConstraintType constraintType : fieldType.getConstraint()) {
+                MetaConstraint<?, ?> constraint =
+                      createConstraint(constraintType, beanClass, field, defaultPackage);
+                factory.addMetaConstraint(beanClass, constraint);
+            }
+        }
+    }
+
+    private void processPropertyLevel(List<GetterType> getters, Class<?> beanClass,
+                                      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 :
+                  getterType.isIgnoreAnnotations();
+            if (ignoreGetterAnnotation) {
+                factory.getAnnotationIgnores().setIgnoreAnnotationsOnMember(method);
+            }
+
+            // valid
+            if (getterType.getValid() != null) {
+                factory.addValid(beanClass, new MethodAccess(getterName, method));
+            }
+
+            // constraints
+            for (ConstraintType constraintType : getterType.getConstraint()) {
+                MetaConstraint<?, ?> metaConstraint =
+                      createConstraint(constraintType, beanClass, method, defaultPackage);
+                factory.addMetaConstraint(beanClass, metaConstraint);
+            }
+        }
+    }
+
+    private void processConstraintDefinitions(
+          List<ConstraintDefinitionType> constraintDefinitionList, String defaultPackage) {
+        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()]));
+            }
+        }
+    }
+
+    private List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> findConstraintValidatorClasses(
+          Class<? extends Annotation> annotationType) {
+        List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> classes =
+              new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
+
+        Class<? extends ConstraintValidator<?, ?>>[] validator =
+              factory.getDefaultConstraints().getValidatorClasses(annotationType);
+        if (validator != null) {
+            classes
+                  .addAll(Arrays.asList(validator));
+        } else {
+            Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType
+                  .getAnnotation(Constraint.class)
+                  .validatedBy();
+            classes.addAll(Arrays.asList(validatedBy));
+        }
+        return classes;
+    }
+
+    private Class<?> loadClass(String className, String defaultPackage) {
+        return SecureActions
+              .loadClass(toQualifiedClassName(className, defaultPackage), this.getClass());
+    }
+
+    private String toQualifiedClassName(String className, String defaultPackage) {
+        if (!isQualifiedClass(className)) {
+            className = defaultPackage + "." + className;
+        }
+        return className;
+    }
+
+    private boolean isQualifiedClass(String clazz) {
+        return clazz.contains(".");
+    }
+
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationParser.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationParser.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/java/com/agimatec/validation/jsr303/xml/ValidationParser.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agimatec.validation.jsr303.xml;
+
+import com.agimatec.validation.jsr303.ConfigurationImpl;
+import com.agimatec.validation.jsr303.util.SecureActions;
+import com.agimatec.validation.util.PrivilegedActions;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.SAXException;
+
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
+import javax.validation.spi.ValidationProvider;
+import javax.xml.XMLConstants;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * Description: uses jaxb to parse validation.xml<br/>
+ * User: roman <br/>
+ * Date: 24.11.2009 <br/>
+ * Time: 16:48:55 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class ValidationParser {
+    private static final String DEFAULT_VALIDATION_XML_FILE = "META-INF/validation.xml";
+    private static final String VALIDATION_CONFIGURATION_XSD =
+          "META-INF/validation-configuration-1.0.xsd";
+    private static final Log log = LogFactory.getLog(ValidationParser.class);
+    private final String validationXmlFile;
+
+    public ValidationParser(String file) {
+        if(file == null) {
+            validationXmlFile = DEFAULT_VALIDATION_XML_FILE;
+        } else {
+            validationXmlFile = file;
+        }
+    }
+
+    public void processValidationConfig(ConfigurationImpl targetConfig) {
+        ValidationConfigType xmlConfig = parseXmlConfig();
+        if (xmlConfig != null) {
+            applyConfig(xmlConfig, targetConfig);
+        }
+    }
+
+    private ValidationConfigType parseXmlConfig() {
+        try {
+            InputStream inputStream = getInputStream(validationXmlFile);
+            if (inputStream == null) {
+                if (log.isDebugEnabled()) log.debug("No " + validationXmlFile +
+                      " found. Using annotation based configuration only.");
+                return null;
+            }
+
+            if (log.isInfoEnabled()) log.info(validationXmlFile + " found.");
+
+            Schema schema = getSchema();
+            JAXBContext jc = JAXBContext.newInstance(ValidationConfigType.class);
+            Unmarshaller unmarshaller = jc.createUnmarshaller();
+            unmarshaller.setSchema(schema);
+            StreamSource stream = new StreamSource(inputStream);
+            JAXBElement<ValidationConfigType> root =
+                  unmarshaller.unmarshal(stream, ValidationConfigType.class);
+            return root.getValue();
+        } catch (JAXBException e) {
+            throw new ValidationException("Unable to parse " + validationXmlFile, e);
+        } catch (IOException e) {
+            throw new ValidationException("Unable to parse " + validationXmlFile, e);
+        }
+    }
+
+    private InputStream getInputStream(String path) throws IOException {
+        ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
+        Enumeration<URL> urls = loader.getResources(path);
+        if (urls.hasMoreElements()) {
+            URL url = urls.nextElement();
+            if (urls.hasMoreElements()) {
+                // spec says: If more than one META-INF/validation.xml file
+                // is found in the classpath, a ValidationException is raised.
+                throw new ValidationException(
+                      "More than one " + path + " is found in the classpath");
+            }
+            return url.openStream();
+        } else {
+            return null;
+        }
+    }
+
+    private Schema getSchema() {
+        return getSchema(VALIDATION_CONFIGURATION_XSD);
+    }
+
+    static Schema getSchema(String xsd) {
+        ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class);
+        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        URL schemaUrl = loader.getResource(xsd);
+        try {
+            return sf.newSchema(schemaUrl);
+        } catch (SAXException e) {
+            log.warn("Unable to parse schema: " + xsd, e);
+            return null;
+        }
+    }
+
+    private void applyConfig(ValidationConfigType xmlConfig, ConfigurationImpl targetConfig) {
+        applyProviderClass(xmlConfig, targetConfig);
+        applyMessageInterpolator(xmlConfig, targetConfig);
+        applyTraversableResolver(xmlConfig, targetConfig);
+        applyConstraintFactory(xmlConfig, targetConfig);
+        applyMappingStreams(xmlConfig, targetConfig);
+        applyProperties(xmlConfig, targetConfig);
+    }
+
+    private void applyProperties(ValidationConfigType xmlConfig, ConfigurationImpl target) {
+        for (PropertyType property : xmlConfig.getProperty()) {
+            if (log.isDebugEnabled()) {
+                log.debug("Found property '" + property.getName() + "' with value '" +
+                      property.getValue() + "' in " + validationXmlFile);
+            }
+            target.addProperty(property.getName(), property.getValue());
+        }
+    }
+
+    private void applyProviderClass(ValidationConfigType xmlConfig, ConfigurationImpl target) {
+        String providerClassName = xmlConfig.getDefaultProvider();
+        if (providerClassName != null) {
+            Class<? extends ValidationProvider<?>> clazz =
+                  (Class<? extends ValidationProvider<?>>) SecureActions
+                        .loadClass(providerClassName, this.getClass());
+            target.setProviderClass(clazz);
+            if (log.isInfoEnabled())
+                log.info("Using " + providerClassName + " as validation provider.");
+        }
+    }
+
+    private void applyMessageInterpolator(ValidationConfigType xmlConfig,
+                                          ConfigurationImpl target) {
+        String messageInterpolatorClass = xmlConfig.getMessageInterpolator();
+        if (messageInterpolatorClass != null) {
+            Class<MessageInterpolator> clazz = (Class<MessageInterpolator>) SecureActions
+                  .loadClass(messageInterpolatorClass, this.getClass());
+            target.messageInterpolator(SecureActions.newInstance(clazz));
+            if (log.isInfoEnabled())
+                log.info("Using " + messageInterpolatorClass + " as message interpolator.");
+
+        }
+    }
+
+    private void applyTraversableResolver(ValidationConfigType xmlConfig,
+                                          ConfigurationImpl target) {
+        String traversableResolverClass = xmlConfig.getTraversableResolver();
+        if (traversableResolverClass != null) {
+            Class<TraversableResolver> clazz = (Class<TraversableResolver>) SecureActions
+                  .loadClass(traversableResolverClass, this.getClass());
+            target.traversableResolver(SecureActions.newInstance(clazz));
+            if (log.isInfoEnabled())
+                log.info("Using " + traversableResolverClass + " as traversable resolver.");
+        }
+    }
+
+    private void applyConstraintFactory(ValidationConfigType xmlConfig,
+                                        ConfigurationImpl target) {
+        String constraintFactoryClass = xmlConfig.getConstraintValidatorFactory();
+        if (constraintFactoryClass != null) {
+            Class<ConstraintValidatorFactory> clazz =
+                  (Class<ConstraintValidatorFactory>) SecureActions
+                        .loadClass(constraintFactoryClass, this.getClass());
+            target.constraintValidatorFactory(SecureActions.newInstance(clazz));
+            if (log.isInfoEnabled())
+                log.info("Using " + constraintFactoryClass + " as constraint factory.");
+        }
+    }
+
+    private void applyMappingStreams(ValidationConfigType xmlConfig,
+                                     ConfigurationImpl target) {
+        for (JAXBElement<String> mappingFileName : xmlConfig.getConstraintMapping()) {
+            if (log.isInfoEnabled()) {
+                log.info(
+                      "Trying to open input stream for " + mappingFileName.getValue());
+            }
+            InputStream in;
+            try {
+                in = getInputStream(mappingFileName.getValue());
+                if (in == null) {
+                    throw new ValidationException(
+                          "Unable to open input stream for mapping file " +
+                                mappingFileName.getValue());
+                }
+            } catch (IOException e) {
+                throw new ValidationException("Unable to open input stream for mapping file " +
+                      mappingFileName.getValue(), e);
+            }
+            target.addMapping(in);
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/main/resources/META-INF/services/javax.validation.spi.ValidationProvider
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/resources/META-INF/services/javax.validation.spi.ValidationProvider?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/resources/META-INF/services/javax.validation.spi.ValidationProvider (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/resources/META-INF/services/javax.validation.spi.ValidationProvider Wed Mar 17 04:39:07 2010
@@ -0,0 +1 @@
+com.agimatec.validation.jsr303.AgimatecValidationProvider
\ No newline at end of file

Added: incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/DefaultConstraints.properties
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/DefaultConstraints.properties?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/DefaultConstraints.properties (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/DefaultConstraints.properties Wed Mar 17 04:39:07 2010
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# configuration for mapping of javax.validation.constraints to ConstraintValidator implementations
+# the annotations from the JSR303 validation-api are mentioned here, but you could
+# also extend the configuration to get a default implementation for other constraint-annotations.
+# format: key=constraint-annotation-class value=constraint-validator-class (multiple classes: comma-separated)
+
+javax.validation.constraints.AssertFalse=com.agimatec.validation.constraints.AssertFalseValidator
+javax.validation.constraints.AssertTrue=com.agimatec.validation.constraints.AssertTrueValidator
+javax.validation.constraints.DecimalMax=com.agimatec.validation.constraints.DecimalMaxValidatorForNumber,\
+  com.agimatec.validation.constraints.DecimalMaxValidatorForString
+javax.validation.constraints.DecimalMin=com.agimatec.validation.constraints.DecimalMinValidatorForNumber,\
+  com.agimatec.validation.constraints.DecimalMinValidatorForString
+javax.validation.constraints.Digits=com.agimatec.validation.constraints.DigitsValidatorForNumber,\
+  com.agimatec.validation.constraints.DigitsValidatorForString
+javax.validation.constraints.Future=com.agimatec.validation.constraints.FutureValidatorForDate,\
+  com.agimatec.validation.constraints.FutureValidatorForCalendar
+javax.validation.constraints.Max=com.agimatec.validation.constraints.MaxValidatorForNumber,\
+  com.agimatec.validation.constraints.MaxValidatorForString
+javax.validation.constraints.Min=com.agimatec.validation.constraints.MinValidatorForNumber,\
+  com.agimatec.validation.constraints.MinValidatorForString
+javax.validation.constraints.NotNull=com.agimatec.validation.constraints.NotNullValidator
+javax.validation.constraints.Null=com.agimatec.validation.constraints.NullValidator
+javax.validation.constraints.Past=com.agimatec.validation.constraints.PastValidatorForDate,\
+  com.agimatec.validation.constraints.PastValidatorForCalendar
+javax.validation.constraints.Size=com.agimatec.validation.constraints.SizeValidatorForString,\
+  com.agimatec.validation.constraints.SizeValidatorForMap,\
+  com.agimatec.validation.constraints.SizeValidatorForCollection,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfBoolean,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfByte,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfChar,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfDouble,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfFloat,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfInt,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfLong,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfObject,\
+  com.agimatec.validation.constraints.SizeValidatorForArrayOfShort
+javax.validation.constraints.Pattern=com.agimatec.validation.constraints.PatternValidator

Added: incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/ValidationMessages.properties
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/ValidationMessages.properties?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/ValidationMessages.properties (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/resources/com/agimatec/validation/jsr303/ValidationMessages.properties Wed Mar 17 04:39:07 2010
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# The properties listed below are resolved by the default message resolver.
+
+# standard
+javax.validation.constraints.Null.message=must be null
+javax.validation.constraints.NotNull.message=may not be null
+javax.validation.constraints.AssertTrue.message=must be true
+javax.validation.constraints.AssertFalse.message=must be false
+javax.validation.constraints.Min.message=must be greater than or equal to {value}
+javax.validation.constraints.Max.message=must be less than or equal to {value}
+javax.validation.constraints.Size.message=size must be between {min} and {max}
+javax.validation.constraints.Digits.message=numeric value out of bounds (<{integer} digits>.<{fraction} digits> expected)
+javax.validation.constraints.Past.message=must be a past date
+javax.validation.constraints.Future.message=must be a future date
+javax.validation.constraints.Pattern.message=must match the following regular expression: {regex}
+
+# agimatec additional built-ins
+com.agimatec.validation.constraints.NotEmpty.message=may not be empty
+com.agimatec.validation.constraints.Email.message=not a well-formed email address

Added: incubator/bval/trunk/agimatec-jsr303/src/main/xjb/binding-customization.xjb
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/xjb/binding-customization.xjb?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/xjb/binding-customization.xjb (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/xjb/binding-customization.xjb Wed Mar 17 04:39:07 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
+    <jxb:bindings schemaLocation="../xsd/validation-mapping-1.0.xsd" node="/xs:schema">
+        <jxb:globalBindings>
+            <xjc:javaType name="java.lang.String" xmlType="xs:string" 
+                adapter="javax.xml.bind.annotation.adapters.CollapsedStringAdapter"/>
+        </jxb:globalBindings>
+
+        <jxb:bindings node="//xs:complexType[9]/xs:sequence[1]/xs:element[1]">
+            <jxb:property name="classType"/>
+        </jxb:bindings>
+    </jxb:bindings>
+</jxb:bindings>

Added: incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-configuration-1.0.xsd
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-configuration-1.0.xsd?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-configuration-1.0.xsd (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-configuration-1.0.xsd Wed Mar 17 04:39:07 2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<xs:schema attributeFormDefault="unqualified"
+           elementFormDefault="qualified"
+           targetNamespace="http://jboss.org/xml/ns/javax/validation/configuration"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           version="1.0">
+    <xs:element name="validation-config" type="config:validation-configType" xmlns:config="http://jboss.org/xml/ns/javax/validation/configuration"/>
+    <xs:complexType name="validation-configType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="default-provider" minOccurs="0"/>
+            <xs:element type="xs:string" name="message-interpolator" minOccurs="0"/>
+            <xs:element type="xs:string" name="traversable-resolver" minOccurs="0"/>
+            <xs:element type="xs:string" name="constraint-validator-factory" minOccurs="0"/>
+            <xs:element type="xs:string" name="constraint-mapping" maxOccurs="unbounded" minOccurs="0"/>
+            <xs:element type="config:propertyType" name="property" maxOccurs="unbounded" minOccurs="0" xmlns:config="http://jboss.org/xml/ns/javax/validation/configuration"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="propertyType">
+        <xs:simpleContent>
+            <xs:extension base="xs:string">
+                <xs:attribute name="name" use="required" type="xs:string"/>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+</xs:schema>

Added: incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-mapping-1.0.xsd
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-mapping-1.0.xsd?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-mapping-1.0.xsd (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/main/xsd/validation-mapping-1.0.xsd Wed Mar 17 04:39:07 2010
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<xs:schema attributeFormDefault="unqualified"
+           elementFormDefault="qualified"
+           targetNamespace="http://jboss.org/xml/ns/javax/validation/mapping"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           version="1.0">
+    <xs:element name="constraint-mappings"
+                type="map:constraint-mappingsType"
+                xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+
+    <xs:complexType name="payloadType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="groupsType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="groupSequenceType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="constraint-mappingsType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="default-package" minOccurs="0"/>
+            <xs:element type="map:beanType"
+                        name="bean"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+            <xs:element type="map:constraint-definitionType"
+                        name="constraint-definition"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="validated-byType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+        </xs:sequence>
+        <xs:attribute type="xs:boolean" name="include-existing-validators" use="optional"/>
+    </xs:complexType>
+    <xs:complexType name="constraintType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="message" minOccurs="0"/>
+            <xs:element type="map:groupsType"
+                        name="groups"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+            <xs:element type="map:payloadType"
+                        name="payload"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>            
+            <xs:element type="map:elementType"
+                        name="element"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="annotation" use="required"/>
+    </xs:complexType>
+    <xs:complexType name="elementType" mixed="true">
+        <xs:sequence>
+            <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+            <xs:element type="map:annotationType"
+                        name="annotation"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="name" use="required"/>
+    </xs:complexType>
+    <xs:complexType name="classType">
+        <xs:sequence>
+            <xs:element type="map:groupSequenceType" 
+                        name="group-sequence" 
+                        minOccurs="0" 
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+            <xs:element type="map:constraintType"
+                        name="constraint"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+    </xs:complexType>
+    <xs:complexType name="beanType">
+        <xs:sequence>
+            <xs:element type="map:classType"
+                        name="class"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping">
+            </xs:element>
+            <xs:element type="map:fieldType"
+                        name="field"
+                        minOccurs="0"
+                        maxOccurs="unbounded"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+            <xs:element type="map:getterType"
+                        name="getter"
+                        minOccurs="0"
+                        maxOccurs="unbounded"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="class" use="required"/>
+        <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+    </xs:complexType>
+    <xs:complexType name="annotationType">
+        <xs:sequence>
+            <xs:element type="map:elementType"
+                        name="element"
+                        maxOccurs="unbounded"
+                        minOccurs="0"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="getterType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
+            <xs:element type="map:constraintType"
+                        name="constraint"
+                        minOccurs="0"
+                        maxOccurs="unbounded"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="name" use="required"/>
+        <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+    </xs:complexType>
+    <xs:complexType name="constraint-definitionType">
+        <xs:sequence>
+            <xs:element type="map:validated-byType"
+                        name="validated-by"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="annotation" use="required"/>
+    </xs:complexType>
+    <xs:complexType name="fieldType">
+        <xs:sequence>
+            <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
+            <xs:element type="map:constraintType"
+                        name="constraint"
+                        minOccurs="0"
+                        maxOccurs="unbounded"
+                        xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+        </xs:sequence>
+        <xs:attribute type="xs:string" name="name" use="required"/>
+        <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+    </xs:complexType>
+</xs:schema>

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/AgimatecEmail.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/AgimatecEmail.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/AgimatecEmail.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/AgimatecEmail.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.constraints.Pattern;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+@Pattern.List({
+    // email
+    @Pattern(regexp = "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}"),
+    // agimatec
+    @Pattern(regexp = ".*?AGIMATEC.*?")
+})
+/**
+ * test a constraint WITHOUT an own ConstraintValidator implementation.
+ * the validations, that must be processed are in the combined constraints only!!
+ * the @Constraint annotation is nevertheless required so that the framework searches
+ * for combined constraints.  
+ */
+@Constraint(validatedBy = {})
+@Documented
+@Target({ANNOTATION_TYPE, METHOD, FIELD, CONSTRUCTOR, PARAMETER})
+@Retention(RUNTIME)
+public @interface AgimatecEmail {
+    String message() default "Not an agimatec email";
+
+    @OverridesAttribute(constraint = Pattern.class, name = "message",
+          constraintIndex = 0) String emailMessage() default "Not an email";
+
+    @OverridesAttribute(constraint = Pattern.class, name = "message",
+          constraintIndex = 1) String agimatecMessage() default "Not Agimatec";
+
+    Class<?>[] groups() default {};
+
+    Class<? extends Payload>[] payload() default {};
+
+    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
+    @Retention(RUNTIME)
+    @Documented
+          @interface List {
+        AgimatecEmail[] value();
+    }
+}
\ No newline at end of file

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/DigitsValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/DigitsValidatorTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/DigitsValidatorTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/DigitsValidatorTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.math.BigDecimal;
+
+/**
+ * DigitsConstraintValidator Tester.
+ *
+ * @author <Authors name>
+ * @since <pre>02/03/2009</pre>
+ * @version 1.0
+ */
+public class DigitsValidatorTest extends TestCase {
+    public DigitsValidatorTest(String name) {
+        super(name);
+    }
+
+    public void testValidateNumber() {
+        DigitsValidatorForNumber validator = new DigitsValidatorForNumber();
+        validator.setFractional(4);
+        validator.setIntegral(2);
+        BigDecimal val = new BigDecimal("100.12345");
+        Assert.assertFalse(validator.isValid(val, null));
+        val = new BigDecimal("99.1234");
+        Assert.assertTrue(validator.isValid(val, null));
+    }
+
+    public void testValidateString() {
+        DigitsValidatorForString validator = new DigitsValidatorForString();
+        validator.setFractional(4);
+        validator.setIntegral(2);
+        String val = "100.12345";
+        Assert.assertFalse(validator.isValid(val, null));
+        val = "99.1234";
+        Assert.assertTrue(validator.isValid(val, null));
+    }
+
+    public void testValidateNumber2() {
+        DigitsValidatorForNumber validator = new DigitsValidatorForNumber();
+        validator.setFractional(4);
+        validator.setIntegral(2);
+        Long val = new Long("100");
+        Assert.assertFalse(validator.isValid(val, null));
+        val = new Long("99");
+        Assert.assertTrue(validator.isValid(val, null));
+    }
+
+    public void testValidateString2() {
+        DigitsValidatorForString validator = new DigitsValidatorForString();
+        validator.setFractional(0);
+        validator.setIntegral(2);
+        String val = "99.5";
+        Assert.assertFalse(validator.isValid(val, null));
+        val = "99";
+        Assert.assertTrue(validator.isValid(val, null));
+    }
+
+    public static Test suite() {
+        return new TestSuite(DigitsValidatorTest.class);
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/EmailValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/EmailValidatorTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/EmailValidatorTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/EmailValidatorTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.example.Customer;
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.validation.Validator;
+
+/**
+ * EmailValidator Tester.
+ *
+ * @author Roman Stumm
+ * @version 1.0
+ * @since <pre>10/14/2008</pre>
+ */
+public class EmailValidatorTest extends TestCase {
+    public EmailValidatorTest(String name) {
+        super(name);
+    }
+
+    public void testEmail() {
+        Validator validator = AgimatecValidatorFactory.getDefault().getValidator();
+        Customer customer = new Customer();
+        customer.setCustomerId("id-1");
+        customer.setFirstName("Mary");
+        customer.setLastName("Do");
+        customer.setPassword("12345");
+
+        Assert.assertEquals(0, validator.validate(customer).size());
+
+        customer.setEmailAddress("some@invalid@address");
+        Assert.assertEquals(1, validator.validate(customer).size());
+
+        customer.setEmailAddress("some.valid-012345@address_at-test.org");
+        Assert.assertEquals(0, validator.validate(customer).size());
+    }
+
+
+    public static Test suite() {
+        return new TestSuite(EmailValidatorTest.class);
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipCode.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipCode.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipCode.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipCode.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Description: example for composed constraint.
+ * not implemented! simple dummy implemenation for tests only! <br/>
+ * User: roman.stumm <br/>
+ * Date: 31.10.2008 <br/>
+ * Time: 16:34:56 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@NotEmpty
+@NotNull
+@Size(min = 4, max = 5, message = "Zipcode should be of size {value}")
+@Constraint(validatedBy = FrenchZipcodeValidator.class)
+@ReportAsSingleViolation
+@Documented
+@Target({ANNOTATION_TYPE, METHOD, FIELD})
+@Retention(RUNTIME)
+public @interface FrenchZipCode {
+    @OverridesAttribute.List({
+            @OverridesAttribute(constraint = Size.class, name= "min"),
+        @OverridesAttribute(constraint = Size.class, name = "max")})
+    int size() default 6;
+
+    @OverridesAttribute(constraint=Size.class, name="message")
+    String sizeMessage() default "{error.zipcode.size}";
+
+    String message() default "Wrong zipcode";
+
+    Class<?>[] groups() default {};
+
+    Class<? extends Payload>[] payload() default { };
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipcodeValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipcodeValidator.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipcodeValidator.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/FrenchZipcodeValidator.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * Description: not implemented (test only)<br/>
+ * User: roman.stumm <br/>
+ * Date: 31.10.2008 <br/>
+ * Time: 16:38:25 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class FrenchZipcodeValidator implements ConstraintValidator<FrenchZipCode, Object> {
+    public void initialize(FrenchZipCode constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Object object, ConstraintValidatorContext validationContext) {
+        return null != object;
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasStringValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasStringValidator.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasStringValidator.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasStringValidator.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agimatec.validation.constraints;
+
+import org.apache.commons.lang.ArrayUtils;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 14:41:07 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class HasStringValidator implements ConstraintValidator<HasValue, String> {
+    private String[] values;
+
+    public void initialize(HasValue stringValues) {
+        values = stringValues.value();
+    }
+
+    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
+        return s == null || ArrayUtils.contains(values, s);
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasValue.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasValue.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasValue.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/HasValue.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Description: allow distinct string values for element (like enums) <br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 14:28:43 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@Target({ANNOTATION_TYPE, METHOD, FIELD})
+@Constraint(validatedBy = {HasStringValidator.class})
+@Retention(RUNTIME)
+public @interface HasValue {
+    String[] value();
+
+    String message() default "Wrong value, must be one of {value}";
+
+    Class<?>[] groups() default {};
+
+    Class<? extends Payload>[] payload() default { };
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/Password.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/Password.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/Password.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/Password.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 01.04.2008 <br/>
+ * Time: 12:02:06 <br/>
+ */
+@NotEmpty
+@NotNull
+@Size(min = 4, max = 5)
+@Retention(RUNTIME)
+@Constraint(validatedBy = {})
+// test that Password is validated although only combined constraints exists, no own implementation 
+public @interface Password {
+    String[] groups() default {};
+
+    String message() default "Wrong password";
+
+    int robustness() default 8;
+
+    Class<? extends Payload>[] payload() default { };
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherence.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherence.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherence.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherence.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * not implemented! simple dummy implemenation for tests only!
+ */
+@Documented
+@Constraint(validatedBy = ZipCodeCityCoherenceValidator.class)
+@Target({TYPE})
+@Retention(RUNTIME)
+public @interface ZipCodeCityCoherence {
+    String message() default "{validator.zipCodeCityCoherence}";    
+    Class<?>[] groups() default {};
+    Class<? extends Payload>[] payload() default { };
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherenceValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherenceValidator.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherenceValidator.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/constraints/ZipCodeCityCoherenceValidator.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.constraints;
+
+import com.agimatec.validation.jsr303.example.ZipCodeCityCarrier;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * Description: Class not implemented! simple dummy implemenation for tests only! <br/>
+ * User: roman.stumm <br/>
+ * Date: 01.04.2008 <br/>
+ * Time: 11:45:22 <br/>
+ */
+public class ZipCodeCityCoherenceValidator
+      implements ConstraintValidator<ZipCodeCityCoherence, ZipCodeCityCarrier> {
+    public void initialize(ZipCodeCityCoherence constraintAnnotation) {
+    }
+
+    public boolean isValid(ZipCodeCityCarrier adr, ConstraintValidatorContext context) {
+        boolean r = true;
+        if ("error".equals(adr.getZipCode())) {
+            context.disableDefaultConstraintViolation();
+            context.buildConstraintViolationWithTemplate("zipcode not OK").addConstraintViolation();
+            r = false;
+        }
+        if ("error".equals(adr.getCity())) {
+            context.disableDefaultConstraintViolation();
+            context.buildConstraintViolationWithTemplate("city not OK").addNode("city").addConstraintViolation();
+            r = false;
+        }
+        return r;
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/BootstrapTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/BootstrapTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/BootstrapTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/BootstrapTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package com.agimatec.validation.jsr303;
+
+import com.agimatec.validation.constraints.NotNullValidator;
+import com.agimatec.validation.jsr303.example.Customer;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import javax.validation.*;
+import javax.validation.bootstrap.ProviderSpecificBootstrap;
+import javax.validation.spi.ValidationProvider;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 29.10.2008 <br/>
+ * Time: 15:06:28 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class BootstrapTest extends TestCase {
+    public void testAgimatecBootstrap() {
+        Validator validator =
+                AgimatecValidatorFactory.getDefault().getValidator();
+        Assert.assertNotNull(validator);
+        Assert.assertTrue(AgimatecValidatorFactory.getDefault() ==
+                AgimatecValidatorFactory.getDefault());
+    }
+
+    public void testEverydayBootstrap() {
+        AgimatecValidatorFactory factory =
+                (AgimatecValidatorFactory) Validation.buildDefaultValidatorFactory();
+        Validator validator = factory.getValidator();
+        Assert.assertNotNull(validator);
+
+        // each call to Validation.getValidationBuilder() returns a new builder with new state
+        AgimatecValidatorFactory factory2 =
+                (AgimatecValidatorFactory) Validation.buildDefaultValidatorFactory();
+        Assert.assertTrue(factory2 != factory);
+        Assert.assertTrue(factory2.getMessageInterpolator() != factory.getMessageInterpolator());
+
+    }
+
+    public void testLocalizedMessageInterpolatorFactory() {
+        Configuration<?> builder = Validation.byDefaultProvider().configure();
+        // changing the builder allows to create different factories
+        DefaultMessageInterpolator interpolator = new DefaultMessageInterpolator();
+        builder.messageInterpolator(interpolator);
+        AgimatecValidatorFactory factory = (AgimatecValidatorFactory) builder.buildValidatorFactory();
+
+        // ALTERNATIVE:
+        // you could do it without modifying the builder or reusing it,
+        // but then you need to use Agimatec proprietary APIs:
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        // now factory's message resolver is using the english locale
+    }
+
+    /**
+     * some tests taken from Hibernate's ValidationTest to ensure that.
+     * our implementation works as the reference implementation
+     */
+
+    public void testCustomConstraintFactory() {
+
+        Configuration<?> builder = Validation.byDefaultProvider().configure();
+        assertDefaultBuilderAndFactory(builder);
+
+        ValidatorFactory factory = builder.buildValidatorFactory();
+        Validator validator = factory.getValidator();
+
+        Customer customer = new Customer();
+        customer.setFirstName("John");
+
+        Set<ConstraintViolation<Customer>> ConstraintViolations = validator.validate(customer);
+        Assert.assertFalse(ConstraintViolations.isEmpty());
+
+        builder = Validation.byDefaultProvider().configure();
+        builder.constraintValidatorFactory(
+                new ConstraintValidatorFactory() {
+                    public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+                        if (key == NotNullValidator.class) {
+                            return (T) new BadlyBehavedNotNullValidator();
+                        }
+                        return new DefaultConstraintValidatorFactory().getInstance(key);
+                    }
+                }
+        );
+        factory = builder.buildValidatorFactory();
+        validator = factory.getValidator();
+        Set<ConstraintViolation<Customer>> ConstraintViolations2 = validator.validate(customer);
+        Assert.assertTrue("Wrong number of constraints",
+                ConstraintViolations.size() > ConstraintViolations2.size());
+    }
+
+    public void testCustomResolverAndType() {
+        ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+            public List<ValidationProvider<?>> getValidationProviders() {
+                List<ValidationProvider<?>> list = new ArrayList(1);
+                list.add(new AgimatecValidationProvider());
+                return list;
+            }
+        };
+
+        AgimatecValidatorConfiguration builder = Validation
+                .byProvider(AgimatecValidationProvider.class)
+                .providerResolver(resolver)
+                .configure();
+        assertDefaultBuilderAndFactory(builder);
+    }
+
+    public void testCustomResolver() {
+        ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+            public List<ValidationProvider<?>> getValidationProviders() {
+                List list = new ArrayList();
+                list.add(new AgimatecValidationProvider());
+                return list;
+            }
+        };
+
+        Configuration<?> builder = Validation
+                .byDefaultProvider()
+                .providerResolver(resolver)
+                .configure();
+        assertDefaultBuilderAndFactory(builder);
+    }
+
+    private void assertDefaultBuilderAndFactory(Configuration builder) {
+        Assert.assertNotNull(builder);
+        Assert.assertTrue(builder instanceof ConfigurationImpl);
+
+        ValidatorFactory factory = builder.buildValidatorFactory();
+        Assert.assertNotNull(factory);
+        Assert.assertTrue(factory instanceof AgimatecValidatorFactory);
+    }
+
+    public void testFailingCustomResolver() {
+        ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+            public List<ValidationProvider<?>> getValidationProviders() {
+                return new ArrayList();
+            }
+        };
+
+        ProviderSpecificBootstrap<AgimatecValidatorConfiguration> type =
+                Validation.byProvider(AgimatecValidationProvider.class);
+
+        final ProviderSpecificBootstrap<AgimatecValidatorConfiguration> specializedBuilderFactory =
+                type.providerResolver(resolver);
+
+        try {
+            specializedBuilderFactory.configure();
+            Assert.fail();
+        }
+        catch (ValidationException e) {
+            Assert.assertTrue(
+                    "Wrong error message",
+                    e.getMessage().contains("provider") && 
+                    e.getMessage().contains("com.agimatec.validation.jsr303.AgimatecValidationProvider")
+            );
+        }
+    }
+
+    class BadlyBehavedNotNullValidator extends NotNullValidator {
+        @Override
+        public boolean isValid(Object object, ConstraintValidatorContext context) {
+            return true;
+        }
+    }
+}