001: /*
002:
003: Derby - Class org.apache.derby.client.am.Version
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.client.am;
023:
024: import org.apache.derby.shared.common.i18n.MessageUtil;
025:
026: public abstract class Version {
027: static MessageUtil msgutil = SqlException.getMessageUtil();
028:
029: // Constants for internationalized message ids
030: private static String SECURITY_MANAGER_NO_ACCESS_ID = "J108";
031: private static String UNKNOWN_HOST_ID = "J109";
032:
033: // Same as java.sql.DatabaseMetaData.getDriverName()
034: public static String getDriverName() {
035: return Configuration.dncDriverName;
036: }
037:
038: // for DatabaseMetaData.getDriverVersion()
039: public static String getDriverVersion() {
040: return Configuration.dncProductVersionHolder__
041: .getVersionBuildString(true);
042: }
043:
044: // Same as java.sql.Driver.getMajorVersion(), getMinorVersion()
045: public static int getMajorVersion() {
046: return Configuration.getProductVersionHolder()
047: .getMajorVersion();
048: }
049:
050: public static int getMinorVersion() {
051: return Configuration.getProductVersionHolder()
052: .getMinorVersion();
053: }
054:
055: public static int getBuildNumber() {
056: return Configuration.getProductVersionHolder()
057: .getBuildNumberAsInt();
058: }
059:
060: public static int getProtocolMaintVersion() {
061: return Configuration.getProductVersionHolder()
062: .getDrdaMaintVersion();
063: }
064:
065: public static boolean isAlpha() {
066: return Configuration.getProductVersionHolder().isAlpha();
067: }
068:
069: public static boolean isBeta() {
070: return Configuration.getProductVersionHolder().isBeta();
071: }
072:
073: // Not an external, just a helper method
074: private static String getDriverNameAndVersion() {
075: return Configuration.dncDriverName
076: + " "
077: + Configuration.dncProductVersionHolder__
078: .getVersionBuildString(true);
079: }
080:
081: // -------------------------- configuration print stream ---------------------
082:
083: public static void writeDriverConfiguration(
084: java.io.PrintWriter printWriter) {
085: String header = "[derby] ";
086: synchronized (printWriter) {
087: printWriter.println(header
088: + "BEGIN TRACE_DRIVER_CONFIGURATION");
089: printWriter.println(header + "Driver: "
090: + getDriverNameAndVersion());
091:
092: printWriter.print(header + "Compatible JRE versions: { ");
093: for (int i = 0; i < Configuration.dncCompatibleJREVersions.length; i++) {
094: printWriter
095: .print(Configuration.dncCompatibleJREVersions[i]);
096: if (i != Configuration.dncCompatibleJREVersions.length - 1) {
097: printWriter.print(", ");
098: }
099: }
100: printWriter.println(" }");
101:
102: printWriter.println(header + "Range checking enabled: "
103: + Configuration.rangeCheckCrossConverters);
104: printWriter.println(header + "Bug check level: 0x"
105: + Integer.toHexString(Configuration.bugCheckLevel));
106: printWriter.println(header + "Default fetch size: "
107: + Configuration.defaultFetchSize);
108: printWriter.println(header + "Default isolation: "
109: + Configuration.defaultIsolation);
110:
111: java.lang.SecurityManager security = java.lang.System
112: .getSecurityManager();
113: if (security == null) {
114: printWriter.println(header
115: + "No security manager detected.");
116: } else {
117: printWriter.println(header
118: + "Security manager detected.");
119: }
120:
121: detectLocalHost(java.lang.System.getSecurityManager(),
122: printWriter);
123:
124: printSystemProperty(security,
125: "JDBC 1 system property jdbc.drivers = ",
126: "jdbc.drivers", printWriter);
127:
128: printSystemProperty(security,
129: "Java Runtime Environment version ",
130: "java.version", printWriter);
131: printSystemProperty(security,
132: "Java Runtime Environment vendor = ",
133: "java.vendor", printWriter);
134: printSystemProperty(security, "Java vendor URL = ",
135: "java.vendor.url", printWriter);
136: printSystemProperty(security,
137: "Java installation directory = ", "java.home",
138: printWriter);
139: printSystemProperty(security,
140: "Java Virtual Machine specification version = ",
141: "java.vm.specification.version", printWriter);
142: printSystemProperty(security,
143: "Java Virtual Machine specification vendor = ",
144: "java.vm.specification.vendor", printWriter);
145: printSystemProperty(security,
146: "Java Virtual Machine specification name = ",
147: "java.vm.specification.name", printWriter);
148: printSystemProperty(security,
149: "Java Virtual Machine implementation version = ",
150: "java.vm.version", printWriter);
151: printSystemProperty(security,
152: "Java Virtual Machine implementation vendor = ",
153: "java.vm.vendor", printWriter);
154: printSystemProperty(security,
155: "Java Virtual Machine implementation name = ",
156: "java.vm.name", printWriter);
157: printSystemProperty(
158: security,
159: "Java Runtime Environment specification version = ",
160: "java.specification.version", printWriter);
161: printSystemProperty(security,
162: "Java Runtime Environment specification vendor = ",
163: "java.specification.vendor", printWriter);
164: printSystemProperty(security,
165: "Java Runtime Environment specification name = ",
166: "java.specification.name", printWriter);
167: printSystemProperty(security,
168: "Java class format version number = ",
169: "java.class.version", printWriter);
170: printSystemProperty(security, "Java class path = ",
171: "java.class.path", printWriter);
172: printSystemProperty(security,
173: "Java native library path = ", "java.library.path",
174: printWriter);
175: printSystemProperty(security,
176: "Path of extension directory or directories = ",
177: "java.ext.dirs", printWriter);
178: printSystemProperty(security, "Operating system name = ",
179: "os.name", printWriter);
180: printSystemProperty(security,
181: "Operating system architecture = ", "os.arch",
182: printWriter);
183: printSystemProperty(security,
184: "Operating system version = ", "os.version",
185: printWriter);
186: printSystemProperty(security,
187: "File separator (\"/\" on UNIX) = ",
188: "file.separator", printWriter);
189: printSystemProperty(security,
190: "Path separator (\":\" on UNIX) = ",
191: "path.separator", printWriter);
192: printSystemProperty(security, "User's account name = ",
193: "user.name", printWriter);
194: printSystemProperty(security, "User's home directory = ",
195: "user.home", printWriter);
196: printSystemProperty(security,
197: "User's current working directory = ", "user.dir",
198: printWriter);
199: printWriter.println(header
200: + "END TRACE_DRIVER_CONFIGURATION");
201: printWriter.flush();
202: }
203: }
204:
205: private static void printSystemProperty(
206: java.lang.SecurityManager security, String prefix,
207: String property, java.io.PrintWriter printWriter) {
208: String header = "[derby] ";
209: synchronized (printWriter) {
210: try {
211: if (security != null) {
212: security.checkPropertyAccess(property);
213: }
214: String result = System.getProperty(property);
215: printWriter.println(header + prefix + result);
216: printWriter.flush();
217: } catch (SecurityException e) {
218: printWriter.println(header
219: + msgutil
220: .getTextMessage(
221: SECURITY_MANAGER_NO_ACCESS_ID,
222: property));
223: printWriter.flush();
224: }
225: }
226: }
227:
228: // printWriter synchronized by caller
229: private static void detectLocalHost(
230: java.lang.SecurityManager security,
231: java.io.PrintWriter printWriter) {
232: String header = "[derby] ";
233: // getLocalHost() will hang the HotJava 1.0 browser with a high security manager.
234: if (security == null) {
235: try {
236: printWriter.print(header
237: + "Detected local client host: ");
238: printWriter.println(java.net.InetAddress.getLocalHost()
239: .toString());
240: printWriter.flush();
241: } catch (java.net.UnknownHostException e) {
242: printWriter.println(header
243: + msgutil.getTextMessage(UNKNOWN_HOST_ID, e
244: .getMessage()));
245: printWriter.flush();
246: }
247: }
248: }
249: }
|