001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): ____________________________________.
022: * Contributor(s): ______________________________________.
023: *
024: * --------------------------------------------------------------------------
025: * $Id: Env.java 4579 2004-04-09 10:00:58Z benoitf $
026: * --------------------------------------------------------------------------
027: */package org.objectweb.common;
028:
029: /**
030: * This class manages global variables and properties used by EJB Server. A
031: * static design pattern is used.
032: */
033: public class Env {
034:
035: /**
036: * No public constructor : utility class
037: */
038: private Env() {
039:
040: }
041:
042: // Variables related to Java Version
043: public static final int JAVA_1_1_6 = 116;
044:
045: public static final int JAVA_1_1_7 = 117;
046:
047: public static final int JAVA_1_1_8 = 118;
048:
049: public static final int JAVA_1_2 = 120;
050:
051: public static final int JAVA_1_3 = 130;
052:
053: public static final int JAVA_1_4 = 140;
054:
055: private static int javaVersion = -1;
056:
057: /**
058: * @return true if the os.name starts with "Windows"
059: */
060: public static boolean isOsWindows() {
061: String osName = System.getProperty("os.name", "");
062: return (osName.startsWith("Windows"));
063: }
064:
065: /**
066: * @return true if the os.name starts with "Mac OS X"
067: */
068: public static boolean isOsMacOsX() {
069: String osName = System.getProperty("os.name", "");
070: return (osName.startsWith("Mac OS X"));
071: }
072:
073: /**
074: * Gets Java Version.
075: * @return javaVersion or -1 if error
076: */
077: public static int getJavaVersion() {
078:
079: if (javaVersion == -1) {
080: // Sets Java Version
081: String strjv = System.getProperty("java.version", "");
082: if (strjv.indexOf("1.1.6") == 0) {
083: javaVersion = JAVA_1_1_6;
084: }
085: if (strjv.indexOf("1.1.7") == 0) {
086: javaVersion = JAVA_1_1_7;
087: }
088: if (strjv.indexOf("1.1.8") == 0) {
089: javaVersion = JAVA_1_1_8;
090: }
091: if (strjv.indexOf("1.2") == 0) {
092: javaVersion = JAVA_1_2;
093: }
094: if (strjv.indexOf("1.3") == 0) {
095: javaVersion = JAVA_1_3;
096: }
097: if (strjv.indexOf("1.4") == 0) {
098: javaVersion = JAVA_1_4;
099: }
100: }
101: return javaVersion;
102: }
103:
104: /**
105: * @return true if JDK 1.2 or later
106: */
107: public static boolean isJAVA2() {
108: return (getJavaVersion() >= JAVA_1_2);
109: }
110:
111: /**
112: * @return true if JDK 1.4 or later
113: */
114: public static boolean isJAVA4() {
115: return (getJavaVersion() >= JAVA_1_4);
116: }
117: }
|