KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > properties > SystemProperties


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
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 implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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

27     // properties
28

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

59     public static final IntProperty rmiSocketTimeoutProperty =
60             new IntProperty(SystemProperties.class, "org.apache.geronimo.interop.rmi.socketTimeout")
61             .defaultValue(600); // 10 minutes
62

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

71     private static SystemProperties instance;
72     private boolean canAccessFileSystem = true;
73     private boolean rmiTrace;
74     private boolean debug;
75     private boolean quiet;
76     private boolean verbose;
77     private String JavaDoc home;
78     private String JavaDoc repository;
79     private String JavaDoc tempDir;
80
81     static {
82         instance = new SystemProperties();
83         instance.init();
84     }
85
86     public static SystemProperties getInstance() {
87         return instance;
88     }
89
90     // private methods
91

92     private SystemProperties() {
93         try {
94             putAll(System.getProperties());
95         } catch (Exception JavaDoc ignore) // e.g. due to Applet Security Manager
96
{
97             canAccessFileSystem = false;
98         }
99     }
100
101     private void init() {
102         debug = debugProperty.getBoolean();
103         quiet = quietProperty.getBoolean();
104         verbose = verboseProperty.getBoolean();
105
106         if (verbose) {
107             System.out.println("System Property org.apache.geronimo.interop.debug = " + debug);
108             System.out.println("System Property org.apache.geronimo.interop.verbose = true");
109         }
110
111         rmiTrace = rmiTraceProperty.getBoolean();
112
113         homeProperty.defaultValue("/org.apache.geronimo.interop");
114         home = homeProperty.getString();
115
116         repositoryProperty.defaultValue(home + "/Repository");
117         repository = repositoryProperty.getString();
118
119         tempDirProperty.defaultValue(home + "/temp");
120         tempDir = tempDirProperty.getString();
121     }
122
123     // public methods
124

125     public static boolean rmiTrace() {
126         return getInstance().rmiTrace;
127     }
128
129     public static boolean debug() {
130         return getInstance().debug;
131     }
132
133     public static boolean quiet() {
134         return getInstance().quiet;
135     }
136
137     public static boolean verbose() {
138         return getInstance().verbose;
139     }
140
141     public static boolean canAccessFileSystem() {
142         return getInstance().canAccessFileSystem;
143     }
144
145     public static String JavaDoc logFile() {
146         // Note: this is not necessarily a constant.
147
// Application might call System.setProperty to change "org.apache.geronimo.interop.logFile".
148
try {
149             String JavaDoc file = System.getProperty(logFileProperty.getPropertyName(), logFileProperty.getDefaultValue());
150             file = FileUtil.expandHomeRelativePath(file);
151             return file;
152         } catch (Exception JavaDoc ex) // e.g. SecurityException in Applet
153
{
154             return logFileProperty.getString();
155         }
156     }
157
158     public static String JavaDoc getHome() {
159         return getInstance().home;
160     }
161
162     public static String JavaDoc getRepository() {
163         return getInstance().repository;
164     }
165
166     public static String JavaDoc getTempDir() {
167         return getInstance().tempDir;
168     }
169 }
170
Popular Tags