001: /*
002:
003: Derby - Class org.apache.derby.iapi.services.info.JVMInfo
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.services.info;
023:
024: /**
025: What's the current JDK runtime environment.
026: */
027: public abstract class JVMInfo {
028: /**
029: The JVM's runtime environment.
030: <UL>
031: <LI> 1 - not used was JDK 1.1
032: <LI> 2 - J2SE_13- JDK 1.2, 1.3
033: <LI> 4 - J2SE_14 - JDK 1.4.0 or 1.4.1
034: <LI> 5 - J2SE_142 - JDK 1.4.2
035: <LI> 6 - J2SE_15 - JDK 1.5
036: </UL>
037: */
038: public static final int JDK_ID;
039:
040: public static final int J2SE_13 = 2;
041: public static final int J2SE_14 = 4;
042: public static final int J2SE_142 = 5;
043: public static final int J2SE_15 = 6; // aka J2SE 5.0
044: public static final int J2SE_16 = 7; // Java SE 6, not J2SE
045:
046: public static final boolean J2ME;
047:
048: /**
049: JDBC Boolean type - Types.BIT in JDK1.1 & 1.2 & 1.3, Types.BOOLEAN in JDK1.4
050: */
051: public static final int JAVA_SQL_TYPES_BOOLEAN;
052:
053: static {
054: int id;
055:
056: //
057: // If the property java.specification.version is set, then try to parse
058: // that. Anything we don't recognize, default to Java 2 platform
059: // because java.specification.version is a property that is introduced
060: // in Java 2. We hope that JVM vendors don't implement Java 1 and
061: // set a Java 2 system property.
062: //
063: // Otherwise, see if we recognize what is set in java.version.
064: // If we don't recoginze that, or if the property is not set, assume
065: // version 1.3.
066: //
067: String javaVersion;
068: String javaSpec;
069: boolean isJ2ME;
070:
071: try {
072: javaSpec = System.getProperty("java.specification.name");
073: } catch (SecurityException se) {
074: // some vms do not know about this property so they
075: // throw a security exception when access is restricted.
076: javaSpec = null;
077: }
078:
079: try {
080: javaVersion = System.getProperty(
081: "java.specification.version", "1.3");
082:
083: } catch (SecurityException se) {
084: // some vms do not know about this property so they
085: // throw a security exception when access is restricted.
086: javaVersion = "1.3";
087: }
088:
089: if (javaSpec != null && javaSpec.startsWith("J2ME")) {
090: // IBM's WCTME 5.7 returns these values for CDC 1.0 profiles.
091: // "J2ME Foundation Specification"
092: //
093:
094: // Foundation 1.0 and Personal Profile 1.0 based
095: // upon CDC 1.0 which is JDK 1.3 based
096: id = J2SE_13;
097: isJ2ME = true;
098: } else {
099: // J2SE/J2EE
100: isJ2ME = false;
101:
102: if (javaVersion.equals("1.2") || javaVersion.equals("1.3")) {
103: id = J2SE_13; //jdk1.3 is still Java2 platform with the same API
104: } else if (javaVersion.equals("1.4")) {
105: String vmVersion = System.getProperty("java.version",
106: "1.4.0");
107:
108: if (JVMInfo.vmCheck(vmVersion, "1.4.0")
109: || JVMInfo.vmCheck(vmVersion, "1.4.1"))
110: id = J2SE_14;
111: else
112: id = J2SE_142;
113: } else if (javaVersion.equals("1.5")) {
114: id = J2SE_15;
115: } else if (javaVersion.equals("1.6")) {
116: id = J2SE_16;
117: } else {
118: // aussme our lowest support unless the java spec
119: // is greater than our highest level.
120: id = J2SE_13;
121:
122: try {
123:
124: if (Float.valueOf(javaVersion).floatValue() > 1.4f)
125: id = 5;
126: } catch (NumberFormatException nfe) {
127: }
128: }
129: }
130:
131: JDK_ID = id;
132: J2ME = isJ2ME;
133: JAVA_SQL_TYPES_BOOLEAN = (isJ2ME || id >= J2SE_14) ? org.apache.derby.iapi.reference.JDBC30Translation.SQL_TYPES_BOOLEAN
134: : java.sql.Types.BIT;
135: }
136:
137: /**
138: Check the vmVersion against a speciifc value.
139: Sun jvms are of the form
140: */
141: private static boolean vmCheck(String vmVersion, String id) {
142: return vmVersion.equals(id) || vmVersion.startsWith(id + "_");
143: }
144:
145: /**
146: Return Derby's understanding of the virtual machine's environment.
147: */
148: public static String derbyVMLevel() {
149: switch (JDK_ID) {
150: case J2SE_13:
151: return J2ME ? "J2ME - JDBC for CDC/FP 1.0"
152: : "J2SE 1.3 - JDBC 2.1";
153: case J2SE_14:
154: return "J2SE 1.4 - JDBC 3.0";
155: case J2SE_142:
156: return "J2SE 1.4.2 - JDBC 3.0";
157: case J2SE_15:
158: return "J2SE 5.0 - JDBC 3.0";
159: case J2SE_16:
160: return "Java SE 6 - JDBC 4.0";
161: default:
162: return "?-?";
163: }
164: }
165: }
|