bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject [08/15] bval git commit: wip
Date Wed, 15 Nov 2017 22:54:13 GMT
http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
new file mode 100644
index 0000000..9d16bf3
--- /dev/null
+++ b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
@@ -0,0 +1,297 @@
+<?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://xmlns.jcp.org/xml/ns/javax/validation/mapping"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:map="http://xmlns.jcp.org/xml/ns/javax/validation/mapping"
+           version="2.0">
+  <xs:element name="constraint-mappings" type="map:constraint-mappingsType" />
+
+  <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="groupConversionType">
+    <xs:attribute type="xs:string" name="from" use="required" />
+    <xs:attribute type="xs:string" name="to" use="required" />
+  </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" />
+      <xs:element type="map:constraint-definitionType"
+                  name="constraint-definition"
+                  maxOccurs="unbounded"
+                  minOccurs="0" />
+    </xs:sequence>
+    <xs:attribute name="version" type="map:versionType" fixed="2.0" /> <!-- use="required"
-->
+  </xs:complexType>
+  <xs:simpleType name="versionType">
+    <xs:restriction base="xs:token">
+      <xs:pattern value="[0-9]+(\.[0-9]+)*" />
+    </xs:restriction>
+  </xs:simpleType>
+  <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" />
+      <xs:element type="map:payloadType"
+                  name="payload"
+                  minOccurs="0" />
+      <xs:element type="map:elementType"
+                  name="element"
+                  maxOccurs="unbounded"
+                  minOccurs="0" />
+    </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" />
+    </xs:sequence>
+    <xs:attribute type="xs:string" name="name" use="required" />
+  </xs:complexType>
+  <xs:complexType name="containerElementTypeType">
+    <xs:sequence>
+      <xs:element type="xs:string"
+                  name="valid"
+                  minOccurs="0"
+                  fixed="" />
+      <xs:element type="map:groupConversionType"
+                  name="convert-group"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:containerElementTypeType"
+                  name="container-element-type"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </xs:sequence>
+    <xs:attribute name="type-argument-index" use="optional">
+      <xs:simpleType>
+        <xs:restriction base="xs:int">
+          <xs:minInclusive value="0" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:attribute>
+  </xs:complexType>
+  <xs:complexType name="classType">
+    <xs:sequence>
+      <xs:element type="map:groupSequenceType"
+                  name="group-sequence"
+                  minOccurs="0" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  maxOccurs="unbounded"
+                  minOccurs="0" />
+    </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">
+      </xs:element>
+      <xs:element type="map:fieldType"
+                  name="field"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:getterType"
+                  name="getter"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constructorType"
+                  name="constructor"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:methodType"
+                  name="method"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </xs:sequence>
+    <xs:attribute type="xs:string" name="class" use="required" />
+    <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" default="true"
/>
+  </xs:complexType>
+  <xs:complexType name="annotationType">
+    <xs:sequence>
+      <xs:element type="map:elementType"
+                  name="element"
+                  maxOccurs="unbounded"
+                  minOccurs="0" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="getterType">
+    <xs:sequence>
+      <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" />
+      <xs:element type="map:groupConversionType"
+                  name="convert-group"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:containerElementTypeType"
+                  name="container-element-type"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </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="methodType">
+    <xs:sequence>
+      <xs:element type="map:parameterType"
+                  name="parameter"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:crossParameterType"
+                  name="cross-parameter"
+                  minOccurs="0"
+                  maxOccurs="1" />
+      <xs:element type="map:returnValueType"
+                  name="return-value"
+                  minOccurs="0"
+                  maxOccurs="1" />
+    </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="constructorType">
+    <xs:sequence>
+      <xs:element type="map:parameterType"
+                  name="parameter"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:crossParameterType"
+                  name="cross-parameter"
+                  minOccurs="0"
+                  maxOccurs="1" />
+      <xs:element type="map:returnValueType"
+                  name="return-value"
+                  minOccurs="0"
+                  maxOccurs="1" />
+    </xs:sequence>
+    <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" />
+  </xs:complexType>
+  <xs:complexType name="parameterType">
+    <xs:sequence>
+      <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" />
+      <xs:element type="map:groupConversionType"
+                  name="convert-group"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:containerElementTypeType"
+                  name="container-element-type"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </xs:sequence>
+    <xs:attribute type="xs:string" name="type" use="required" />
+    <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" />
+  </xs:complexType>
+  <xs:complexType name="returnValueType">
+    <xs:sequence>
+      <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" />
+      <xs:element type="map:groupConversionType"
+                  name="convert-group"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:containerElementTypeType"
+                  name="container-element-type"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </xs:sequence>
+    <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" />
+  </xs:complexType>
+  <xs:complexType name="crossParameterType">
+    <xs:sequence>
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </xs:sequence>
+    <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" />
+    </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:groupConversionType"
+                  name="convert-group"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:containerElementTypeType"
+                  name="container-element-type"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+      <xs:element type="map:constraintType"
+                  name="constraint"
+                  minOccurs="0"
+                  maxOccurs="unbounded" />
+    </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>

http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java
index 355d676..fca45d1 100644
--- a/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.bval.jsr;
 
 import static org.hamcrest.CoreMatchers.isA;
 
+import javax.validation.ClockProvider;
 import javax.validation.ConstraintValidatorFactory;
 import javax.validation.MessageInterpolator;
 import javax.validation.ParameterNameProvider;
@@ -95,6 +96,11 @@ public class CustomValidatorFactoryTest {
             return null;
         }
 
+        @Override
+        public ClockProvider getClockProvider() {
+            return null;
+        }
+
     }
 
     public static class NotAValidatorFactory {

http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
new file mode 100644
index 0000000..02a07a8
--- /dev/null
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
@@ -0,0 +1,40 @@
+package org.apache.bval.jsr.xml;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.UnmarshallerHandler;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+public class Demo {
+
+    @Test
+    public void test1() throws Exception {
+        JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class);
+
+        // Set the parent XMLReader on the XMLFilter
+        SAXParserFactory spf = SAXParserFactory.newInstance();
+        spf.setNamespaceAware(true);
+        SAXParser sp = spf.newSAXParser();
+        XMLReader xr = sp.getXMLReader();
+
+        // Set UnmarshallerHandler as ContentHandler on XMLFilter
+        
+        Unmarshaller unmarshaller = jc.createUnmarshaller();
+        
+        UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
+        xr.setContentHandler(unmarshallerHandler);
+
+        // Parse the XML
+        InputSource xml = new InputSource(getClass().getResourceAsStream("/sample-validation2.xml"));
+        xr.parse(xml);
+        JAXBElement<ValidationConfigType> result = (JAXBElement<ValidationConfigType>)
unmarshallerHandler.getResult();
+        System.out.println(ToStringBuilder.reflectionToString(result.getValue()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java
index 827abae..5da75ff 100644
--- a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java
@@ -84,6 +84,18 @@ public class ValidationParserTest implements ApacheValidatorConfiguration.Proper
     }
 
     @Test
+    public void testParseV11() {
+        ConfigurationImpl config = new ConfigurationImpl(null, new ApacheValidationProvider());
+        ValidationParser.processValidationConfig("sample-validation11.xml", config, false);
+    }
+
+    @Test
+    public void testParseV20() {
+        ConfigurationImpl config = new ConfigurationImpl(null, new ApacheValidationProvider());
+        ValidationParser.processValidationConfig("sample-validation2.xml", config, false);
+    }
+
+    @Test
     public void testConfigureFromXml() {
         ValidatorFactory factory = getFactory();
         assertThat(factory.getMessageInterpolator(), instanceOf(TestMessageInterpolator.class));

http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/test/resources/sample-validation11.xml
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/resources/sample-validation11.xml b/bval-jsr/src/test/resources/sample-validation11.xml
new file mode 100644
index 0000000..648ba1c
--- /dev/null
+++ b/bval-jsr/src/test/resources/sample-validation11.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+<validation-config
+    xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation=
+        "http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
+    version="1.1">
+  <default-provider>org.apache.bval.jsr.ApacheValidationProvider</default-provider>
+  <message-interpolator>org.apache.bval.jsr.xml.TestMessageInterpolator</message-interpolator>
+  <traversable-resolver>org.apache.bval.jsr.resolver.SimpleTraversableResolver</traversable-resolver>
+  <constraint-validator-factory>org.apache.bval.jsr.xml.TestConstraintValidatorFactory</constraint-validator-factory>
+  <constraint-mapping>sample-constraints.xml</constraint-mapping>
+  <property name="test-prop">test-prop-value</property>
+</validation-config>

http://git-wip-us.apache.org/repos/asf/bval/blob/a43c0b0c/bval-jsr/src/test/resources/sample-validation2.xml
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/resources/sample-validation2.xml b/bval-jsr/src/test/resources/sample-validation2.xml
new file mode 100644
index 0000000..4758454
--- /dev/null
+++ b/bval-jsr/src/test/resources/sample-validation2.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+<validation-config
+    xmlns="http://xmlns.jcp.org/xml/ns/javax/validation/configuration"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation=
+        "http://xmlns.jcp.org/xml/ns/javax/validation/configuration validation-configuration-2.0.xsd"
+    version="2.0">
+  <default-provider>org.apache.bval.jsr.ApacheValidationProvider</default-provider>
+  <message-interpolator>org.apache.bval.jsr.xml.TestMessageInterpolator</message-interpolator>
+  <traversable-resolver>org.apache.bval.jsr.resolver.SimpleTraversableResolver</traversable-resolver>
+  <constraint-validator-factory>org.apache.bval.jsr.xml.TestConstraintValidatorFactory</constraint-validator-factory>
+  <constraint-mapping>sample-constraints.xml</constraint-mapping>
+  <property name="test-prop">test-prop-value</property>
+</validation-config>


Mime
View raw message