001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.util;
018:
019: /**
020: * Deals with the different version of the Java Virtual Machine. <br>
021: */
022: public class JVM {
023:
024: public final static int JDK1_0 = 10;
025: public final static int JDK1_1 = 11;
026: public final static int JDK1_2 = 12;
027: public final static int JDK1_3 = 13;
028: public final static int JDK1_4 = 14;
029: public final static int JDK1_5 = 15;
030: public final static int JDK1_6 = 16;
031:
032: private static JVM current;
033: static {
034: current = new JVM();
035: }
036:
037: /**
038: * @return the current JVM object
039: */
040: public static JVM current() {
041: return current;
042: }
043:
044: private int jdkVersion;
045:
046: /**
047: * Creates a new JVM data from the <code>java.version</code>
048: * System property
049: *
050: */
051: public JVM() {
052: this (System.getProperty("java.version"));
053: }
054:
055: /**
056: * Constructor for the OS object
057: */
058: public JVM(String p_JavaVersion) {
059: if (p_JavaVersion.startsWith("1.6.")) {
060: jdkVersion = JDK1_6;
061: } else if (p_JavaVersion.startsWith("1.5.")) {
062: jdkVersion = JDK1_5;
063: } else if (p_JavaVersion.startsWith("1.4.")) {
064: jdkVersion = JDK1_4;
065: } else if (p_JavaVersion.startsWith("1.3.")) {
066: jdkVersion = JDK1_3;
067: } else if (p_JavaVersion.startsWith("1.2.")) {
068: jdkVersion = JDK1_2;
069: } else if (p_JavaVersion.startsWith("1.1.")) {
070: jdkVersion = JDK1_1;
071: } else if (p_JavaVersion.startsWith("1.0.")) {
072: jdkVersion = JDK1_0;
073: } else {
074: // unknown version, assume 1.3
075: jdkVersion = JDK1_3;
076: }
077: }
078:
079: public boolean isOrLater(int p_Version) {
080: return jdkVersion >= p_Version;
081: }
082:
083: public boolean isOneDotOne() {
084: return jdkVersion == JDK1_1;
085: }
086:
087: public boolean isOneDotTwo() {
088: return jdkVersion == JDK1_2;
089: }
090:
091: public boolean isOneDotThree() {
092: return jdkVersion == JDK1_3;
093: }
094:
095: public boolean isOneDotFour() {
096: return jdkVersion == JDK1_4;
097: }
098:
099: public boolean isOneDotFive() {
100: return jdkVersion == JDK1_5;
101: }
102:
103: public boolean isOneDotSix() {
104: return jdkVersion == JDK1_6;
105: }
106:
107: }
|