KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > Version


1 /*
2
3    Derby - Class org.apache.derby.client.am.Version
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import org.apache.derby.shared.common.i18n.MessageUtil;
25
26
27
28 public abstract class Version {
29     static MessageUtil msgutil = SqlException.getMessageUtil();
30     
31     // Constants for internationalized message ids
32
private static String JavaDoc SECURITY_MANAGER_NO_ACCESS_ID = "J108";
33     private static String JavaDoc UNKNOWN_HOST_ID = "J109";
34     
35     // Same as java.sql.DatabaseMetaData.getDriverName()
36
public static String JavaDoc getDriverName() {
37         return Configuration.dncDriverName;
38     }
39
40     // for DatabaseMetaData.getDriverVersion()
41
public static String JavaDoc getDriverVersion() {
42         return Configuration.dncProductVersionHolder__.getVersionBuildString(true);
43     }
44
45
46     // Same as java.sql.Driver.getMajorVersion(), getMinorVersion()
47
public static int getMajorVersion() {
48         return Configuration.getProductVersionHolder().getMajorVersion();
49     }
50
51     public static int getMinorVersion() {
52         return Configuration.getProductVersionHolder().getMinorVersion();
53     }
54
55     public static int getBuildNumber() {
56         return Configuration.getProductVersionHolder().getBuildNumberAsInt();
57     }
58
59     public static int getProtocolMaintVersion() {
60         return Configuration.getProductVersionHolder().getDrdaMaintVersion();
61     }
62
63     public static boolean isAlpha() {
64         return Configuration.getProductVersionHolder().isAlpha();
65     }
66
67     public static boolean isBeta() {
68         return Configuration.getProductVersionHolder().isBeta();
69     }
70
71     // Not an external, just a helper method
72
private static String JavaDoc getDriverNameAndVersion() {
73         return Configuration.dncDriverName + " " +
74                 Configuration.dncProductVersionHolder__.getVersionBuildString(true);
75     }
76
77     // -------------------------- configuration print stream ---------------------
78

79     public static void writeDriverConfiguration(java.io.PrintWriter JavaDoc printWriter) {
80         String JavaDoc header = "[derby] ";
81         synchronized (printWriter) {
82             printWriter.println(header + "BEGIN TRACE_DRIVER_CONFIGURATION");
83             printWriter.println(header + "Driver: " + getDriverNameAndVersion());
84
85             printWriter.print(header + "Compatible JRE versions: { ");
86             for (int i = 0; i < Configuration.dncCompatibleJREVersions.length; i++) {
87                 printWriter.print(Configuration.dncCompatibleJREVersions[i]);
88                 if (i != Configuration.dncCompatibleJREVersions.length - 1) {
89                     printWriter.print(", ");
90                 }
91             }
92             printWriter.println(" }");
93
94             printWriter.println(header + "Range checking enabled: " + Configuration.rangeCheckCrossConverters);
95             printWriter.println(header + "Bug check level: 0x" + Integer.toHexString(Configuration.bugCheckLevel));
96             printWriter.println(header + "Default fetch size: " + Configuration.defaultFetchSize);
97             printWriter.println(header + "Default isolation: " + Configuration.defaultIsolation);
98
99             java.lang.SecurityManager JavaDoc security = java.lang.System.getSecurityManager();
100             if (security == null) {
101                 printWriter.println(header + "No security manager detected.");
102             } else {
103                 printWriter.println(header + "Security manager detected.");
104             }
105
106             detectLocalHost(java.lang.System.getSecurityManager(), printWriter);
107
108             printSystemProperty(security, "JDBC 1 system property jdbc.drivers = ", "jdbc.drivers", printWriter);
109
110             printSystemProperty(security, "Java Runtime Environment version ", "java.version", printWriter);
111             printSystemProperty(security, "Java Runtime Environment vendor = ", "java.vendor", printWriter);
112             printSystemProperty(security, "Java vendor URL = ", "java.vendor.url", printWriter);
113             printSystemProperty(security, "Java installation directory = ", "java.home", printWriter);
114             printSystemProperty(security, "Java Virtual Machine specification version = ", "java.vm.specification.version", printWriter);
115             printSystemProperty(security, "Java Virtual Machine specification vendor = ", "java.vm.specification.vendor", printWriter);
116             printSystemProperty(security, "Java Virtual Machine specification name = ", "java.vm.specification.name", printWriter);
117             printSystemProperty(security, "Java Virtual Machine implementation version = ", "java.vm.version", printWriter);
118             printSystemProperty(security, "Java Virtual Machine implementation vendor = ", "java.vm.vendor", printWriter);
119             printSystemProperty(security, "Java Virtual Machine implementation name = ", "java.vm.name", printWriter);
120             printSystemProperty(security, "Java Runtime Environment specification version = ", "java.specification.version", printWriter);
121             printSystemProperty(security, "Java Runtime Environment specification vendor = ", "java.specification.vendor", printWriter);
122             printSystemProperty(security, "Java Runtime Environment specification name = ", "java.specification.name", printWriter);
123             printSystemProperty(security, "Java class format version number = ", "java.class.version", printWriter);
124             printSystemProperty(security, "Java class path = ", "java.class.path", printWriter);
125             printSystemProperty(security, "Java native library path = ", "java.library.path", printWriter);
126             printSystemProperty(security, "Path of extension directory or directories = ", "java.ext.dirs", printWriter);
127             printSystemProperty(security, "Operating system name = ", "os.name", printWriter);
128             printSystemProperty(security, "Operating system architecture = ", "os.arch", printWriter);
129             printSystemProperty(security, "Operating system version = ", "os.version", printWriter);
130             printSystemProperty(security, "File separator (\"/\" on UNIX) = ", "file.separator", printWriter);
131             printSystemProperty(security, "Path separator (\":\" on UNIX) = ", "path.separator", printWriter);
132             printSystemProperty(security, "User's account name = ", "user.name", printWriter);
133             printSystemProperty(security, "User's home directory = ", "user.home", printWriter);
134             printSystemProperty(security, "User's current working directory = ", "user.dir", printWriter);
135             printWriter.println(header + "END TRACE_DRIVER_CONFIGURATION");
136             printWriter.flush();
137         }
138     }
139
140     private static void printSystemProperty(java.lang.SecurityManager JavaDoc security,
141                                             String JavaDoc prefix,
142                                             String JavaDoc property,
143                                             java.io.PrintWriter JavaDoc printWriter) {
144         String JavaDoc header = "[derby] ";
145         synchronized (printWriter) {
146             try {
147                 if (security != null) {
148                     security.checkPropertyAccess(property);
149                 }
150                 String JavaDoc result = System.getProperty(property);
151                 printWriter.println(header + prefix + result);
152                 printWriter.flush();
153             } catch (SecurityException JavaDoc e) {
154                 printWriter.println(header +
155                     msgutil.getTextMessage(SECURITY_MANAGER_NO_ACCESS_ID, property));
156                 printWriter.flush();
157             }
158         }
159     }
160
161     // printWriter synchronized by caller
162
private static void detectLocalHost(java.lang.SecurityManager JavaDoc security, java.io.PrintWriter JavaDoc printWriter) {
163         String JavaDoc header = "[derby] ";
164         // getLocalHost() will hang the HotJava 1.0 browser with a high security manager.
165
if (security == null) {
166             try {
167                 printWriter.print(header + "Detected local client host: ");
168                 printWriter.println(java.net.InetAddress.getLocalHost().toString());
169                 printWriter.flush();
170             } catch (java.net.UnknownHostException JavaDoc e) {
171                 printWriter.println(header +
172                     msgutil.getTextMessage(UNKNOWN_HOST_ID, e.getMessage()));
173                 printWriter.flush();
174             }
175         }
176     }
177 }
178
Popular Tags