001 /* 002 * $Id: JVM.java,v 1.2 2005/10/10 18:03:00 rbair Exp $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021 package org.jdesktop.swingx.util; 022 023 /** 024 * Deals with the different version of the Java Virtual Machine. <br> 025 */ 026 public class JVM { 027 028 public final static int JDK1_0 = 10; 029 public final static int JDK1_1 = 11; 030 public final static int JDK1_2 = 12; 031 public final static int JDK1_3 = 13; 032 public final static int JDK1_4 = 14; 033 public final static int JDK1_5 = 15; 034 public final static int JDK1_6 = 16; 035 036 private static JVM current; 037 static { 038 current = new JVM(); 039 } 040 041 /** 042 * @return the current JVM object 043 */ 044 public static JVM current() { 045 return current; 046 } 047 048 private int jdkVersion; 049 050 /** 051 * Creates a new JVM data from the <code>java.version</code> 052 * System property 053 * 054 */ 055 public JVM() { 056 this(System.getProperty("java.version")); 057 } 058 059 /** 060 * Constructor for the OS object 061 */ 062 public JVM(String p_JavaVersion) { 063 if (p_JavaVersion.startsWith("1.6.")) { 064 jdkVersion = JDK1_6; 065 } else if (p_JavaVersion.startsWith("1.5.")) { 066 jdkVersion = JDK1_5; 067 } else if (p_JavaVersion.startsWith("1.4.")) { 068 jdkVersion = JDK1_4; 069 } else if (p_JavaVersion.startsWith("1.3.")) { 070 jdkVersion = JDK1_3; 071 } else if (p_JavaVersion.startsWith("1.2.")) { 072 jdkVersion = JDK1_2; 073 } else if (p_JavaVersion.startsWith("1.1.")) { 074 jdkVersion = JDK1_1; 075 } else if (p_JavaVersion.startsWith("1.0.")) { 076 jdkVersion = JDK1_0; 077 } else { 078 // unknown version, assume 1.3 079 jdkVersion = JDK1_3; 080 } 081 } 082 083 public boolean isOrLater(int p_Version) { 084 return jdkVersion >= p_Version; 085 } 086 087 public boolean isOneDotOne() { 088 return jdkVersion == JDK1_1; 089 } 090 091 public boolean isOneDotTwo() { 092 return jdkVersion == JDK1_2; 093 } 094 095 public boolean isOneDotThree() { 096 return jdkVersion == JDK1_3; 097 } 098 099 public boolean isOneDotFour() { 100 return jdkVersion == JDK1_4; 101 } 102 103 public boolean isOneDotFive() { 104 return jdkVersion == JDK1_5; 105 } 106 107 public boolean isOneDotSix() { 108 return jdkVersion == JDK1_6; 109 } 110 111 }