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