KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > Version


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22

23 /**
24  * This class stores variables for the version and build Numbers that are used in printouts and exceptions.
25  *
26  * @author Eric Gwin
27  * @since 1.0,
28  * 1.16 Added get and set Methods. Made variables private. - EJG
29  */

30 package oracle.toplink.essentials;
31
32 public class Version {
33     // The current copyright info for TopLink.
34
private static final String JavaDoc CopyrightString = "Copyright (c) 1998, 2006, Oracle. All rights reserved.";
35
36     // The current version of TopLink.
37
// This will be used by all product components and included in exceptions.
38
private static String JavaDoc product = "Oracle TopLink Essentials";
39     private static final String JavaDoc version = "2006.8";
40     private static final String JavaDoc buildNumber = "060830";
41
42     /** Keep track of JDK version in order to make some decisions about datastructures. **/
43     public static final int JDK_VERSION_NOT_SET = 0;
44     public static final int JDK_1_3 = 1;
45     public static final int JDK_1_4 = 2;
46     public static final int JDK_1_5 = 3;
47     public static int JDK_VERSION = JDK_VERSION_NOT_SET;
48
49     public static String JavaDoc getProduct() {
50         return product;
51     }
52
53     public static void setProduct(String JavaDoc ProductName) {
54         product = ProductName;
55     }
56
57     public static String JavaDoc getVersion() {
58         return version;
59     }
60
61     public static String JavaDoc getBuildNumber() {
62         return buildNumber;
63     }
64
65     /**
66     * INTERNAL:
67     * return the JDK version we are using.
68     */

69     public static int getJDKVersion() {
70         if (JDK_VERSION == JDK_VERSION_NOT_SET) {
71             String JavaDoc version = System.getProperty("java.version");
72             if ((version != null) && version.startsWith("1.5")) {
73                 useJDK15();
74             } else if ((version != null) && version.startsWith("1.4")) {
75                 useJDK14();
76             } else {
77                 useJDK13();
78             }
79         }
80         return JDK_VERSION;
81     }
82
83     public static void useJDK13() {
84         JDK_VERSION = JDK_1_3;
85     }
86
87     public static void useJDK14() {
88         JDK_VERSION = JDK_1_4;
89     }
90
91     public static void useJDK15() {
92         JDK_VERSION = JDK_1_5;
93     }
94
95     public static boolean isJDK13() {
96         return getJDKVersion() == JDK_1_3;
97     }
98
99     public static boolean isJDK14() {
100         return getJDKVersion() == JDK_1_4;
101     }
102
103     public static boolean isJDK15() {
104         return getJDKVersion() == JDK_1_5;
105     }
106 }
107
Popular Tags