Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / services / info / JVMInfo.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
new file mode 100644 (file)
index 0000000..e917c23
--- /dev/null
@@ -0,0 +1,173 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.services.info.JVMInfo\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.services.info;\r
+\r
+\r
+/**\r
+       This class is used to determine which Java specification Derby will run at.\r
+    For a useful discussion of how this class is used, please see DERBY-3176.\r
+ */\r
+public abstract class JVMInfo\r
+{\r
+       /**\r
+               The JVM's runtime environment.\r
+               <UL>\r
+               <LI> 1 - not used was JDK 1.1\r
+               <LI> 2 - not used, was for JDK 1.2 and 1.3\r
+               <LI> 4 - J2SE_14 - JDK 1.4.0 or 1.4.1\r
+               <LI> 5 - J2SE_142 - JDK 1.4.2\r
+               <LI> 6 - J2SE_15 - JDK 1.5\r
+               <LI> 7 - J2SE_16 - JDK 1.6\r
+               </UL>\r
+       */\r
+       public static final int JDK_ID;\r
+\r
+       public static final int J2SE_13 = 2;\r
+       public static final int J2SE_14 = 4;\r
+       public static final int J2SE_142 = 5;\r
+       public static final int J2SE_15 = 6; // aka J2SE 5.0\r
+       public static final int J2SE_16 = 7; // Java SE 6, not J2SE\r
+\r
+       public static final boolean J2ME;\r
+\r
+       /**\r
+    JDBC Boolean type - Types.BIT in JDK1.1 & 1.2 & 1.3, Types.BOOLEAN in JDK1.4\r
+       */\r
+       public static final int JAVA_SQL_TYPES_BOOLEAN;\r
+\r
+       static \r
+       {\r
+               int id;\r
+\r
+               //\r
+               // If the property java.specification.version is set, then try to parse\r
+               // that.  Anything we don't recognize, default to Java 2 platform\r
+               // because java.specification.version is a property that is introduced\r
+               // in Java 2.  We hope that JVM vendors don't implement Java 1 and\r
+               // set a Java 2 system property.\r
+               // \r
+               // Otherwise, see if we recognize what is set in java.version.\r
+               // If we don't recoginze that, or if the property is not set, assume\r
+               // version 1.3.\r
+               //\r
+               String javaVersion;\r
+               String javaSpec;\r
+               boolean isJ2ME;\r
+\r
+               try {\r
+                       javaSpec = System.getProperty("java.specification.name");\r
+               } catch (SecurityException se) {\r
+                       // some vms do not know about this property so they\r
+                       // throw a security exception when access is restricted.\r
+                       javaSpec = null;\r
+               }\r
+\r
+               try {\r
+                       javaVersion = System.getProperty("java.specification.version", "1.4");\r
+\r
+               } catch (SecurityException se) {\r
+                       // some vms do not know about this property so they\r
+                       // throw a security exception when access is restricted.\r
+                       javaVersion = "1.4";\r
+               }\r
+\r
+               if (javaSpec != null &&\r
+            (\r
+             javaSpec.startsWith("J2ME") || // recognize IBM WCTME\r
+             (\r
+              (javaSpec.indexOf( "Profile" ) > -1) && // recognize phoneME\r
+              (javaSpec.indexOf( "Specification" ) > -1)\r
+             )\r
+            )\r
+            )\r
+               {\r
+                       id = J2SE_14;\r
+                       isJ2ME = true;\r
+               }\r
+               else\r
+               {\r
+                       // J2SE/J2EE\r
+                       isJ2ME = false;\r
+\r
+                       if (javaVersion.equals("1.4"))\r
+                       {\r
+                               String vmVersion = System.getProperty("java.version", "1.4.0");\r
+\r
+                               if (JVMInfo.vmCheck(vmVersion, "1.4.0") || JVMInfo.vmCheck(vmVersion, "1.4.1"))\r
+                                       id = J2SE_14;\r
+                               else\r
+                                       id = J2SE_142;\r
+                       }\r
+                       else if (javaVersion.equals("1.5"))\r
+                       {\r
+                               id = J2SE_15;\r
+                       }\r
+                       else if (javaVersion.equals("1.6"))\r
+                       {\r
+                               id = J2SE_16;\r
+                       }\r
+                       else\r
+                       {\r
+                               // aussme our lowest support unless the java spec\r
+                               // is greater than our highest level.\r
+                               id = J2SE_14;\r
+\r
+                               try {\r
+\r
+                                       if (Float.valueOf(javaVersion).floatValue() > 1.6f)\r
+                                               id = J2SE_16;\r
+                               } catch (NumberFormatException nfe) {\r
+                               }\r
+                       }\r
+               }\r
+\r
+               JDK_ID = id;\r
+               J2ME = isJ2ME;\r
+               JAVA_SQL_TYPES_BOOLEAN = (isJ2ME || id >= J2SE_14) ?\r
+                       org.apache.derby.iapi.reference.JDBC30Translation.SQL_TYPES_BOOLEAN :java.sql.Types.BIT;\r
+       }\r
+\r
+       /**\r
+               Check the vmVersion against a speciifc value.\r
+               Sun jvms are of the form\r
+       */\r
+       private static boolean vmCheck(String vmVersion, String id)\r
+       {\r
+               return vmVersion.equals(id) || vmVersion.startsWith(id + "_");\r
+       }\r
+\r
+       /**\r
+               Return Derby's understanding of the virtual machine's environment.\r
+       */\r
+       public static String derbyVMLevel()\r
+       {\r
+               switch (JDK_ID)\r
+               {\r
+               case J2SE_14: return J2ME ? "J2ME - JDBC for CDC/FP 1.1" : "J2SE 1.4 - JDBC 3.0";\r
+               case J2SE_142: return "J2SE 1.4.2 - JDBC 3.0";\r
+               case J2SE_15: return "J2SE 5.0 - JDBC 3.0";\r
+               case J2SE_16: return "Java SE 6 - JDBC 4.0";\r
+               default: return "?-?";\r
+               }\r
+       }\r
+\r
+}\r