2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
9 @version $Id: Configuration.java 1798 2007-05-09 02:08:41Z dcollins $
12 package gov
.nasa
.worldwind
;
17 public class Configuration
// Singleton
19 private static final String CONFIG_FILE_NAME
= "config/worldwind.properties";
20 private static final String CONFIG_FILE_PROPERTY_KEY
= "gov.nasa.worldwind.config.file";
22 private static Configuration ourInstance
= new Configuration();
24 private static Configuration
getInstance()
29 private Properties defaultSettings
= new Properties();
30 private Properties customSettings
;
32 private Configuration()
38 private void initializeDefaults()
40 defaultSettings
.setProperty(AVKey
.DATA_FILE_CACHE_CLASS_NAME
, "gov.nasa.worldwind.BasicDataFileCache");
41 defaultSettings
.setProperty(AVKey
.DATA_FILE_CACHE_CONFIGURATION_FILE_NAME
, "config/DataFileCache.xml");
42 defaultSettings
.setProperty(AVKey
.FRAME_CONTROLLER_CLASS_NAME
, "gov.nasa.worldwind.BasicFrameController");
43 defaultSettings
.setProperty(AVKey
.GLOBE_CLASS_NAME
, "gov.nasa.worldwind.globes.Earth");
44 defaultSettings
.setProperty(AVKey
.INPUT_HANDLER_CLASS_NAME
, "gov.nasa.worldwind.awt.AWTInputHandler");
45 defaultSettings
.setProperty(AVKey
.LOGGER_NAME
, "gov.nasa.worldwind");
46 defaultSettings
.setProperty(AVKey
.MEMORY_CACHE_CLASS_NAME
, "gov.nasa.worldwind.BasicMemoryCache");
47 defaultSettings
.setProperty(AVKey
.MODEL_CLASS_NAME
, "gov.nasa.worldwind.BasicModel");
48 defaultSettings
.setProperty(AVKey
.RETRIEVAL_SERVICE_CLASS_NAME
, "gov.nasa.worldwind.BasicRetrievalService");
49 defaultSettings
.setProperty(AVKey
.SCENE_CONTROLLER_CLASS_NAME
, "gov.nasa.worldwind.BasicSceneController");
50 defaultSettings
.setProperty(AVKey
.THREADED_TASK_SERVICE_CLASS_NAME
, "gov.nasa.worldwind.ThreadedTaskService");
51 defaultSettings
.setProperty(AVKey
.VIEW_CLASS_NAME
, "gov.nasa.worldwind.BasicOrbitView");
52 defaultSettings
.setProperty(AVKey
.LAYERS_CLASS_NAMES
,
53 "gov.nasa.worldwind.layers.Earth.BMNGSurfaceLayer"
54 + ",gov.nasa.worldwind.layers.Earth.LandsatI3"
55 + ",gov.nasa.worldwind.layers.Earth.USGSUrbanAreaOrtho"
56 + ",gov.nasa.worldwind.layers.Earth.EarthNASAPlaceNameLayer"
57 + ",gov.nasa.worldwind.layers.CompassLayer"
60 defaultSettings
.setProperty(AVKey
.INITIAL_LATITUDE
, "0");
61 defaultSettings
.setProperty(AVKey
.RETRIEVAL_POOL_SIZE
, "5");
62 defaultSettings
.setProperty(AVKey
.RETRIEVAL_QUEUE_SIZE
, "200");
63 defaultSettings
.setProperty(AVKey
.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT
, "9000");
64 defaultSettings
.setProperty(AVKey
.THREADED_TASK_POOL_SIZE
, "1");
65 defaultSettings
.setProperty(AVKey
.THREADED_TASK_QUEUE_SIZE
, "5");
66 defaultSettings
.setProperty(AVKey
.VERTICAL_EXAGGERATION
, "1");
67 defaultSettings
.setProperty(AVKey
.CACHE_SIZE
, "2000000000");
68 defaultSettings
.setProperty(AVKey
.CACHE_LOW_WATER
, "140000000");
69 defaultSettings
.setProperty(AVKey
.URL_CONNECT_TIMEOUT
, "8000"); // milliseconds
70 defaultSettings
.setProperty(AVKey
.URL_READ_TIMEOUT
, "5000"); // milliseconds
73 private void initializeCustom()
75 this.customSettings
= new Properties(defaultSettings
);
77 String configFileName
= System
.getProperty(CONFIG_FILE_PROPERTY_KEY
, CONFIG_FILE_NAME
);
80 InputStream propsStream
= this.getClass().getResourceAsStream("/" + configFileName
);
81 if (propsStream
== null)
83 File propsFile
= new File(configFileName
);
84 if (propsFile
.exists())
86 propsStream
= new FileInputStream(propsFile
);
90 String message
= WorldWind
.retrieveErrMsg("Configuration.UnavailablePropsFile" + configFileName
);
91 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
95 if (propsStream
!= null)
97 this.customSettings
.load(propsStream
);
100 catch (FileNotFoundException e
)
102 String message
= WorldWind
.retrieveErrMsg("Configuration.UnavailablePropsFile" + configFileName
);
103 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
105 catch (IOException e
)
107 String message
= WorldWind
.retrieveErrMsg("Configuration.ExceptionReadingPropsFile" + configFileName
);
108 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
112 String message
= WorldWind
.retrieveErrMsg("Configuration.ExceptionReadingPropsFile" + configFileName
113 + " " + e
.getLocalizedMessage());
114 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
, e
);
118 public static String
getStringValue(String key
, String defaultValue
)
120 String v
= getStringValue(key
);
121 return v
!= null ? v
: defaultValue
;
124 public static String
getStringValue(String key
)
126 return getInstance().customSettings
.getProperty(key
);
129 public static Integer
getIntegerValue(String key
, Integer defaultValue
)
131 Integer v
= getIntegerValue(key
);
132 return v
!= null ? v
: defaultValue
;
135 public static Integer
getIntegerValue(String key
)
137 String v
= getStringValue(key
);
143 return Integer
.parseInt(v
);
145 catch (NumberFormatException e
)
147 String message
= WorldWind
.retrieveErrMsg("Configuration.ConversionError" + v
);
148 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
154 public static Long
getLongValue(String key
, Long defaultValue
)
156 Long v
= getLongValue(key
);
157 return v
!= null ? v
: defaultValue
;
160 public static Long
getLongValue(String key
)
162 String v
= getStringValue(key
);
168 return Long
.parseLong(v
);
170 catch (NumberFormatException e
)
172 String message
= WorldWind
.retrieveErrMsg("Configuration.ConversionError" + v
);
173 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
179 public static Double
getDoubleValue(String key
, Double defaultValue
)
181 Double v
= getDoubleValue(key
);
182 return v
!= null ? v
: defaultValue
;
185 public static Double
getDoubleValue(String key
)
187 String v
= getStringValue(key
);
193 return Double
.parseDouble(v
);
195 catch (NumberFormatException e
)
197 String message
= WorldWind
.retrieveErrMsg("Configuration.ConversionError" + v
);
198 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
204 public static boolean hasKey(String key
)
206 return getInstance().customSettings
.contains(key
);
209 public static void removeKey(String key
)
211 getInstance().customSettings
.remove(key
);
214 public static void setValue(String key
, Object value
)
216 getInstance().customSettings
.put(key
, value
.toString());
219 // OS, user, and run-time specific system properties. //
221 public static String
currentWorkingDirectory()
223 String dir
= System
.getProperty("user.dir");
224 return (dir
!= null) ? dir
: ".";
227 public static String
getUserHomeDirectory()
229 String dir
= System
.getProperty("user.home");
230 return (dir
!= null) ? dir
: ".";
233 public static String
systemTempDirectory()
235 String dir
= System
.getProperty("java.io.tmpdir");
236 return (dir
!= null) ? dir
: ".";
239 public static boolean isMacOS()
241 String osName
= System
.getProperty("os.name");
242 return osName
!= null && osName
.toLowerCase().contains("mac");
245 public static boolean isWindowsOS()
247 String osName
= System
.getProperty("os.name");
248 return osName
!= null && osName
.toLowerCase().contains("windows");
251 public static boolean isLinuxOS()
253 String osName
= System
.getProperty("os.name");
254 return osName
!= null && osName
.toLowerCase().contains("linux");
257 public static boolean isUnixOS()
259 String osName
= System
.getProperty("os.name");
260 return osName
!= null && osName
.toLowerCase().contains("unix");
263 public static boolean isSolarisOS()
265 String osName
= System
.getProperty("os.name");
266 return osName
!= null && osName
.toLowerCase().contains("solaris");