1 21 22 package org.apache.derby.iapi.services.info; 23 24 25 28 public abstract class JVMInfo 29 { 30 40 public static final int JDK_ID; 41 42 public static final int J2SE_13 = 2; 43 public static final int J2SE_14 = 4; 44 public static final int J2SE_142 = 5; 45 public static final int J2SE_15 = 6; public static final int J2SE_16 = 7; 48 public static final boolean J2ME; 49 50 53 public static final int JAVA_SQL_TYPES_BOOLEAN; 54 55 static 56 { 57 int id; 58 59 String javaVersion; 71 String javaSpec; 72 boolean isJ2ME; 73 74 try { 75 javaSpec = System.getProperty("java.specification.name"); 76 } catch (SecurityException se) { 77 javaSpec = null; 80 } 81 82 try { 83 javaVersion = System.getProperty("java.specification.version", "1.3"); 84 85 } catch (SecurityException se) { 86 javaVersion = "1.3"; 89 } 90 91 if (javaSpec != null && javaSpec.startsWith("J2ME")) 92 { 93 97 id = J2SE_13; 100 isJ2ME = true; 101 } 102 else 103 { 104 isJ2ME = false; 106 107 if (javaVersion.equals("1.2") || javaVersion.equals("1.3")) 108 { 109 id = J2SE_13; } 111 else if (javaVersion.equals("1.4")) 112 { 113 String vmVersion = System.getProperty("java.version", "1.4.0"); 114 115 if (JVMInfo.vmCheck(vmVersion, "1.4.0") || JVMInfo.vmCheck(vmVersion, "1.4.1")) 116 id = J2SE_14; 117 else 118 id = J2SE_142; 119 } 120 else if (javaVersion.equals("1.5")) 121 { 122 id = J2SE_15; 123 } 124 else if (javaVersion.equals("1.6")) 125 { 126 id = J2SE_16; 127 } 128 else 129 { 130 id = J2SE_13; 133 134 try { 135 136 if (Float.valueOf(javaVersion).floatValue() > 1.4f) 137 id = 5; 138 } catch (NumberFormatException nfe) { 139 } 140 } 141 } 142 143 JDK_ID = id; 144 J2ME = isJ2ME; 145 JAVA_SQL_TYPES_BOOLEAN = (isJ2ME || id >= J2SE_14) ? 146 org.apache.derby.iapi.reference.JDBC30Translation.SQL_TYPES_BOOLEAN :java.sql.Types.BIT; 147 } 148 149 153 private static boolean vmCheck(String vmVersion, String id) 154 { 155 return vmVersion.equals(id) || vmVersion.startsWith(id + "_"); 156 } 157 158 161 public static String derbyVMLevel() 162 { 163 switch (JDK_ID) 164 { 165 case J2SE_13: return J2ME ? "J2ME - JDBC for CDC/FP 1.0" : "J2SE 1.3 - JDBC 2.1"; 166 case J2SE_14: return "J2SE 1.4 - JDBC 3.0"; 167 case J2SE_142: return "J2SE 1.4.2 - JDBC 3.0"; 168 case J2SE_15: return "J2SE 5.0 - JDBC 3.0"; 169 case J2SE_16: return "Java SE 6 - JDBC 4.0"; 170 default: return "?-?"; 171 } 172 } 173 } 174 | Popular Tags |