1 /*
2 * Copyright 2005-2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.xml;
18
19 import org.springframework.util.ClassUtils;
20
21 /**
22 * Helper class used to find the current version of JAXP. We cannot depend on the Java version, since JAXP can be
23 * upgraded independently of the Java version.
24 * <p/>
25 * Only distinguishes between JAXP 1.0, 1.1, 1.3, and 1.4, since JAXP 1.2 was a maintenance release with no new
26 * classes.
27 * <p>
28 * Note that Spring-WS requires JDK 1.5 as of Spring-WS 2.0, and therefore has at least JAXP 1.3 available.
29 *
30 * @author Arjen Poutsma
31 * @since 1.0.0
32 */
33 public abstract class JaxpVersion {
34
35 /**
36 * Constant identifying JAXP 1.0.
37 */
38 public static final int JAXP_10 = 0;
39
40 /**
41 * Constant identifying JAXP 1.1.
42 */
43 public static final int JAXP_11 = 1;
44
45 /**
46 * Constant identifying JAXP 1.3.
47 */
48 public static final int JAXP_13 = 3;
49
50 /**
51 * Constant identifying JAXP 1.4.
52 */
53 public static final int JAXP_14 = 4;
54
55 private static final String JAXP_14_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
56
57 private static int jaxpVersion;
58
59 static {
60 ClassLoader classLoader = JaxpVersion.class.getClassLoader();
61 try {
62 ClassUtils.forName(JAXP_14_CLASS_NAME, classLoader);
63 jaxpVersion = JAXP_14;
64 }
65 catch (ClassNotFoundException ex) {
66 // leave 1.3 as default (it's either 1.3 or unknown)
67 jaxpVersion = JAXP_13;
68 }
69 }
70
71 /**
72 * Gets the JAXP version. This means we can do things like if <code>(getJaxpVersion() < JAXP_13)</code>.
73 *
74 * @return a code comparable to the JAXP_XX codes in this class
75 * @see #JAXP_10
76 * @see #JAXP_11
77 * @see #JAXP_13
78 * @see #JAXP_14
79 */
80 public static int getJaxpVersion() {
81 return jaxpVersion;
82 }
83
84 /**
85 * Convenience method to determine if the current JAXP version is at least 1.4 (packaged with JDK 1.6).
86 *
87 * @return <code>true</code> if the current JAXP version is at least JAXP 1.4
88 * @see #getJaxpVersion()
89 * @see #JAXP_14
90 */
91 public static boolean isAtLeastJaxp14() {
92 return getJaxpVersion() >= JAXP_14;
93 }
94
95 }