001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.core;
018:
019: /**
020: * Internal helper class used to find the Java/JDK version
021: * that Spring is operating on, to allow for automatically
022: * adapting to the present platform's capabilities.
023: *
024: * <p>Note that Spring does not support 1.2 or earlier JVMs.
025: *
026: * @author Rod Johnson
027: * @author Juergen Hoeller
028: * @author Rick Evans
029: */
030: public abstract class JdkVersion {
031:
032: /**
033: * Constant identifying the 1.3.x JVM (JDK 1.3).
034: */
035: public static final int JAVA_13 = 0;
036:
037: /**
038: * Constant identifying the 1.4.x JVM (J2SE 1.4).
039: */
040: public static final int JAVA_14 = 1;
041:
042: /**
043: * Constant identifying the 1.5 JVM (Java 5).
044: */
045: public static final int JAVA_15 = 2;
046:
047: /**
048: * Constant identifying the 1.6 JVM (Java 6).
049: */
050: public static final int JAVA_16 = 3;
051:
052: /**
053: * Constant identifying the 1.7 JVM.
054: */
055: public static final int JAVA_17 = 4;
056:
057: private static final String javaVersion;
058:
059: private static final int majorJavaVersion;
060:
061: static {
062: javaVersion = System.getProperty("java.version");
063: // version String should look like "1.4.2_10"
064: if (javaVersion.indexOf("1.7.") != -1) {
065: majorJavaVersion = JAVA_17;
066: } else if (javaVersion.indexOf("1.6.") != -1) {
067: majorJavaVersion = JAVA_16;
068: } else if (javaVersion.indexOf("1.5.") != -1) {
069: majorJavaVersion = JAVA_15;
070: } else if (javaVersion.indexOf("1.4.") != -1) {
071: majorJavaVersion = JAVA_14;
072: } else {
073: // else leave 1.3 as default (it's either 1.3 or unknown)
074: majorJavaVersion = JAVA_13;
075: }
076: }
077:
078: /**
079: * Return the full Java version string, as returned by
080: * <code>System.getProperty("java.version")</code>.
081: * @return the full Java version string
082: * @see System#getProperty(String)
083: */
084: public static String getJavaVersion() {
085: return javaVersion;
086: }
087:
088: /**
089: * Get the major version code. This means we can do things like
090: * <code>if (getMajorJavaVersion() < JAVA_14)</code>.
091: * @return a code comparable to the JAVA_XX codes in this class
092: * @see #JAVA_13
093: * @see #JAVA_14
094: * @see #JAVA_15
095: * @see #JAVA_16
096: * @see #JAVA_17
097: */
098: public static int getMajorJavaVersion() {
099: return majorJavaVersion;
100: }
101:
102: /**
103: * Convenience method to determine if the current JVM is at least Java 1.4.
104: * @return <code>true</code> if the current JVM is at least Java 1.4
105: * @see #getMajorJavaVersion()
106: * @see #JAVA_14
107: * @see #JAVA_15
108: * @see #JAVA_16
109: * @see #JAVA_17
110: */
111: public static boolean isAtLeastJava14() {
112: return getMajorJavaVersion() >= JAVA_14;
113: }
114:
115: /**
116: * Convenience method to determine if the current JVM is at least
117: * Java 1.5 (Java 5).
118: * @return <code>true</code> if the current JVM is at least Java 1.5
119: * @see #getMajorJavaVersion()
120: * @see #JAVA_15
121: * @see #JAVA_16
122: * @see #JAVA_17
123: */
124: public static boolean isAtLeastJava15() {
125: return getMajorJavaVersion() >= JAVA_15;
126: }
127:
128: }
|