8000 HV-2103 Include Jakarta Validation 3.1 XSDs · hibernate/hibernate-validator@c586ed8 · GitHub
[go: up one dir, main page]

Skip to content

Commit c586ed8

Browse files
committed
HV-2103 Include Jakarta Validation 3.1 XSDs
1 parent 8ea505e commit c586ed8

File tree

4 files changed

+419
-27
lines changed

4 files changed

+419
-27
lines changed

engine/src/main/java/org/hibernate/validator/internal/xml/config/ValidationXmlParser.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.io.IOException;
88
import java.io.InputStream;
99
import java.lang.invoke.MethodHandles;
10-
import java.util.Collections;
1110
import java.util.Map;
1211

1312
import javax.xml.stream.XMLEventReader;
@@ -18,7 +17,6 @@
1817

1918
import jakarta.validation.BootstrapConfiguration;
2019

21-
import org.hibernate.validator.internal.util.CollectionHelper;
2220
import org.hibernate.validator.internal.util.actions.GetClassLoader;
2321
import org.hibernate.validator.internal.util.actions.SetContextClassLoader;
2422
import org.hibernate.validator.internal.util.logging.Log;
@@ -39,21 +37,16 @@ public class ValidationXmlParser {
3937
private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
4038

4139
private static final String VALIDATION_XML_FILE = "META-INF/validation.xml";
42-
private static final Map<String, String> SCHEMAS_BY_VERSION = Collections.unmodifiableMap( getSchemasByVersion() );
40+
private static final Map<String, String> SCHEMAS_BY_VERSION = Map.of(
41+
"1.0", "META-INF/validation-configuration-1.0.xsd",
42+
"1.1", "META-INF/validation-configuration-1.1.xsd",
43+
"2.0", "META-INF/validation-configuration-2.0.xsd",
44+
"3.0", "META-INF/validation-configuration-3.0.xsd",
45+
"3.1", "META-INF/validation-configuration-3.1.xsd"
46+
);
4347

4448
private final ClassLoader externalClassLoader;
4549

46-
private static Map<String, String> getSchemasByVersion() {
47-
Map<String, String> schemasByVersion = CollectionHelper.newHashMap( 4 );
48-
49-
schemasByVersion.put( "1.0", "META-INF/validation-configuration-1.0.xsd" );
50-
schemasByVersion.put( "1.1", "META-INF/validation-configuration-1.1.xsd" );
51-
schemasByVersion.put( "2.0", "META-INF/validation-configuration-2.0.xsd" );
52-
schemasByVersion.put( "3.0", "META-INF/validation-configuration-3.0.xsd" );
53-
54-
return schemasByVersion;
55-
}
56-
5750
public ValidationXmlParser(ClassLoader externalClassLoader) {
5851
this.externalClassLoader = externalClassLoader;
5952
}

engine/src/main/java/org/hibernate/validator/internal/xml/mapping/MappingXmlParser.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.io.InputStream;
1212
import java.lang.invoke.MethodHandles;
1313
import java.util.Collections;
14-
import java.util.HashMap;
1514
import java.util.List;
1615
import java.util.Map;
1716
import java.util.Set;
@@ -58,18 +57,13 @@ public class MappingXmlParser {
5857

5958
private final ClassLoadingHelper classLoadingHelper;
6059

61-
private static final Map<String, String> SCHEMAS_BY_VERSION = Collections.unmodifiableMap( getSchemasByVersion() );
62-
63-
private static Map<String, String> getSchemasByVersion() {
64-
Map<String, String> schemasByVersion = new HashMap<>();
65-
66-
schemasByVersion.put( "1.0", "META-INF/validation-mapping-1.0.xsd" );
67-
schemasByVersion.put( "1.1", "META-INF/validation-mapping-1.1.xsd" );
68-
schemasByVersion.put( "2.0", "META-INF/validation-mapping-2.0.xsd" );
69-
schemasByVersion.put( "3.0", "META-INF/validation-mapping-3.0.xsd" );
70-
71-
return schemasByVersion;
72-
}
60+
private static final Map<String, String> SCHEMAS_BY_VERSION = Map.of(
61+
"1.0", "META-INF/validation-mapping-1.0.xsd",
62+
"1.1", "META-INF/validation-mapping-1.1.xsd",
63+
"2.0", "META-INF/validation-mapping-2.0.xsd",
64+
"3.0", "META-INF/validation-mapping-3.0.xsd",
65+
"3.1", "META-INF/validation-mapping-3.1.xsd"
66+
);
7367

7468
public MappingXmlParser(ConstraintCreationContext constraintCreationContext, JavaBeanHelper javaBeanHelper, ClassLoader externalClassLoader) {
7569
this.constraintCreationContext = constraintCreationContext;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Jakarta Validation API
4+
~
5+
~ License: Apache License, Version 2.0
6+
~ See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
7+
-->
8+
<xs:schema attributeFormDefault="unqualified"
9+
elementFormDefault="qualified"
10+
targetNamespace="https://jakarta.ee/xml/ns/validation/configuration"
11+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
12+
xmlns:config="https://jakarta.ee/xml/ns/validation/configuration"
13+
version="3.1">
14+
15+
<xs:annotation>
16+
<xs:documentation><![CDATA[
17+
This is the XML Schema for the Jakarta Validation configuration file.
18+
The configuration file must be named "META-INF/validation.xml".
19+
20+
Jakarta Validation configuration files must indicate the Jakarta Validation
21+
XML schema by using the validation namespace:
22+
23+
https://jakarta.ee/xml/ns/validation/configuration
24+
25+
and indicate the version of the schema by using the version attribute
26+
as shown below:
27+
28+
<validation-config
29+
xmlns="https://jakarta.ee/xml/ns/validation/configuration"
30+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31+
xsi:schemaLocation="
32+
https://jakarta.ee/xml/ns/validation/configuration
33+
https://jakarta.ee/xml/ns/validation/validation-configuration-3.1.xsd"
34+
version="3.1">
35+
[...]
36+
</validation-config>
37+
]]>
38+
</xs:documentation>
39+
</xs:annotation>
40+
41+
<xs:element name="validation-config" type="config:validation-configType"/>
42+
<xs:complexType name="validation-configType">
43+
<xs:sequence>
44+
<xs:element type="xs:string" name="default-provider" minOccurs="0"/>
45+
<xs:element type="xs:string" name="message-interpolator" minOccurs="0"/>
46+
<xs:element type="xs:string" name="traversable-resolver" minOccurs="0"/>
47+
<xs:element type="xs:string" name="constraint-validator-factory" minOccurs="0"/>
48+
<xs:element type="xs:string" name="parameter-name-provider" minOccurs="0"/>
49+
<xs:element type="xs:string" name="clock-provider" minOccurs="0"/>
50+
<xs:element type="xs:string" name="value-extractor" maxOccurs="unbounded"
51+
minOccurs="0"/>
52+
<xs:element type="config:executable-validationType" name="executable-validation"
53+
minOccurs="0"/>
54+
<xs:element type="xs:string" name="constraint-mapping" maxOccurs="unbounded"
55+
minOccurs="0"/>
56+
<xs:element type="config:propertyType" name="property" maxOccurs="unbounded"
57+
minOccurs="0"/>
58+
</xs:sequence>
59+
<xs:attribute name="version" type="config:versionType" fixed="3.1" use="required"/>
60+
</xs:complexType>
61+
62+
<xs:complexType name="executable-validationType">
63+
<xs:sequence>
64+
<xs:element type="config:default-validated-executable-typesType"
65+
name="default-validated-executable-types" minOccurs="0"/>
66+
</xs:sequence>
67+
<xs:attribute name="enabled" use="optional" type="xs:boolean" default="true"/>
68+
</xs:complexType>
69+
<xs:complexType name="default-validated-executable-typesType">
70+
<xs:sequence>
71+
<xs:element name="executable-type" maxOccurs="unbounded" minOccurs="1">
72+
<xs:simpleType>
73+
<xs:restriction base="xs:string">
74+
<xs:enumeration value="NONE"/>
75+
<xs:enumeration value="CONSTRUCTORS"/>
76+
<xs:enumeration value="NON_GETTER_METHODS"/>
77+
<xs:enumeration value="GETTER_METHODS"/>
78+
<xs:enumeration value="ALL"/>
79+
</xs:restriction>
80+
</xs:simpleType>
81+
</xs:element>
82+
</xs:sequence>
83+
</xs:complexType>
84+
<xs:complexType name="propertyType">
85+
<xs:simpleContent>
86+
<xs:extension base="xs:string">
87+
<xs:attribute name="name" use="required" type="xs:string"/>
88+
</xs:extension>
89+
</xs:simpleContent>
90+
</xs:complexType>
91+
<xs:simpleType name="versionType">
92+
<xs:restriction base="xs:token">
93+
<xs:pattern value="[0-9]+(\.[0-9]+)*" />
94+
</xs:restriction>
95+
</xs:simpleType>
96+
</xs:schema>

0 commit comments

Comments
 (0)
0