KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > common > Env


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): ____________________________________.
22  * Contributor(s): ______________________________________.
23  *
24  * --------------------------------------------------------------------------
25  * $Id: Env.java,v 1.10 2004/04/09 10:00:58 benoitf Exp $
26  * --------------------------------------------------------------------------
27  */

28
29 package org.objectweb.common;
30
31 /**
32  * This class manages global variables and properties used by EJB Server. A
33  * static design pattern is used.
34  */

35 public class Env {
36
37     /**
38      * No public constructor : utility class
39      */

40     private Env() {
41
42     }
43
44     // Variables related to Java Version
45
public static final int JAVA_1_1_6 = 116;
46
47     public static final int JAVA_1_1_7 = 117;
48
49     public static final int JAVA_1_1_8 = 118;
50
51     public static final int JAVA_1_2 = 120;
52
53     public static final int JAVA_1_3 = 130;
54
55     public static final int JAVA_1_4 = 140;
56
57     private static int javaVersion = -1;
58
59     /**
60      * @return true if the os.name starts with "Windows"
61      */

62     public static boolean isOsWindows() {
63         String JavaDoc osName = System.getProperty("os.name", "");
64         return (osName.startsWith("Windows"));
65     }
66
67     /**
68      * @return true if the os.name starts with "Mac OS X"
69      */

70     public static boolean isOsMacOsX() {
71         String JavaDoc osName = System.getProperty("os.name", "");
72         return (osName.startsWith("Mac OS X"));
73     }
74
75     /**
76      * Gets Java Version.
77      * @return javaVersion or -1 if error
78      */

79     public static int getJavaVersion() {
80
81         if (javaVersion == -1) {
82             // Sets Java Version
83
String JavaDoc strjv = System.getProperty("java.version", "");
84             if (strjv.indexOf("1.1.6") == 0) {
85                 javaVersion = JAVA_1_1_6;
86             }
87             if (strjv.indexOf("1.1.7") == 0) {
88                 javaVersion = JAVA_1_1_7;
89             }
90             if (strjv.indexOf("1.1.8") == 0) {
91                 javaVersion = JAVA_1_1_8;
92             }
93             if (strjv.indexOf("1.2") == 0) {
94                 javaVersion = JAVA_1_2;
95             }
96             if (strjv.indexOf("1.3") == 0) {
97                 javaVersion = JAVA_1_3;
98             }
99             if (strjv.indexOf("1.4") == 0) {
100                 javaVersion = JAVA_1_4;
101             }
102         }
103         return javaVersion;
104     }
105
106     /**
107      * @return true if JDK 1.2 or later
108      */

109     public static boolean isJAVA2() {
110         return (getJavaVersion() >= JAVA_1_2);
111     }
112
113     /**
114      * @return true if JDK 1.4 or later
115      */

116     public static boolean isJAVA4() {
117         return (getJavaVersion() >= JAVA_1_4);
118     }
119 }
120
121
Popular Tags