⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extfilemanager.java

📁 Petri网分析工具PIPE is open-source
💻 JAVA
字号:
//######################################################################################/* * Created on 07-Feb-2004 * Author is Michael Camacho * *///######################################################################################package pipe.gui;import java.io.File;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.net.URLClassLoader;import java.security.CodeSource;//######################################################################################public class ExtFileManager{//######################################################################################	private static URLClassLoader cLoader = null;//######################################################################################	public ExtFileManager()	{	}//######################################################################################	public static Class loadExtClass(String className)	{		Class c = null;		try		{			c = cLoader.loadClass(className);		}		catch (Exception e)		{			System.err.println("Failed to load Class " + className);		}		return c;	}//######################################################################################	public static Class loadExtClass(File classFile)	{		Class myClass = null;		File path = classFile.getParentFile();		String name = classFile.getName();		addSearchPath(path);		if (name.endsWith(".class"))		{			name = name.substring(0, name.length()-6);			System.err.println("Class Name = "+name);			try			{				myClass = cLoader.loadClass(name);						}			catch (Exception e)			{				System.err.println("Class "+name+" wasn't loaded.");			}		}		URL[] myPaths = cLoader.getURLs();			return myClass;	}//######################################################################################	public static Object loadExtClass(URL classURL)	{		Object myObj = null;		try		{//			System.err.println(classURL.getFile());			myObj = classURL.getContent();		}		catch (Exception e)		{			System.err.println("loadExtClass caused an IO Exception");		}		return myObj;	}//######################################################################################	public static void addSearchPath(File p)	{		if (p.exists() && p.isDirectory())		{			try			{				URL[] pathURLs = {p.getCanonicalFile().toURI().toURL()};				addSearchPath(pathURLs);			}			catch(Exception e)			{				System.err.println("Failed to add path: URI.toURL generated an error.");			}		}	}//######################################################################################	public static void addSearchPath(URL[] urls)	{		if (cLoader == null)		{			cLoader = new URLClassLoader(urls);		}		else		{			cLoader = new URLClassLoader(urls, cLoader);		}			}//######################################################################################	public void addClassRootToPath(Class someClass)	{		File rootPath = getClassRoot(someClass);		if (rootPath != null) {			addSearchPath(rootPath);		}	}//######################################################################################	public static File getClassRoot(Class someClass)	{		CodeSource source =			someClass.getProtectionDomain().getCodeSource();				if (source == null) return null;				File dataDir;				try		{			URI sourceURI = new URI(source.getLocation().toString());			dataDir = new File(sourceURI);		}		catch (URISyntaxException e)		{			return null;		}		catch (IllegalArgumentException e)		{			return null;		}				if (!dataDir.isDirectory()) dataDir = dataDir.getParentFile();		return dataDir;	}//######################################################################################}//######################################################################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -