KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > Platform


1 /*
2  * Platform.java
3  *
4  * Copyright (C) 1998-2004 Peter Graves
5  * $Id: Platform.java,v 1.5 2004/06/09 23:44:24 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 public final class Platform
25 {
26     private static final String JavaDoc osName = System.getProperty("os.name");
27     private static final boolean isPlatformLinux = osName.startsWith("Linux");
28     private static final boolean isPlatformUnix =
29         isPlatformLinux || osName.startsWith("Mac OS X") ||
30         osName.startsWith("Solaris") || osName.startsWith("SunOS") ||
31         osName.startsWith("AIX");
32     private static final boolean isPlatformWindows =
33         osName.startsWith("Windows");
34     private static final boolean isJava13 =
35         System.getProperty("java.version").startsWith("1.3");
36     private static final boolean isJava14 =
37         System.getProperty("java.version").startsWith("1.4");
38     private static final boolean isJava140 =
39         System.getProperty("java.version").startsWith("1.4.0");
40
41     public static final boolean isPlatformLinux()
42     {
43         return isPlatformLinux;
44     }
45
46     public static final boolean isPlatformUnix()
47     {
48         return isPlatformUnix;
49     }
50
51     public static final boolean isPlatformWindows()
52     {
53         return isPlatformWindows;
54     }
55
56     public static final boolean isPlatformMacOSX()
57     {
58         return osName.startsWith("Mac OS X");
59     }
60
61     public static final boolean isPlatformWindows5()
62     {
63         if (!isPlatformWindows)
64             return false;
65         final String JavaDoc version = System.getProperty("os.version");
66         int index = version.indexOf('.');
67         final String JavaDoc s = index >= 0 ? version.substring(0, index) : version;
68         try {
69             final int major = Integer.parseInt(s);
70             return major >= 5;
71         }
72         catch (NumberFormatException JavaDoc e) {
73             Log.error(e);
74             return false;
75         }
76     }
77
78     public static final boolean isPlatformWindowsNT4()
79     {
80         if (!isPlatformWindows)
81             return false;
82         if (osName.indexOf("Windows NT") < 0)
83             return false;
84         final String JavaDoc version = System.getProperty("os.version");
85         int index = version.indexOf('.');
86         final String JavaDoc s = index >= 0 ? version.substring(0, index) : version;
87         try {
88             final int major = Integer.parseInt(s);
89             return major >= 4;
90         }
91         catch (NumberFormatException JavaDoc e) {
92             Log.error(e);
93             return false;
94         }
95     }
96
97     public static final boolean isJava13()
98     {
99         return isJava13;
100     }
101
102     public static final boolean isJava14()
103     {
104         return isJava14;
105     }
106
107     public static final boolean isJava140()
108     {
109         return isJava140;
110     }
111 }
112
Popular Tags