Source Code Cross Referenced for OSInfo.java in  » 6.0-JDK-Modules-sun » awt » sun » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules sun » awt » sun.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.awt;
027:
028:        import java.security.PrivilegedAction;
029:        import java.util.HashMap;
030:        import java.util.Map;
031:
032:        import static sun.awt.OSInfo.OSType.*;
033:
034:        /**
035:         * @author Pavel Porvatov
036:         * @version 1.2 06/15/07
037:         */
038:        public class OSInfo {
039:            public static enum OSType {
040:                WINDOWS, LINUX, SOLARIS, UNKNOWN
041:            }
042:
043:            /*
044:               The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN,
045:               and so the method getWindowsVersion() will return the constant for known OS.
046:               It allows compare objects by "==" instead of "equals".
047:             */
048:            public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(
049:                    -1, -1);
050:            public static final WindowsVersion WINDOWS_95 = new WindowsVersion(
051:                    4, 0);
052:            public static final WindowsVersion WINDOWS_98 = new WindowsVersion(
053:                    4, 10);
054:            public static final WindowsVersion WINDOWS_ME = new WindowsVersion(
055:                    4, 90);
056:            public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(
057:                    5, 0);
058:            public static final WindowsVersion WINDOWS_XP = new WindowsVersion(
059:                    5, 1);
060:            public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(
061:                    5, 2);
062:            public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(
063:                    6, 0);
064:
065:            private static final String OS_NAME = "os.name";
066:            private static final String OS_VERSION = "os.version";
067:
068:            private final static Map<String, WindowsVersion> windowsVersionMap = new HashMap<String, OSInfo.WindowsVersion>();
069:
070:            static {
071:                windowsVersionMap.put(WINDOWS_95.toString(), WINDOWS_95);
072:                windowsVersionMap.put(WINDOWS_98.toString(), WINDOWS_98);
073:                windowsVersionMap.put(WINDOWS_ME.toString(), WINDOWS_ME);
074:                windowsVersionMap.put(WINDOWS_2000.toString(), WINDOWS_2000);
075:                windowsVersionMap.put(WINDOWS_XP.toString(), WINDOWS_XP);
076:                windowsVersionMap.put(WINDOWS_2003.toString(), WINDOWS_2003);
077:                windowsVersionMap.put(WINDOWS_VISTA.toString(), WINDOWS_VISTA);
078:            }
079:
080:            private static final PrivilegedAction<OSType> osTypeAction = new PrivilegedAction<OSType>() {
081:                public OSType run() {
082:                    return getOSType();
083:                }
084:            };
085:
086:            private OSInfo() {
087:                // Don't allow to create instances
088:            }
089:
090:            /**
091:             * Returns type of operating system.
092:             */
093:            public static OSType getOSType() throws SecurityException {
094:                String osName = System.getProperty(OS_NAME);
095:
096:                if (osName != null) {
097:                    if (osName.contains("Windows")) {
098:                        return WINDOWS;
099:                    }
100:
101:                    if (osName.contains("Linux")) {
102:                        return LINUX;
103:                    }
104:
105:                    if (osName.contains("Solaris") || osName.contains("SunOS")) {
106:                        return SOLARIS;
107:                    }
108:
109:                    // determine another OS here 
110:                }
111:
112:                return UNKNOWN;
113:            }
114:
115:            public static PrivilegedAction<OSType> getOSTypeAction() {
116:                return osTypeAction;
117:            }
118:
119:            public static WindowsVersion getWindowsVersion()
120:                    throws SecurityException {
121:                String osVersion = System.getProperty(OS_VERSION);
122:
123:                if (osVersion == null) {
124:                    return WINDOWS_UNKNOWN;
125:                }
126:
127:                synchronized (windowsVersionMap) {
128:                    WindowsVersion result = windowsVersionMap.get(osVersion);
129:
130:                    if (result == null) {
131:                        // Try parse version and put object into windowsVersionMap 
132:                        String[] arr = osVersion.split("\\.");
133:
134:                        if (arr.length == 2) {
135:                            try {
136:                                result = new WindowsVersion(Integer
137:                                        .parseInt(arr[0]), Integer
138:                                        .parseInt(arr[1]));
139:                            } catch (NumberFormatException e) {
140:                                return WINDOWS_UNKNOWN;
141:                            }
142:                        } else {
143:                            return WINDOWS_UNKNOWN;
144:                        }
145:
146:                        windowsVersionMap.put(osVersion, result);
147:                    }
148:
149:                    return result;
150:                }
151:            }
152:
153:            public static class WindowsVersion implements 
154:                    Comparable<WindowsVersion> {
155:                private final int major;
156:
157:                private final int minor;
158:
159:                private WindowsVersion(int major, int minor) {
160:                    this .major = major;
161:                    this .minor = minor;
162:                }
163:
164:                public int getMajor() {
165:                    return major;
166:                }
167:
168:                public int getMinor() {
169:                    return minor;
170:                }
171:
172:                public int compareTo(WindowsVersion o) {
173:                    int result = major - o.getMajor();
174:
175:                    if (result == 0) {
176:                        result = minor - o.getMinor();
177:                    }
178:
179:                    return result;
180:                }
181:
182:                public boolean equals(Object obj) {
183:                    return obj instanceof  WindowsVersion
184:                            && compareTo((WindowsVersion) obj) == 0;
185:                }
186:
187:                public int hashCode() {
188:                    return 31 * major + minor;
189:                }
190:
191:                public String toString() {
192:                    return major + "." + minor;
193:                }
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.