KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > JdkVersion


1 /*
2  * Copyright 2002-2007 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.core;
18
19 /**
20  * Internal helper class used to find the Java/JDK version
21  * that Spring is operating on, to allow for automatically
22  * adapting to the present platform's capabilities.
23  *
24  * <p>Note that Spring does not support 1.2 or earlier JVMs.
25  *
26  * @author Rod Johnson
27  * @author Juergen Hoeller
28  * @author Rick Evans
29  */

30 public abstract class JdkVersion {
31
32     /**
33      * Constant identifying the 1.3.x JVM (JDK 1.3).
34      */

35     public static final int JAVA_13 = 0;
36
37     /**
38      * Constant identifying the 1.4.x JVM (J2SE 1.4).
39      */

40     public static final int JAVA_14 = 1;
41
42     /**
43      * Constant identifying the 1.5 JVM (Java 5).
44      */

45     public static final int JAVA_15 = 2;
46
47     /**
48      * Constant identifying the 1.6 JVM (Java 6).
49      */

50     public static final int JAVA_16 = 3;
51
52     /**
53      * Constant identifying the 1.7 JVM.
54      */

55     public static final int JAVA_17 = 4;
56
57
58     private static final String JavaDoc javaVersion;
59
60     private static final int majorJavaVersion;
61
62     static {
63         javaVersion = System.getProperty("java.version");
64         // version String should look like "1.4.2_10"
65
if (javaVersion.indexOf("1.7.") != -1) {
66             majorJavaVersion = JAVA_17;
67         }
68         else if (javaVersion.indexOf("1.6.") != -1) {
69             majorJavaVersion = JAVA_16;
70         }
71         else if (javaVersion.indexOf("1.5.") != -1) {
72             majorJavaVersion = JAVA_15;
73         }
74         else if (javaVersion.indexOf("1.4.") != -1) {
75             majorJavaVersion = JAVA_14;
76         }
77         else {
78             // else leave 1.3 as default (it's either 1.3 or unknown)
79
majorJavaVersion = JAVA_13;
80         }
81     }
82
83
84     /**
85      * Return the full Java version string, as returned by
86      * <code>System.getProperty("java.version")</code>.
87      * @return the full Java version string
88      * @see System#getProperty(String)
89      */

90     public static String JavaDoc getJavaVersion() {
91         return javaVersion;
92     }
93
94     /**
95      * Get the major version code. This means we can do things like
96      * <code>if (getMajorJavaVersion() < JAVA_14)</code>.
97      * @return a code comparable to the JAVA_XX codes in this class
98      * @see #JAVA_13
99      * @see #JAVA_14
100      * @see #JAVA_15
101      * @see #JAVA_16
102      * @see #JAVA_17
103      */

104     public static int getMajorJavaVersion() {
105         return majorJavaVersion;
106     }
107
108     /**
109      * Convenience method to determine if the current JVM is at least Java 1.4.
110      * @return <code>true</code> if the current JVM is at least Java 1.4
111      * @see #getMajorJavaVersion()
112      * @see #JAVA_14
113      * @see #JAVA_15
114      * @see #JAVA_16
115      * @see #JAVA_17
116      */

117     public static boolean isAtLeastJava14() {
118         return getMajorJavaVersion() >= JAVA_14;
119     }
120
121     /**
122      * Convenience method to determine if the current JVM is at least
123      * Java 1.5 (Java 5).
124      * @return <code>true</code> if the current JVM is at least Java 1.5
125      * @see #getMajorJavaVersion()
126      * @see #JAVA_15
127      * @see #JAVA_16
128      * @see #JAVA_17
129      */

130     public static boolean isAtLeastJava15() {
131         return getMajorJavaVersion() >= JAVA_15;
132     }
133
134 }
135
Popular Tags