/
ConfigXsdSupport.java
87 lines (75 loc) · 2.08 KB
/
ConfigXsdSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.boot.xsd;
import org.jboss.logging.Logger;
/**
* Support for XSD handling related to Hibernate's `cfg.xml` and
* JPA's `persistence.xml`.
*
* @author Steve Ebersole
*/
@SuppressWarnings("unused")
public class ConfigXsdSupport {
private static final Logger log = Logger.getLogger( ConfigXsdSupport.class );
/**
* Singleton access
*/
public static final ConfigXsdSupport INSTANCE = new ConfigXsdSupport();
private ConfigXsdSupport() {
//Do not construct new instances
}
private final XsdDescriptor jpa10 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/persistence_1_0.xsd",
"1.0",
"http://java.sun.com/xml/ns/persistence"
);
private final XsdDescriptor jpa20 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/persistence_2_0.xsd",
"2.0" ,
"http://java.sun.com/xml/ns/persistence"
);
private final XsdDescriptor jpa21 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/persistence_2_1.xsd",
"2.1",
"http://xmlns.jcp.org/xml/ns/persistence"
);
private final XsdDescriptor jpa22 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/persistence_2_2.xsd",
"2.2" ,
"http://xmlns.jcp.org/xml/ns/persistence"
);
private final XsdDescriptor cfgXml = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/xsd/cfg/legacy-configuration-4.0.xsd",
"4.0" ,
"http://www.hibernate.org/xsd/orm/cfg"
);
public XsdDescriptor latestJpaDescriptor() {
return jpa22;
}
public XsdDescriptor jpaXsd(String version) {
switch ( version ) {
case "1.0": {
return jpa10;
}
case "2.0": {
return jpa20;
}
case "2.1": {
return jpa21;
}
case "2.2": {
return jpa22;
}
default: {
throw new IllegalArgumentException( "Unrecognized JPA persistence.xml XSD version : `" + version + "`" );
}
}
}
public XsdDescriptor cfgXsd() {
return cfgXml;
}
}