All pastes #498778 Raw Edit

Mine

public java v1 · immutable
·published 2007-05-20 17:38 UTC
rendered paste body
public void loadHandlers() {		handlers.clear();		File f = new File("./modules/");		if (!f.exists()) { f.mkdirs(); }		File[] dirs = f.listFiles(new FileFilter() {			public boolean accept(File arg0) {				return arg0.isDirectory();			}					});		int i = 0;		URL[] url = new URL[1];		try {		  url[0] = new File("").toURI().toURL();		} catch (MalformedURLException e) { 			Logger.logError("Unable to load modules...");			Logger.die(e);		}		URLClassLoader loader = new URLClassLoader(url);		for (File d : dirs) {			if ((d = new File(d.getPath() + "/Main.class")).exists()) {				try {					String path = d.getPath();					path = path.replaceAll("^[" + Pattern.quote(File.separator) + ".]+","").replace(".class","").substring(8); // Make relative to modules/					Class c = loader.loadClass(path.replace(File.separator, "."));					handlers.add((IRREventHandler)c.cast(new Object()));					i++;				} catch (ClassNotFoundException e) {					// TODO Auto-generated catch block					Logger.logError("Module error, not found");					Logger.log(e);					continue;				}			}			else { continue; }		}		Logger.logEvent("Loaded " + i + " modules.");	}