All pastes #406232 Raw Edit

Stuff

public java v1 · immutable
·published 2007-03-22 06:40 UTC
rendered paste body
package impsoft.nexus.storage;import impsoft.nexus.gui.threads.GuiThread;import java.io.File;import java.io.IOException;import java.net.JarURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.net.URLClassLoader;import java.util.ArrayList;import java.util.Enumeration;import java.util.jar.JarEntry;import java.util.jar.JarFile;public class iDirClassLoader extends iClassLoader {	String theLocation;		String theName;	public iDirClassLoader(String location,String name) {		theLocation = location;		theName=name;		update();	}	@Override	public void update() {		CoreScriptStorage.clear(theLocation);		try {			File scriptDir = new File(theLocation);			URLClassLoader ucl = new URLClassLoader(new URL[] { scriptDir.toURL() });            for (File f : scriptDir.listFiles()) {            	String name = f.getName();            	if(name.endsWith(".class") && name.indexOf("$") == -1){            		String className = f.getName().substring(0,                            f.getName().indexOf("."));                    try {						Class c = ucl.loadClass(className);						CoreScriptStorage.addScriptClass(c,theName);					} catch (ClassNotFoundException e) {						GuiThread.exception(e);					}            	}            }		} catch (MalformedURLException e) {			GuiThread.exception(e);		}		CoreScriptStorage.guiRefresh();	}}package impsoft.nexus.storage;import impsoft.nexus.gui.threads.GuiThread;import java.io.IOException;import java.net.JarURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.net.URLClassLoader;import java.util.ArrayList;import java.util.Enumeration;import java.util.jar.JarEntry;import java.util.jar.JarFile;public class iJarClassLoader extends iClassLoader {	String theLocation;	String theName;	public iJarClassLoader(String location, String name) {		theLocation = location;		theName=name;		update();	}	@Override	public void update() {		CoreScriptStorage.clear(theLocation);		try {			URL url = new URL("jar:" + theLocation + "!/");			JarURLConnection conn = (JarURLConnection) url.openConnection();			JarFile jarfile = conn.getJarFile();			Enumeration<JarEntry> entires = jarfile.entries();			ArrayList<String> classNames = new ArrayList<String>(10);			while (entires.hasMoreElements()) {				JarEntry entry = entires.nextElement();				String name = entry.toString();				if ((name.endsWith(".class") && name.indexOf("$") == -1)) {					classNames.add(name);				}			}			URLClassLoader urlCL = new URLClassLoader(new URL[] { url });			for (String className : classNames) {				try {					Class c = urlCL.loadClass(className.replace(".class", ""));					CoreScriptStorage.addScriptClass(c,theName);				} catch (ClassNotFoundException e) {					GuiThread.exception(e);				}			}		} catch (MalformedURLException e) {			GuiThread.exception(e);		} catch (IOException e) {			GuiThread.exception(e);		}		CoreScriptStorage.guiRefresh();	}}package impsoft.nexus.storage;import impsoft.nexus.bots.core.interfaces.CoreScript;import impsoft.nexus.gui.threads.GuiThread;import impsoft.nexus.handlers.Handler;import impsoft.nexus.handlers.storage.ActiveHandlerStorage;import impsoft.nexus.handlers.storage.HandlerStorage;import java.util.ArrayList;import java.util.List;public class CoreScriptStorage {    public static List<ScriptWrapper> scripts = new ArrayList<ScriptWrapper>(0);        public static void clear(String location){    	for(int i=0;i<scripts.size();i++){    		if(scripts.get(i).getLocation().equalsIgnoreCase(location)){    			scripts.remove(i);    		}    	}    }        public static void guiRefresh(){    	for (int i = 0; i < ActiveHandlerStorage.handlers.length; i++) {            HandlerStorage.handlers[i].updateScriptDialogButtons();            HandlerStorage.handlers[i].updateScriptsTable();        }    }    public static void addScriptClass(Class clazz, String location) {        try {            if (CoreScript.class.isAssignableFrom(clazz)) {                Object obj = clazz.newInstance();                String author = " ";                String description = " ";                String[] cmds = null;                try {                    cmds = (String[]) (clazz.getField("commands").get(obj));                } catch (Exception e) {                }                try {                    author = ((String) clazz.getField("author").get(obj));                } catch (Exception e) {                }                try {                    description = ((String) clazz.getField("description").get(                            obj));                } catch (Exception e) {                }                if (cmds == null)                    cmds = new String[] { " " };                ;                if (author == null || author.length() == 0) {                    author = " ";                }                if (description == null || description.length() == 0) {                    description = " ";                }                GuiThread.info("Loaded Script " + clazz.getName() + " by " + author);                GuiThread.info("        From "+location);                for (int i = 0; i < cmds.length; i++) {                	GuiThread.info("     " + cmds[i]);                }                scripts.add(new ScriptWrapper(clazz, cmds, author, description, location));            }        } catch (Exception e) {            GuiThread.exception(e);        }    }}