cuba.wired
Class DDClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by cuba.wired.DDClassLoader

public class DDClassLoader
extends java.net.URLClassLoader

Specialized class loader which reads module names from wired-application.xml and tries to locate them in all directories specified in the system class path. This allows to keep the module names themselfs off from the class path which otherwise may become very, very large and potentially can't be expressed on a command line any more. E.g. on Windows systems up to Windows 2000 the maximum length for command lines and environment variables is 1024 characters, causing troubles very soon when working with a large number of separate component modules.

This class loader is supposed to be used only in wired J2SE environments and being specified as an alternative system class loader by system property java.system.class.loader. In managed environments like servlet engines or application servers you should never change the class loader at all. And you hopefully never have to, because the class loaders in these environments are already suitable for large amounts of separate modules.

Author:
Jan Lessner

Constructor Summary
DDClassLoader(java.lang.ClassLoader parent)
          Construct a new DDClassLoader.
 
Method Summary
protected  void addClasspath()
          Add the system class path elements to the URL search list of this loader to let it load as many classes as possible by its own rather then asking its parent.
protected  void addModule(java.lang.String moduleName)
          Try to locate a module and add it to the loader's URL search list if found.
 java.lang.Class loadClass(java.lang.String name)
          Overwrites the appropriate method of the base class.
protected  java.lang.String locateModule(java.lang.String moduleName)
          Try to find a module from one of the directories listed in the system class path.
protected  java.net.URL makeURL(java.lang.String moduleLocation)
          Make a URL from a file name
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DDClassLoader

public DDClassLoader(java.lang.ClassLoader parent)
              throws InitException
Construct a new DDClassLoader. The loader reads all modules being listed in a wired-application.xml and tries to locate them on the class path. If they are not present, it tries to find them in one of the directories mentioned in the class path and adds these locations to its URL search list.

Throws:
InitException - if no wired-application.xml can be found or if it can't be read properly.
Method Detail

addClasspath

protected void addClasspath()
                     throws java.net.MalformedURLException
Add the system class path elements to the URL search list of this loader to let it load as many classes as possible by its own rather then asking its parent. See loadClass(java.lang.String) why this is reasonable.

Throws:
java.net.MalformedURLException

locateModule

protected java.lang.String locateModule(java.lang.String moduleName)
Try to find a module from one of the directories listed in the system class path.

Parameters:
moduleName - Name of the module as found from wired-application.xml
Returns:
The module's full path or null if it could not be located

makeURL

protected java.net.URL makeURL(java.lang.String moduleLocation)
                        throws java.net.MalformedURLException
Make a URL from a file name

Throws:
java.net.MalformedURLException

addModule

protected void addModule(java.lang.String moduleName)
                  throws java.net.MalformedURLException
Try to locate a module and add it to the loader's URL search list if found.

Parameters:
moduleName - Name of the module to locate
Throws:
java.net.MalformedURLException

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Overwrites the appropriate method of the base class. As an exception from the general rule, we first try to load the class by our own before asking the parent class loader. This is of interest for loading classes from both class directories on the class path and from component archives made accessible through this loader's extension scheme (e.g. during development). This often causes the typical problem of a class being loaded by one loader which then hasn't access to the depending classes. This loader includes the complete system class path to its own search list and calls the parent only if this is still not enough.

Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException