Jadex 0.96-beta1

jadex.util
Class DynamicURLClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by jadex.util.DynamicURLClassLoader

public class DynamicURLClassLoader
extends ClassLoader

This loader supports reloading of modified classes, and also offers the functionality to add and remove URLs. A global instance of this class is provided by the static getInstance() method. For use in applets and webstart static facade methods are provided, which implement a fallback to the standard class loader in case of security restrictions.


Constructor Summary
DynamicURLClassLoader(ClassLoader parent)
          Create a new url class loader.
 
Method Summary
 void addURL(URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
static void addURLToInstance(URL url)
          Operate on the singleton instance if available.
 List getAllClasspathURLs()
          Get all urls from the classpath including the added ones.
static ClassLoader getInstance()
          Retrieve the global Jadex class loader.
 String getPackageOfFile(String filename)
          Return the package (if any).
static String getPackageOfFileFromInstance(String filename)
          Return the package (if any).
 URL[] getURLs()
          Return the URLs of the class loader.
static URL[] getURLsFromInstance()
          Operate on the singleton instance if available.
 Class loadClass(String name)
          Load a given class.
static Class loadClassWithInstance(String name, boolean resolve)
          Operate on the singleton instance if available.
 Class loadModifiedClass(Class clazz)
          Reload a given class.
static Class loadModifiedClassWithInstance(Class clazz)
          Operate on the singleton instance if available.
 void removeURL(URL url)
          Removes the specified URL from the list of URLs to search for classes and resources.
static void removeURLFromInstance(URL url)
          Operate on the singleton instance if available.
 void reset()
          Reset the class loader (remove all urls).
static void resetInstance()
          Reset the global Jadex class loader.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicURLClassLoader

public DynamicURLClassLoader(ClassLoader parent)
Create a new url class loader.

Parameters:
parent - the parent class loader for delegation
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a class loader.
See Also:
SecurityManager.checkCreateClassLoader()
Method Detail

addURL

public void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources. Checks if the URL is already contained in the list of urls and adds only when URL is new.

Parameters:
url - the URL to be added to the search path of URLs

removeURL

public void removeURL(URL url)
Removes the specified URL from the list of URLs to search for classes and resources.

Parameters:
url - the URL to be added to the search path of URLs

reset

public void reset()
Reset the class loader (remove all urls).


getURLs

public URL[] getURLs()
Return the URLs of the class loader.


loadModifiedClass

public Class loadModifiedClass(Class clazz)
Reload a given class. Checks the if the class has been modified and also reloads anonymous inner classes.

Returns:
A newly loaded version of the class (if modified) or the original class object.

getAllClasspathURLs

public List getAllClasspathURLs()
Get all urls from the classpath including the added ones.


getPackageOfFile

public String getPackageOfFile(String filename)
Return the package (if any).

Returns:
The package (e.g. "java.lang") corresponding to a filename.

loadClass

public Class loadClass(String name)
                throws ClassNotFoundException
Load a given class.

Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

getInstance

public static ClassLoader getInstance()
Retrieve the global Jadex class loader.

Returns:
The Jadex class loader.

addURLToInstance

public static void addURLToInstance(URL url)
Operate on the singleton instance if available.


removeURLFromInstance

public static void removeURLFromInstance(URL url)
Operate on the singleton instance if available.


resetInstance

public static void resetInstance()
Reset the global Jadex class loader.


getURLsFromInstance

public static URL[] getURLsFromInstance()
Operate on the singleton instance if available.


loadClassWithInstance

public static Class loadClassWithInstance(String name,
                                          boolean resolve)
                                   throws ClassNotFoundException
Operate on the singleton instance if available.

Throws:
ClassNotFoundException

loadModifiedClassWithInstance

public static Class loadModifiedClassWithInstance(Class clazz)
Operate on the singleton instance if available.


getPackageOfFileFromInstance

public static String getPackageOfFileFromInstance(String filename)
Return the package (if any).

Returns:
The package (e.g. "java.lang") corresponding to a filename.

Jadex 0.96-beta1

Submit a bug or feature
For further API reference and developer documentation, see the Jadex User Guide and the Jadex Tutorial. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, and working code examples.

Copyright (C) 2002-2007 Lars Braubach, Alexander Pokahr - University of Hamburg. Use is subject to license terms.