submarine.pages.loader
Class SimpleClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--submarine.pages.loader.SimpleClassLoader

public class SimpleClassLoader
extends java.lang.ClassLoader

This is a JDK1.1 equivalent of URLClassLoader. It have no dependency on tomcat or any other api - just standard java. Based on AdaptiveClassLoader from JServ1, with the dependency check and reloading features removed ( and moved to an external component) This is based on the fact that class loading and dependency checking can be separated and we want to support multiple forms of class loaders. The interface also changed to match URLClassLoader. This class should be used _only_ with JDK1.1, for JDK1.2 you should use a class loader that is aware of Permissions and the new rules ( sealing, etc ) This class loader respects the standard order defined in the ClassLoader documentation - for a different order you can plug in a different class loader ( in the configurations ). Since this class loader will be visible to applications we need to prevent exploits - we'll minimize the public method usage. The class path can be set only when the object is constructed.


Inner Class Summary
private  class SimpleClassLoader.Resource
          Private class used to store the result of the search
 
Inner classes inherited from class java.lang.ClassLoader
java.lang.ClassLoader.NativeLibrary
 
Field Summary
private static int debug
           
protected  java.lang.ClassLoader parent
          A parent class loader for delegation of finding a class definition.
protected  java.lang.String[] reserved
          Reserved names - this class loader will not allow creation of classes that start with one of those strings.
(package private)  java.lang.SecurityManager sm
           
protected  java.net.URL[] urls
          The classpath which this classloader searches for class definitions.
 
Fields inherited from class java.lang.ClassLoader
bootstrapClassPath, classes, defaultDomain, defaultPermissions, domains, getClassLoaderPerm, initialized, loadedLibraryNames, nativeLibraries, nativeLibraryContext, nocerts, package2certs, packages, scl, sclSet, sys_paths, systemNativeLibraries, usr_paths
 
Constructor Summary
SimpleClassLoader(java.net.URL[] urls)
           
SimpleClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
           
SimpleClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent, java.lang.String[] reserved)
          This is the prefered constructor to be used with this class loader
 
Method Summary
private  void checkURLs()
           
private  SimpleClassLoader.Resource doFindResource(java.lang.String name)
           
 java.lang.ClassLoader getParentLoader()
          We can't declare a method "getParent" since it'll not compile in JDK1.2 - the method is final.
 java.net.URL getResource(java.lang.String name)
          Find a resource with a given name.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Get an InputStream on a given resource.
 java.net.URL[] getURLs()
           
 boolean hasLoadedClass(java.lang.String name)
           
private  byte[] loadBytesFromStream(java.io.InputStream in, int length)
          Loads all the bytes of an InputStream.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Resolves the specified name to a Class.
(package private)  void log(java.lang.String s)
           
 
Methods inherited from class java.lang.ClassLoader
, addClass, check, checkCerts, checkPackageAccess, compareCerts, defineClass, defineClass, defineClass, defineClass0, definePackage, findBootstrapClass, findBootstrapClass0, findClass, findLibrary, findLoadedClass, findNative, findResource, findResources, findSystemClass, getBootstrapClassPath, getBootstrapResource, getBootstrapResources, getCallerClassLoader, getDefaultDomain, getGetClassLoaderPerm, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, initializePath, isAncestor, loadClass, loadClassInternal, loadLibrary, loadLibrary0, resolveClass, resolveClass0, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

debug

private static final int debug

urls

protected java.net.URL[] urls
The classpath which this classloader searches for class definitions. Each element of the vector should be either a directory, a .zip file, or a .jar file.

It may be empty when only system classes are controlled.


parent

protected java.lang.ClassLoader parent
A parent class loader for delegation of finding a class definition. JDK 1.2 contains parent class loaders as part of java.lang.ClassLoader, the parent being passed to a constructor, and retreived with getParent() method. For JDK 1.1 compatibility, we'll duplicate the 1.2 private member var.

reserved

protected java.lang.String[] reserved
Reserved names - this class loader will not allow creation of classes that start with one of those strings.

sm

java.lang.SecurityManager sm
Constructor Detail

SimpleClassLoader

public SimpleClassLoader(java.net.URL[] urls)

SimpleClassLoader

public SimpleClassLoader(java.net.URL[] urls,
                         java.lang.ClassLoader parent)

SimpleClassLoader

public SimpleClassLoader(java.net.URL[] urls,
                         java.lang.ClassLoader parent,
                         java.lang.String[] reserved)
This is the prefered constructor to be used with this class loader
Method Detail

getParentLoader

public java.lang.ClassLoader getParentLoader()
We can't declare a method "getParent" since it'll not compile in JDK1.2 - the method is final. But we don't have to - this will be used via JdkCompat

checkURLs

private void checkURLs()

log

void log(java.lang.String s)

hasLoadedClass

public boolean hasLoadedClass(java.lang.String name)

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Resolves the specified name to a Class. The method loadClass() is called by the virtual machine. As an abstract method, loadClass() must be defined in a subclass of ClassLoader.
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - the name of the desired Class.
resolve - true if the Class needs to be resolved; false if the virtual machine just wants to determine whether the class exists or not
Returns:
the resulting Class.
Throws:
java.lang.ClassNotFoundException - if the class loader cannot find a the requested class.

getResource

public java.net.URL getResource(java.lang.String name)
Find a resource with a given name. The return is a URL to the resource. Doing a getContent() on the URL may return an Image, an AudioClip,or an InputStream.
Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - the name of the resource, to be used as is.
Returns:
an URL on the resource, or null if not found.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Get an InputStream on a given resource. Will return null if no resource with this name is found.

The JServClassLoader translate the resource's name to a file or a zip entry. It looks for the resource in all its repository entry.

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
name - the name of the resource, to be used as is.
Returns:
an InputStream on the resource, or null if not found.
See Also:
Class.getResourceAsStream(String)

doFindResource

private SimpleClassLoader.Resource doFindResource(java.lang.String name)

loadBytesFromStream

private byte[] loadBytesFromStream(java.io.InputStream in,
                                   int length)
                            throws java.io.IOException
Loads all the bytes of an InputStream.

getURLs

public java.net.URL[] getURLs()

Submarine project. free distribution of this software must include the opensource licence.
Guénolé de Cadoudal.