21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt;
27
28 import java.security.PrivilegedAction;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import static sun.awt.OSInfo.OSType.*;
33
34 /**
35 * @author Pavel Porvatov
36 */
37 public class OSInfo {
38 public static enum OSType {
39 WINDOWS,
40 LINUX,
41 SOLARIS,
42 MACOSX,
43 AIX,
44 UNKNOWN
45 }
46
47 /*
48 The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN,
49 and so the method getWindowsVersion() will return the constant for known OS.
50 It allows compare objects by "==" instead of "equals".
51 */
52 public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(-1, -1);
53 public static final WindowsVersion WINDOWS_95 = new WindowsVersion(4, 0);
54 public static final WindowsVersion WINDOWS_98 = new WindowsVersion(4, 10);
55 public static final WindowsVersion WINDOWS_ME = new WindowsVersion(4, 90);
56 public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(5, 0);
57 public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1);
58 public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2);
59 public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0);
60 public static final WindowsVersion WINDOWS_7 = new WindowsVersion(6, 1);
61
81 }
82 };
83
84 private OSInfo() {
85 // Don't allow to create instances
86 }
87
88 /**
89 * Returns type of operating system.
90 */
91 public static OSType getOSType() throws SecurityException {
92 String osName = System.getProperty(OS_NAME);
93
94 if (osName != null) {
95 if (osName.contains("Windows")) {
96 return WINDOWS;
97 }
98
99 if (osName.contains("Linux")) {
100 return LINUX;
101 }
102
103 if (osName.contains("Solaris") || osName.contains("SunOS")) {
104 return SOLARIS;
105 }
106
107 if (osName.contains("OS X")) {
108 return MACOSX;
109 }
110
111 if (osName.contains("AIX")) {
112 return AIX;
113 }
114
115 // determine another OS here
116 }
117
118 return UNKNOWN;
119 }
120
121 public static PrivilegedAction<OSType> getOSTypeAction() {
122 return osTypeAction;
123 }
124
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt;
27
28 import java.security.PrivilegedAction;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import static sun.awt.OSInfo.OSType.*;
33
34 /**
35 * @author Pavel Porvatov
36 */
37 public class OSInfo {
38 public static enum OSType {
39 WINDOWS,
40 LINUX,
41 MACOSX,
42 AIX,
43 UNKNOWN
44 }
45
46 /*
47 The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN,
48 and so the method getWindowsVersion() will return the constant for known OS.
49 It allows compare objects by "==" instead of "equals".
50 */
51 public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(-1, -1);
52 public static final WindowsVersion WINDOWS_95 = new WindowsVersion(4, 0);
53 public static final WindowsVersion WINDOWS_98 = new WindowsVersion(4, 10);
54 public static final WindowsVersion WINDOWS_ME = new WindowsVersion(4, 90);
55 public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(5, 0);
56 public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1);
57 public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2);
58 public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0);
59 public static final WindowsVersion WINDOWS_7 = new WindowsVersion(6, 1);
60
80 }
81 };
82
83 private OSInfo() {
84 // Don't allow to create instances
85 }
86
87 /**
88 * Returns type of operating system.
89 */
90 public static OSType getOSType() throws SecurityException {
91 String osName = System.getProperty(OS_NAME);
92
93 if (osName != null) {
94 if (osName.contains("Windows")) {
95 return WINDOWS;
96 }
97
98 if (osName.contains("Linux")) {
99 return LINUX;
100 }
101
102 if (osName.contains("OS X")) {
103 return MACOSX;
104 }
105
106 if (osName.contains("AIX")) {
107 return AIX;
108 }
109
110 // determine another OS here
111 }
112
113 return UNKNOWN;
114 }
115
116 public static PrivilegedAction<OSType> getOSTypeAction() {
117 return osTypeAction;
118 }
119
|