mote type classloaders

This commit is contained in:
nifi 2006-08-22 12:25:24 +00:00
parent 8c2765f0f7
commit c1dc1c4fd3

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: GUI.java,v 1.2 2006/08/22 08:56:08 nifi Exp $
* $Id: GUI.java,v 1.3 2006/08/22 12:25:24 nifi Exp $
*/
package se.sics.cooja;
@ -1517,50 +1517,82 @@ public class GUI extends JDesktopPane {
}
try {
if (userPlatformClassLoader != null) {
return userPlatformClassLoader.loadClass(className).asSubclass(classType);
}
} catch (ClassNotFoundException e) {
}
return null;
}
public ClassLoader createUserPlatformClassLoader(Vector<File> platformsList) {
if (userPlatformClassLoader == null) {
reparsePlatformConfig();
}
return createClassLoader(userPlatformClassLoader, platformsList);
}
private ClassLoader createClassLoader(Vector<File> currentUserPlatforms) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
return createClassLoader(ClassLoader.getSystemClassLoader(), currentUserPlatforms);
}
// Combine class loader from all user platforms (including any specified JAR
// files)
for (File userPlatform : currentUserPlatforms) {
// Read configuration to check if any JAR files should be loaded
private File findJarFile(File platformPath, String jarfile) {
File fp = new File(jarfile);
if (!fp.exists()) {
fp = new File(platformPath, jarfile);
}
if (!fp.exists()) {
fp = new File(platformPath, "java/" + jarfile);
}
if (!fp.exists()) {
fp = new File(platformPath, "java/lib/" + jarfile);
}
if (!fp.exists()) {
fp = new File(platformPath, "lib/" + jarfile);
}
return fp.exists() ? fp : null;
}
private ClassLoader createClassLoader(ClassLoader parent,
Vector<File> platformsList) {
if (platformsList == null || platformsList.isEmpty()) {
return parent;
}
// Combine class loader from all user platforms (including any
// specified JAR files)
ArrayList<URL> urls = new ArrayList<URL>();
for (int j = platformsList.size() - 1; j >= 0; j--) {
File userPlatform = platformsList.get(j);
try {
File userPlatformConfigFile = new File(userPlatform.getPath()
+ File.separatorChar + PLATFORM_CONFIG_FILENAME);
urls.add((new File(userPlatform, "java")).toURL());
// Read configuration to check if any JAR files should be loaded
File userPlatformConfigFile =
new File(userPlatform, PLATFORM_CONFIG_FILENAME);
PlatformConfig userPlatformConfig = new PlatformConfig();
userPlatformConfig.appendConfig(userPlatformConfigFile);
String[] platformJarFiles = userPlatformConfig.getStringArrayValue(
GUI.class, "JARFILES");
if (platformJarFiles != null && platformJarFiles.length > 0) {
URL[] platformJarURLs = new URL[platformJarFiles.length];
for (int i = 0; i < platformJarFiles.length; i++) {
platformJarURLs[i] = new File(userPlatform.getPath()
+ File.separatorChar + "lib" + File.separatorChar
+ platformJarFiles[i]).toURL();
for (String jarfile : platformJarFiles) {
File jarpath = findJarFile(userPlatform, jarfile);
if (jarpath == null) {
throw new FileNotFoundException(jarfile);
}
urls.add(jarpath.toURL());
}
classLoader = new URLClassLoader(platformJarURLs, classLoader);
}
} catch (Exception e) {
logger.fatal("Error when trying to read JAR-file in " + userPlatform
+ ": " + e);
}
// Add java class directory
classLoader = new DirectoryClassLoader(classLoader, new File(userPlatform
.getPath()
+ File.separatorChar + "java"));
}
return classLoader;
return new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]),
userPlatformClassLoader);
}
/**