com.sun.istack.tools
Class ParallelWorldClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by com.sun.istack.tools.ParallelWorldClassLoader

public class ParallelWorldClassLoader
extends java.lang.ClassLoader

Load classes/resources from a side folder, so that classes of the same package can live in a single jar file.

For example, with the following jar file:

  /
  +- foo
     +- X.class
  +- bar
     +- X.class
 

ParallelWorldClassLoader("foo/") would load X.class from /foo/X.class (note that X is defined in the root package, not foo.X.

This can be combined with MaskingClassLoader to mask classes which are loaded by the parent class loader so that the child class loader classes living in different folders are loaded before the parent class loader loads classes living the jar file publicly visible For example, with the following jar file:

  /
  +- foo
     +- X.class
  +- bar
     +-foo
        +- X.class
 

ParallelWorldClassLoader(MaskingClassLoader.class.getClassLoader()) would load foo.X.class from /bar/foo.X.class not the foo.X.class in the publicly visible place in the jar file, thus masking the parent classLoader from loading the class from foo.X.class (note that X is defined in the package foo, not bar.foo.X.

Author:
Kohsuke Kawaguchi

Constructor Summary
ParallelWorldClassLoader(java.lang.ClassLoader parent, java.lang.String prefix)
           
 
Method Summary
protected  java.lang.Class findClass(java.lang.String name)
           
protected  java.net.URL findResource(java.lang.String name)
           
protected  java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
           
static java.net.URL toJarUrl(java.net.URL res)
          Given the URL inside jar, returns the URL to the jar itself.
 
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, 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

ParallelWorldClassLoader

public ParallelWorldClassLoader(java.lang.ClassLoader parent,
                                java.lang.String prefix)
Method Detail

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Overrides:
findClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

findResource

protected java.net.URL findResource(java.lang.String name)
Overrides:
findResource in class java.lang.ClassLoader

findResources

protected java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
                                                     throws java.io.IOException
Overrides:
findResources in class java.lang.ClassLoader
Throws:
java.io.IOException

toJarUrl

public static java.net.URL toJarUrl(java.net.URL res)
                             throws java.lang.ClassNotFoundException,
                                    java.net.MalformedURLException
Given the URL inside jar, returns the URL to the jar itself.

Throws:
java.lang.ClassNotFoundException
java.net.MalformedURLException


Copyright © 2011. All Rights Reserved.