KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > properties > SystemProperties


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.properties;
20
21 import gcc.util.*;
22
23 public class SystemProperties extends PropertyMap
24 {
25     // Not a component as it is required for bootstrapping
26
// and we want to avoid circular build dependencies.
27

28     // properties
29

30     public static final BooleanProperty debugProperty =
31         new BooleanProperty(SystemProperties.class, "gcc.debug");
32
33     public static final BooleanProperty quietProperty =
34         new BooleanProperty(SystemProperties.class, "gcc.quiet");
35
36     public static final BooleanProperty verboseProperty =
37         new BooleanProperty(SystemProperties.class, "gcc.verbose");
38
39     public static final StringProperty homeProperty =
40         new StringProperty(SystemProperties.class, "gcc.home")
41         .isDirName();
42
43     public static final StringProperty repositoryProperty =
44         new StringProperty(SystemProperties.class, "gcc.repository")
45         .isDirName();
46
47     public static final StringProperty logFileProperty =
48         new StringProperty(SystemProperties.class, "gcc.logFile")
49         .defaultValue("~/logs/default.log")
50         .isFileName();
51
52     public static final StringProperty tempDirProperty =
53         new StringProperty(SystemProperties.class, "gcc.tempDir")
54         .isFileName();
55
56     public static final IntProperty rmiNamingContextCacheTimeoutProperty =
57         new IntProperty(SystemProperties.class, "gcc.rmi.namingContextCacheTimeout")
58         .defaultValue(600); // 10 minutes
59

60     public static final IntProperty rmiSocketTimeoutProperty =
61         new IntProperty(SystemProperties.class, "gcc.rmi.socketTimeout")
62         .defaultValue(600); // 10 minutes
63

64     public static final BooleanProperty rmiTraceProperty =
65         new BooleanProperty(SystemProperties.class, "gcc.rmiTrace");
66
67     public static final BooleanProperty useThreadLocalRmiConnectionPoolsProperty =
68         new BooleanProperty(SystemProperties.class, "gcc.rmi.useThreadLocalConnectionPools");
69
70     // privata data
71

72     private static SystemProperties _instance;
73     private boolean _canAccessFileSystem = true;
74     private boolean _rmiTrace;
75     private boolean _debug;
76     private boolean _quiet;
77     private boolean _verbose;
78     private String _home;
79     private String _repository;
80     private String _tempDir;
81
82     static
83     {
84         _instance = new SystemProperties();
85         _instance.init();
86     }
87
88     public static SystemProperties getInstance()
89     {
90         return _instance;
91     }
92
93     // private methods
94

95     private SystemProperties()
96     {
97         try
98         {
99             putAll(System.getProperties());
100         }
101         catch (Exception ignore) // e.g. due to Applet Security Manager
102
{
103             _canAccessFileSystem = false;
104         }
105     }
106
107     private void init()
108     {
109         _debug = debugProperty.getBoolean();
110         _quiet = quietProperty.getBoolean();
111         _verbose = verboseProperty.getBoolean();
112
113         if (_verbose)
114         {
115             System.out.println("System Property gcc.debug = " + _debug);
116             System.out.println("System Property gcc.verbose = true");
117         }
118
119         _rmiTrace = rmiTraceProperty.getBoolean();
120
121         homeProperty.defaultValue("/gcc");
122         _home = homeProperty.getString();
123
124         repositoryProperty.defaultValue(_home + "/Repository");
125         _repository = repositoryProperty.getString();
126
127         tempDirProperty.defaultValue(_home + "/temp");
128         _tempDir = tempDirProperty.getString();
129     }
130
131     // public methods
132

133     public static boolean rmiTrace()
134     {
135         return getInstance()._rmiTrace;
136     }
137
138     public static boolean debug()
139     {
140         return getInstance()._debug;
141     }
142
143     public static boolean quiet()
144     {
145         return getInstance()._quiet;
146     }
147
148     public static boolean verbose()
149     {
150         return getInstance()._verbose;
151     }
152
153     public static boolean canAccessFileSystem()
154     {
155         return getInstance()._canAccessFileSystem;
156     }
157
158     public static String logFile()
159     {
160         // Note: this is not necessarily a constant.
161
// Application might call System.setProperty to change "gcc.logFile".
162
try
163         {
164             String file = System.getProperty(logFileProperty.getPropertyName(), logFileProperty.getDefaultValue());
165             file = FileUtil.expandHomeRelativePath(file);
166             return file;
167         }
168         catch (Exception ex) // e.g. SecurityException in Applet
169
{
170             return logFileProperty.getString();
171         }
172     }
173
174     public static String getHome()
175     {
176         return getInstance()._home;
177     }
178
179     public static String getRepository()
180     {
181         return getInstance()._repository;
182     }
183
184     public static String getTempDir()
185     {
186         return getInstance()._tempDir;
187     }
188 }
189
Popular Tags