JVM.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: JVM.java,v 1.2 2005/10/10 18:03:00 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx.util;
  22. /**
  23.  * Deals with the different version of the Java Virtual Machine. <br>
  24.  */
  25. public class JVM {
  26.   public final static int JDK1_0 = 10;
  27.   public final static int JDK1_1 = 11;
  28.   public final static int JDK1_2 = 12;
  29.   public final static int JDK1_3 = 13;
  30.   public final static int JDK1_4 = 14;
  31.   public final static int JDK1_5 = 15;
  32.   public final static int JDK1_6 = 16;
  33.   private static JVM current;
  34.   static {
  35.     current = new JVM();
  36.   }
  37.   /**
  38.    * @return the current JVM object
  39.    */
  40.   public static JVM current() {
  41.     return current;
  42.   }
  43.   private int jdkVersion;
  44.   /**
  45.    * Creates a new JVM data from the <code>java.version</code>
  46.    * System property
  47.    *  
  48.    */
  49.   public JVM() {
  50.     this(System.getProperty("java.version"));
  51.   }
  52.   /**
  53.    * Constructor for the OS object
  54.    */
  55.   public JVM(String p_JavaVersion) {
  56.     if (p_JavaVersion.startsWith("1.6.")) {
  57.       jdkVersion = JDK1_6;
  58.     } else if (p_JavaVersion.startsWith("1.5.")) {
  59.       jdkVersion = JDK1_5;
  60.     } else if (p_JavaVersion.startsWith("1.4.")) {
  61.       jdkVersion = JDK1_4;
  62.     } else if (p_JavaVersion.startsWith("1.3.")) {
  63.       jdkVersion = JDK1_3;
  64.     } else if (p_JavaVersion.startsWith("1.2.")) {
  65.       jdkVersion = JDK1_2;
  66.     } else if (p_JavaVersion.startsWith("1.1.")) {
  67.       jdkVersion = JDK1_1;
  68.     } else if (p_JavaVersion.startsWith("1.0.")) {
  69.       jdkVersion = JDK1_0;
  70.     } else {
  71.       // unknown version, assume 1.3
  72.       jdkVersion = JDK1_3;
  73.     }
  74.   }
  75.   public boolean isOrLater(int p_Version) {
  76.     return jdkVersion >= p_Version;
  77.   }
  78.   public boolean isOneDotOne() {
  79.     return jdkVersion == JDK1_1;
  80.   }
  81.   public boolean isOneDotTwo() {
  82.     return jdkVersion == JDK1_2;
  83.   }
  84.   public boolean isOneDotThree() {
  85.     return jdkVersion == JDK1_3;
  86.   }
  87.   public boolean isOneDotFour() {
  88.     return jdkVersion == JDK1_4;
  89.   }
  90.   public boolean isOneDotFive() {
  91.     return jdkVersion == JDK1_5;
  92.   }
  93.   public boolean isOneDotSix() {
  94.     return jdkVersion == JDK1_6;
  95.   }
  96. }