org.javagroup.util
Class URLClassLoader
java.lang.Object
|
+--java.lang.ClassLoader
|
+--org.javagroup.util.URLClassLoader
- public class URLClassLoader
- extends java.lang.ClassLoader
Generic classloader for URL-based classpaths.
TODO: add archive support, and rewrite as this is currently a hack
Constructor Summary |
URLClassLoader()
Creates a ClassLoader with no classpath. |
URLClassLoader(java.net.URL classpath)
Creates a ClassLoader with a single URL for a classpath. |
URLClassLoader(java.net.URL[] classpath)
Creates a ClassLoader with a list of classpath URLs. |
Method Summary |
void |
addClassPath(java.net.URL classpath)
Add a URL to the classpath. |
void |
addClassPath(java.net.URL[] classpath)
|
static java.net.URL[] |
decodePathString(java.lang.String classpath)
Converts a path string into an array of URLs. |
void |
forcePublic(byte[] theClass)
Take a byte array of class data and modify it to ensure that the class is public. |
java.net.URL |
getResource(java.lang.String name)
|
java.io.InputStream |
getResourceAsStream(java.lang.String name)
|
java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
|
java.lang.Class |
loadClass(java.lang.String name,
boolean resolve,
boolean mainClass)
|
java.lang.Class |
loadMainClass(java.lang.String name)
|
protected byte[] |
readClassFile(java.lang.String classname)
Try to read the byte[] data for a class file from the classpath. |
protected byte[] |
readFile(java.lang.String name)
|
Methods inherited from class java.lang.ClassLoader |
defineClass,
defineClass,
defineClass,
definePackage,
findClass,
findLibrary,
findLoadedClass,
findResource,
findResources,
findSystemClass,
getPackage,
getPackages,
getParent,
getResources,
getSystemClassLoader,
getSystemResource,
getSystemResourceAsStream,
getSystemResources,
loadClass,
resolveClass,
setSigners |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
_urlClassPath
protected java.util.Vector _urlClassPath
_classCache
protected java.util.Hashtable _classCache
URLClassLoader
public URLClassLoader()
- Creates a ClassLoader with no classpath.
URLClassLoader
public URLClassLoader(java.net.URL classpath)
- Creates a ClassLoader with a single URL for a classpath.
- Parameters:
classpath
- The base URL to search for classes relative to.
URLClassLoader
public URLClassLoader(java.net.URL[] classpath)
- Creates a ClassLoader with a list of classpath URLs.
- Parameters:
classpath
- The URLs to search for classes relative to.
addClassPath
public void addClassPath(java.net.URL[] classpath)
addClassPath
public void addClassPath(java.net.URL classpath)
- Add a URL to the classpath. This URL is searched for for classes.
- Parameters:
classpath
- The base URL to search.
loadMainClass
public java.lang.Class loadMainClass(java.lang.String name)
throws java.lang.ClassNotFoundException
loadClass
public java.lang.Class loadClass(java.lang.String name,
boolean resolve)
throws java.lang.ClassNotFoundException
- Overrides:
- loadClass in class java.lang.ClassLoader
loadClass
public java.lang.Class loadClass(java.lang.String name,
boolean resolve,
boolean mainClass)
throws java.lang.ClassNotFoundException
readClassFile
protected byte[] readClassFile(java.lang.String classname)
- Try to read the byte[] data for a class file from the classpath.
- Parameters:
name
- The fully-qualified name of the class.- Returns:
- A byte[] containing the classfile data, or null if not found.
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
- Overrides:
- getResourceAsStream in class java.lang.ClassLoader
getResource
public java.net.URL getResource(java.lang.String name)
- Overrides:
- getResource in class java.lang.ClassLoader
readFile
protected byte[] readFile(java.lang.String name)
decodePathString
public static java.net.URL[] decodePathString(java.lang.String classpath)
- Converts a path string into an array of URLs.
eg. "foo:http://bar/" would become a 2-URL array, with "file:///foo/"
and "http://bar/".
- Parameters:
classpath
- The path to decode, entries delimited by the
appropriate charactor for the platform.
forcePublic
public void forcePublic(byte[] theClass)
- Take a byte array of class data and modify it to ensure that the class is public.
This is used for the "main" classes of applications.