org.argouml.uml.reveng
Class ImportClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.argouml.uml.reveng.ImportClassLoader
- public class ImportClassLoader
- extends java.net.URLClassLoader
Class to help users reverse engineer class information from arbitrary
.jar/.class file resources, like an import classpath.
can be used as follows:
try{
ImportClassLoader loader = ImportClassLoader.getInstance();
// add paths...
loader.addFile(new File("/opt/lib/myjar.jar"));
Class clazz = loader.loadClass("org.xyz.MyException");
Object ex = clazz.newInstance();
cat.info("loaded class ok");
}catch(Exception e){cat.warn("error loading class: "+e.toString());}
It supports adding and removing Files from the import classpath.
And saving and loading the path to/from the users properties file.
It should be possible to make this the system class loader, but
I haven't got this to work yet:
final URLClassLoader urlClassLoader = new URLClassLoader(urls, cl);
//create a new custom class with the default classloader as its parent
try {
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
eq.invokeAndWait(new Runnable() {
public void run() {
Thread.currentThread().setContextClassLoader(urlClassLoader);
//this will replace the default system class loader with the new custom
//classloader, so that the jvm will use the new custom classloader to
// lookup a class
}
});
//...
Nested classes inherited from class java.lang.ClassLoader |
|
Fields inherited from class java.net.URLClassLoader |
|
Fields inherited from class java.security.SecureClassLoader |
|
Fields inherited from class java.lang.ClassLoader |
|
Methods inherited from class java.net.URLClassLoader |
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance |
Methods inherited from class java.security.SecureClassLoader |
defineClass |
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
cat
private org.apache.log4j.Logger cat
- logger
instance
private static ImportClassLoader instance
ImportClassLoader
private ImportClassLoader(java.net.URL[] urls)
getInstance
public static ImportClassLoader getInstance()
throws java.net.MalformedURLException
- try and return the existing instance if one exists.
- Throws:
java.net.MalformedURLException
getInstance
public static ImportClassLoader getInstance(java.net.URL[] urls)
throws java.net.MalformedURLException
- there is no default constructor for URLClassloader, so we should provide
urls when creating the instance.
we crate a new instance in this method.
- Throws:
java.net.MalformedURLException
addFile
public void addFile(java.io.File f)
throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
removeFile
public void removeFile(java.io.File f)
- can't remove the last file.
setPath
public void setPath(java.lang.String path)
getURLs
public static java.net.URL[] getURLs(java.lang.String path)
setPath
public void setPath(java.lang.Object[] paths)
loadUserPath
public void loadUserPath()
saveUserPath
public void saveUserPath()
toString
public java.lang.String toString()