EMMA Coverage Report (generated Wed Jun 28 22:15:27 PDT 2006)
[all classes][org.apache.derby.iapi.services.info]

COVERAGE SUMMARY FOR SOURCE FILE [JVMInfo.java]

nameclass, %method, %block, %line, %
JVMInfo.java100% (1/1)75%  (3/4)72%  (95/132)59%  (22.6/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JVMInfo100% (1/1)75%  (3/4)72%  (95/132)59%  (22.6/38)
<static initializer> 100% (1/1)72%  (68/94)60%  (18/30)
JVMInfo (): void 0%   (0/1)0%   (0/3)0%   (0/1)
derbyVMLevel (): String 100% (1/1)62%  (10/16)61%  (3.7/6)
vmCheck (String, String): boolean 100% (1/1)89%  (17/19)89%  (0.9/1)

1/*
2 
3   Derby - Class org.apache.derby.iapi.services.info.JVMInfo
4 
5   Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable.
6 
7   Licensed under the Apache License, Version 2.0 (the "License");
8   you may not use this file except in compliance with the License.
9   You may obtain a copy of the License at
10 
11      http://www.apache.org/licenses/LICENSE-2.0
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 
19 */
20 
21package org.apache.derby.iapi.services.info;
22 
23 
24/**
25        What's the current JDK runtime environment.
26 */
27public abstract class JVMInfo
28{
29        /**
30                The JVM's runtime environment.
31                <UL>
32                <LI> 1 - not used was JDK 1.1
33                <LI> 2 - J2SE_13- JDK 1.2, 1.3
34                <LI> 4 - J2SE_14 - JDK 1.4.0 or 1.4.1
35                <LI> 5 - J2SE_142 - JDK 1.4.2
36                <LI> 6 - J2SE_15 - JDK 1.5
37                </UL>
38        */
39        public static final int JDK_ID;
40 
41        public static final int J2SE_13 = 2;
42        public static final int J2SE_14 = 4;
43        public static final int J2SE_142 = 5;
44        public static final int J2SE_15 = 6; // aka J2SE 5.0
45        public static final int J2SE_16 = 7; 
46 
47        public static final boolean J2ME;
48 
49        /**
50    JDBC Boolean type - Types.BIT in JDK1.1 & 1.2 & 1.3, Types.BOOLEAN in JDK1.4
51        */
52        public static final int JAVA_SQL_TYPES_BOOLEAN;
53 
54        static 
55        {
56                int id;
57 
58                //
59                // If the property java.specification.version is set, then try to parse
60                // that.  Anything we don't recognize, default to Java 2 platform
61                // because java.specification.version is a property that is introduced
62                // in Java 2.  We hope that JVM vendors don't implement Java 1 and
63                // set a Java 2 system property.
64                // 
65                // Otherwise, see if we recognize what is set in java.version.
66                // If we don't recoginze that, or if the property is not set, assume
67                // version 1.3.
68                //
69                String javaVersion;
70                String javaSpec;
71                boolean isJ2ME;
72 
73                try {
74                        javaSpec = System.getProperty("java.specification.name");
75                } catch (SecurityException se) {
76                        // some vms do not know about this property so they
77                        // throw a security exception when access is restricted.
78                        javaSpec = null;
79                }
80 
81                try {
82                        javaVersion = System.getProperty("java.specification.version", "1.3");
83 
84                } catch (SecurityException se) {
85                        // some vms do not know about this property so they
86                        // throw a security exception when access is restricted.
87                        javaVersion = "1.3";
88                }
89 
90                if (javaSpec != null && javaSpec.startsWith("J2ME"))
91                {
92                        // IBM's WCTME 5.7 returns these values for CDC 1.0 profiles.
93                        // "J2ME Foundation Specification"
94                        //
95 
96                        // Foundation 1.0 and Personal Profile 1.0 based
97                        // upon CDC 1.0 which is JDK 1.3 based
98                        id = J2SE_13;
99                        isJ2ME = true;
100                }
101                else
102                {
103                        // J2SE/J2EE
104                        isJ2ME = false;
105 
106                        if (javaVersion.equals("1.2") || javaVersion.equals("1.3"))
107                        {        
108                                id = J2SE_13; //jdk1.3 is still Java2 platform with the same API
109                        }
110                        else if (javaVersion.equals("1.4"))
111                        {
112                                String vmVersion = System.getProperty("java.version", "1.4.0");
113 
114                                if (JVMInfo.vmCheck(vmVersion, "1.4.0") || JVMInfo.vmCheck(vmVersion, "1.4.1"))
115                                        id = J2SE_14;
116                                else
117                                        id = J2SE_142;
118                        }
119                        else if (javaVersion.equals("1.5"))
120                        {
121                                id = J2SE_15;
122                        }
123                        else if (javaVersion.equals("1.6"))
124                        {
125                                id = J2SE_16;
126                        }
127                        else
128                        {
129                                // aussme our lowest support unless the java spec
130                                // is greater than our highest level.
131                                id = J2SE_13;
132 
133                                try {
134 
135                                        if (Float.valueOf(javaVersion).floatValue() > 1.4f)
136                                                id = 5;
137                                } catch (NumberFormatException nfe) {
138                                }
139                        }
140                }
141 
142                JDK_ID = id;
143                J2ME = isJ2ME;
144                JAVA_SQL_TYPES_BOOLEAN = (isJ2ME || id >= J2SE_14) ?
145                        org.apache.derby.iapi.reference.JDBC30Translation.SQL_TYPES_BOOLEAN :java.sql.Types.BIT;
146        }
147 
148        /**
149                Check the vmVersion against a speciifc value.
150                Sun jvms are of the form
151        */
152        private static boolean vmCheck(String vmVersion, String id)
153        {
154                return vmVersion.equals(id) || vmVersion.startsWith(id + "_");
155        }
156 
157        /**
158                Return Derby's understanding of the virtual machine's environment.
159        */
160        public static String derbyVMLevel()
161        {
162                switch (JDK_ID)
163                {
164                case J2SE_13: return J2ME ? "J2ME - JDBC for CDC/FP 1.0" : "J2SE 1.3 - JDBC 2.1";
165                case J2SE_14: return "J2SE 1.4 - JDBC 3.0";
166                case J2SE_142: return "J2SE 1.4.2 - JDBC 3.0";
167                case J2SE_15: return "J2SE 5.0 - JDBC 3.0";
168                default: return "?-?";
169                }
170        }
171}

[all classes][org.apache.derby.iapi.services.info]
EMMA 2.0.5312 (C) Vladimir Roubtsov