001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.types;
028
029 /**
030 * This class defines an enumeration that may be used to identify
031 * the operating system on which the JVM is running.
032 *
033 * NOTE: to share code this class is used in SetupUtils and should
034 * not contain any dependency with other classes (not even with
035 * classes in this package).
036 * If this class is modified to depend on other classes it will break
037 * the quicksetup. If this must be done, the references to this
038 * class in SetupUtils must be removed.
039 */
040 @org.opends.server.types.PublicAPI(
041 stability=org.opends.server.types.StabilityLevel.VOLATILE,
042 mayInstantiate=false,
043 mayExtend=false,
044 mayInvoke=true)
045 public enum OperatingSystem
046 {
047 /**
048 * The value indicating the AIX operating system.
049 */
050 AIX("AIX"),
051
052
053
054 /**
055 * The value indicating the FreeBSD operating system.
056 */
057 FREEBSD("FreeBSD"),
058
059
060
061 /**
062 * The value indicating the HP-UX operating system.
063 */
064 HPUX("HP-UX"),
065
066
067
068 /**
069 * The value indicating the Linux operating system.
070 */
071 LINUX("Linux"),
072
073
074
075 /**
076 * The value indicating the Mac OS X operating system.
077 */
078 MACOS("Mac OS X"),
079
080
081
082 /**
083 * The value indicating the Solaris operating system.
084 */
085 SOLARIS("Solaris"),
086
087
088
089 /**
090 * The value indicating the Windows operating system.
091 */
092 WINDOWS("Windows"),
093
094
095
096 /**
097 * The value indicating the z/OS operating system.
098 */
099 ZOS("z/OS"),
100
101
102
103 /**
104 * The value indicating an unknown operating system.
105 */
106 UNKNOWN("Unknown");
107
108
109
110 // The human-readable name for this operating system.
111 private String osName;
112
113
114
115 /**
116 * Creates a new operating system value with the provided name.
117 *
118 * @param osName The human-readable name for the operating system.
119 */
120 private OperatingSystem(String osName)
121 {
122 this.osName = osName;
123 }
124
125
126
127 /**
128 * Retrieves the human-readable name of this operating system.
129 *
130 * @return The human-readable name for this operating system.
131 */
132 public String toString()
133 {
134 return osName;
135 }
136
137
138
139 /**
140 * Retrieves the operating system for the provided name. The name
141 * provided should come from the <CODE>os.name</CODE> system
142 * property.
143 *
144 * @param osName The name for which to retrieve the corresponding
145 * operating system.
146 *
147 * @return The operating system for the provided name.
148 */
149 public static OperatingSystem forName(String osName)
150 {
151 if (osName == null)
152 {
153 return UNKNOWN;
154 }
155
156
157 String lowerName = osName.toLowerCase();
158
159 if ((lowerName.indexOf("solaris") >= 0) ||
160 (lowerName.indexOf("sunos") >= 0))
161 {
162 return SOLARIS;
163 }
164 else if (lowerName.indexOf("linux") >= 0)
165 {
166 return LINUX;
167 }
168 else if ((lowerName.indexOf("hp-ux") >= 0) ||
169 (lowerName.indexOf("hp ux") >= 0) ||
170 (lowerName.indexOf("hpux") >= 0))
171 {
172 return HPUX;
173 }
174 else if (lowerName.indexOf("aix") >= 0)
175 {
176 return AIX;
177 }
178 else if (lowerName.indexOf("windows") >= 0)
179 {
180 return WINDOWS;
181 }
182 else if ((lowerName.indexOf("freebsd") >= 0) ||
183 (lowerName.indexOf("free bsd") >= 0))
184 {
185 return FREEBSD;
186 }
187 else if ((lowerName.indexOf("macos") >= 0) ||
188 (lowerName.indexOf("mac os") >= 0))
189 {
190 return MACOS;
191 }
192 else if (lowerName.indexOf("z/os") >= 0)
193 {
194 return ZOS;
195 }
196 else
197 {
198 return UNKNOWN;
199 }
200 }
201
202
203
204 /**
205 * Indicates whether the provided operating system is UNIX-based.
206 * UNIX-based operating systems include Solaris, Linux, HP-UX, AIX,
207 * FreeBSD, and Mac OS X.
208 *
209 * @param os The operating system for which to make the
210 * determination.
211 *
212 * @return <CODE>true</CODE> if the provided operating system is
213 * UNIX-based, or <CODE>false</CODE> if not.
214 */
215 public static boolean isUNIXBased(OperatingSystem os)
216 {
217 switch (os)
218 {
219 case SOLARIS:
220 case LINUX:
221 case HPUX:
222 case AIX:
223 case FREEBSD:
224 case MACOS:
225 return true;
226 default:
227 return false;
228 }
229 }
230 }
231