KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > util > GlobalConstants


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: GlobalConstants.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
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.opensubsystems.core.util;
23
24 /**
25  * Class containing global constants for the system and for the product running
26  * this code.
27  *
28  * Good list of values for system properties can be found at
29  * http://www.tolstoy.com/samizdat/sysprops.html
30  *
31  * @version $Id: GlobalConstants.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
32  * @author Miro Halas
33  * @code.reviewer Miro Halas
34  * @code.reviewed 1.3 2005/07/29 07:36:24 bastafidli
35  */

36 public final class GlobalConstants
37 {
38    // Constants ////////////////////////////////////////////////////////////////
39

40    /**
41     * constant for 0 - Integer
42     */

43    public static final Integer JavaDoc INTEGER_0 = new Integer JavaDoc(0);
44    
45    /**
46     * constant for 1 - Integer
47     */

48    public static final Integer JavaDoc INTEGER_1 = new Integer JavaDoc(1);
49
50    /**
51     * Constant controlling if error checking is performed. If this is changed
52     * to false and the whole project is rebuilt, compiler should exclude all
53     * error checking to improve performance.
54     */

55    public static final boolean ERROR_CHECKING = true;
56
57    // Attributes ///////////////////////////////////////////////////////////////
58

59    /**
60     * Information about current product running this code.
61     */

62    protected static ProductInfo s_currentProduct = null;
63    
64    /**
65     * Current operating system.
66     */

67    protected static String JavaDoc s_currentOS;
68    
69    /**
70     * Current operating system.
71     */

72    protected static String JavaDoc s_currentOSUpper;
73    
74    /**
75     * End of lines characters used on given platform.
76     */

77    protected static String JavaDoc s_lineSeparator;
78
79    /**
80     * Separator used to separate various elements of a file path.
81     */

82    protected static String JavaDoc s_fileSeparator;
83
84    /**
85     * System specified temporary directory.
86     */

87    protected static String JavaDoc s_strTempDirectory;
88    
89    // Constructors /////////////////////////////////////////////////////////////
90

91    /**
92     * Static initializer.
93     */

94    static
95    {
96       s_currentOS = System.getProperty("os.name");
97       s_currentOSUpper = s_currentOS.toUpperCase();
98       s_lineSeparator = System.getProperty("line.separator");
99       s_fileSeparator = System.getProperty("file.separator");
100       s_strTempDirectory = System.getProperty("java.io.tmpdir");
101       if (!s_strTempDirectory.endsWith(s_fileSeparator))
102       {
103          s_strTempDirectory = s_strTempDirectory + s_fileSeparator;
104       }
105    }
106
107    /**
108     * Private constructor since this class cannot be instantiated
109     */

110    private GlobalConstants(
111    )
112    {
113       // Do nothing
114
}
115    
116    // Public methods ///////////////////////////////////////////////////////////
117

118    /**
119     * @return ProductInfo - information about current product
120     */

121    public static ProductInfo getCurrentProduct()
122    {
123       return s_currentProduct;
124    }
125    
126    /**
127     * @param currentProduct - The currentProduct to set.
128     */

129    public static void setCurrentProduct(
130       ProductInfo currentProduct
131    )
132    {
133       if (ERROR_CHECKING)
134       {
135          assert s_currentProduct == null
136                 : "Cannot change product information once it is set";
137       }
138       s_currentProduct = currentProduct;
139    }
140    
141    /**
142     * Are we running on Linux.
143     *
144     * @return boolean
145     */

146    public static boolean isLinux(
147    )
148    {
149       return s_currentOSUpper.indexOf("LINUX") >= 0;
150    }
151    
152    /**
153     * Are we running on Windows.
154     *
155     * @return boolean
156     */

157    public static boolean isWindows(
158    )
159    {
160       return s_currentOSUpper.indexOf("WINDOWS") >= 0;
161    }
162
163    /**
164     * Are we running on Windows 9X (such as Windows 95, 98, Me).
165     *
166     * @return boolean
167     */

168    public static boolean isWindows9x(
169    )
170    {
171       return (s_currentOSUpper.indexOf("WINDOWS 9") >= 0)
172              || s_currentOSUpper.indexOf("WINDOWS M") >= 0;
173    }
174
175    /**
176     * @return String - line separator used at current platform
177     */

178    public static String JavaDoc getLineSeparator()
179    {
180       return s_lineSeparator;
181    }
182
183    /**
184     * @return String - file separator used at current platform
185     */

186    public static String JavaDoc getFileSeparator()
187    {
188       return s_fileSeparator;
189    }
190
191    /**
192     * @return String - system specified temporary directory, it is guaranteed
193     * to end with file separator
194     */

195    public static String JavaDoc getTempDirectory()
196    {
197       return s_strTempDirectory;
198    }
199 }
200
Popular Tags