2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
;
9 import gov
.nasa
.worldwind
.avlist
.AVKey
;
10 import gov
.nasa
.worldwind
.cache
.*;
11 import gov
.nasa
.worldwind
.exception
.WWRuntimeException
;
12 import gov
.nasa
.worldwind
.retrieve
.RetrievalService
;
13 import gov
.nasa
.worldwind
.util
.*;
15 import java
.util
.logging
.Level
;
19 * @version $Id: WorldWind.java 2471 2007-07-31 21:50:57Z tgaskins $
21 public final class WorldWind
23 private static WorldWind instance
= new WorldWind();
25 private WWObjectImpl wwo
;
26 private MemoryCacheSet memoryCacheSet
;
27 private FileCache dataFileCache
;
28 private RetrievalService retrievalService
;
29 private TaskService taskService
;
31 private WorldWind() // Singleton, prevent public instantiation.
36 private void initialize()
38 this.wwo
= new WWObjectImpl();
39 this.retrievalService
= (RetrievalService
) createConfigurationComponent(AVKey
.RETRIEVAL_SERVICE_CLASS_NAME
);
40 this.taskService
= (TaskService
) createConfigurationComponent(AVKey
.TASK_SERVICE_CLASS_NAME
);
41 this.dataFileCache
= (FileCache
) createConfigurationComponent(AVKey
.DATA_FILE_CACHE_CLASS_NAME
);
42 this.memoryCacheSet
= (MemoryCacheSet
) createConfigurationComponent(AVKey
.MEMORY_CACHE_SET_CLASS_NAME
);
45 private void dispose()
47 this.taskService
.shutdown(true);
48 this.retrievalService
.shutdown(true);
49 this.memoryCacheSet
.clear();
53 * Reinitialize World Wind to its initial ready state. Shut down and restart all World Wind services and clear all
54 * World Wind memory caches. Cache memory will be released at the next JVM garbage collection.
56 * Call this method to reduce World Wind's current resource usage to its initial, empty state. This is typically
57 * required by applets when the user leaves the applet page.
59 * World Wind can continue to be used after calling this method. The state of any existing World Wind drawables is
60 * subsequently indeterminate and they should be disposed.
62 public static synchronized void shutDown()
65 instance
= new WorldWind();
66 instance
.initialize();
69 public static MemoryCacheSet
getMemoryCacheSet()
71 return instance
.memoryCacheSet
;
74 public static synchronized MemoryCache
getMemoryCache(String key
)
76 return instance
.memoryCacheSet
.getCache(key
);
79 public static FileCache
getDataFileCache()
81 return instance
.dataFileCache
;
84 public static RetrievalService
getRetrievalService()
86 return instance
.retrievalService
;
89 public static TaskService
getTaskService()
91 return instance
.taskService
;
97 * @throws WWRuntimeException if the <code>Object</code> could not be created
98 * @throws IllegalArgumentException if <code>className</code> is null or zero length
100 public static Object
createComponent(String className
) throws WWRuntimeException
102 if (className
== null || className
.length() == 0)
104 Logging
.logger().severe("WorldWind.ClassNameKeyNulZero");
105 throw new IllegalArgumentException(Logging
.getMessage("WorldWind.ClassNameKeyNulZero"));
110 Class c
= Class
.forName(className
);
111 return c
.newInstance();
115 Logging
.logger().log(Level
.SEVERE
, "WorldWind.ExceptionCreatingComponent", className
);
116 throw new WWRuntimeException(Logging
.getMessage("WorldWind.ExceptionCreatingComponent", className
), e
);
120 Logging
.logger().log(Level
.SEVERE
, "WorldWind.ErrorCreatingComponent", className
);
121 throw new WWRuntimeException(Logging
.getMessage("WorldWind.ErrorCreatingComponent", className
), t
);
126 * @param classNameKey
128 * @throws IllegalStateException if no name could be found which corresponds to <code>classNameKey</code>
129 * @throws IllegalArgumentException if <code>classNameKey<code> is null
130 * @throws WWRuntimeException if the component could not be created
132 public static Object
createConfigurationComponent(String classNameKey
)
133 throws IllegalStateException
, IllegalArgumentException
135 if (classNameKey
== null)
137 Logging
.logger().severe("WorldWind.ClassNameKeyNulZero");
138 throw new IllegalArgumentException(Logging
.getMessage("WorldWind.ClassNameKeyNulZero"));
141 String name
= Configuration
.getStringValue(classNameKey
);
144 Logging
.logger().log(Level
.SEVERE
, "WorldWind.NoClassNameInConfigurationForKey", classNameKey
);
145 throw new WWRuntimeException(
146 Logging
.getMessage("WorldWind.NoClassNameInConfigurationForKey", classNameKey
));
151 return WorldWind
.createComponent(name
);
155 Logging
.logger().log(Level
.SEVERE
, "WorldWind.UnableToCreateClassForConfigurationKey", name
);
156 throw new IllegalStateException(
157 Logging
.getMessage("WorldWind.UnableToCreateClassForConfigurationKey", name
), e
);
161 public static void setValue(String key
, String value
)
163 instance
.wwo
.setValue(key
, value
);
166 public static Object
getValue(String key
)
168 return instance
.wwo
.getValue(key
);
171 public static String
getStringValue(String key
)
173 return instance
.wwo
.getStringValue(key
);
176 public static boolean hasKey(String key
)
178 return instance
.wwo
.hasKey(key
);
181 public static void removeKey(String key
)
183 instance
.wwo
.removeKey(key
);