< prev index next >

src/jdk.xml.bind/share/classes/com/sun/istack/internal/tools/ParallelWorldClassLoader.java

Print this page




  40 import java.util.HashSet;
  41 import java.util.Set;
  42 import java.util.jar.JarFile;
  43 import java.util.logging.Level;
  44 import java.util.logging.Logger;
  45 
  46 /**
  47  * Load classes/resources from a side folder, so that
  48  * classes of the same package can live in a single jar file.
  49  *
  50  * <p>
  51  * For example, with the following jar file:
  52  * <pre>
  53  *  /
  54  *  +- foo
  55  *     +- X.class
  56  *  +- bar
  57  *     +- X.class
  58  * </pre>
  59  * <p>
  60  * {@link ParallelWorldClassLoader}("foo/") would load <tt>X.class<tt> from
  61  * <tt>/foo/X.class</tt> (note that X is defined in the root package, not
  62  * <tt>foo.X</tt>.
  63  *
  64  * <p>
  65  * This can be combined with  {@link MaskingClassLoader} to mask classes which are loaded by the parent
  66  * class loader so that the child class loader
  67  * classes living in different folders are loaded
  68  * before the parent class loader loads classes living the jar file publicly
  69  * visible
  70  * For example, with the following jar file:
  71  * <pre>
  72  *  /
  73  *  +- foo
  74  *     +- X.class
  75  *  +- bar
  76  *     +-foo
  77  *        +- X.class
  78  * </pre>
  79  * <p>
  80  * {@link ParallelWorldClassLoader}(MaskingClassLoader.class.getClassLoader()) would load <tt>foo.X.class<tt> from
  81  * <tt>/bar/foo.X.class</tt> not the <tt>foo.X.class<tt> in the publicly visible place in the jar file, thus
  82  * masking the parent classLoader from loading the class from  <tt>foo.X.class<tt>


  83  * (note that X is defined in the  package foo, not
  84  * <tt>bar.foo.X</tt>.
  85  *
  86  * @author Kohsuke Kawaguchi
  87  */
  88 public class ParallelWorldClassLoader extends ClassLoader implements Closeable {
  89 
  90     /**
  91      * Strings like "prefix/", "abc/", or "" to indicate
  92      * classes should be loaded normally.
  93      */
  94     private final String prefix;
  95     private final Set<JarFile> jars;
  96 
  97     public ParallelWorldClassLoader(ClassLoader parent,String prefix) {
  98         super(parent);
  99         this.prefix = prefix;
 100         jars = Collections.synchronizedSet(new HashSet<JarFile>());
 101     }
 102 
 103     protected Class findClass(String name) throws ClassNotFoundException {
 104 




  40 import java.util.HashSet;
  41 import java.util.Set;
  42 import java.util.jar.JarFile;
  43 import java.util.logging.Level;
  44 import java.util.logging.Logger;
  45 
  46 /**
  47  * Load classes/resources from a side folder, so that
  48  * classes of the same package can live in a single jar file.
  49  *
  50  * <p>
  51  * For example, with the following jar file:
  52  * <pre>
  53  *  /
  54  *  +- foo
  55  *     +- X.class
  56  *  +- bar
  57  *     +- X.class
  58  * </pre>
  59  * <p>
  60  * {@link ParallelWorldClassLoader}("foo/") would load {@code X.class} from
  61  * {@code /foo/X.class} (note that X is defined in the root package, not
  62  * {@code foo.X}.
  63  *
  64  * <p>
  65  * This can be combined with  {@link MaskingClassLoader} to mask classes which are loaded by the parent
  66  * class loader so that the child class loader
  67  * classes living in different folders are loaded
  68  * before the parent class loader loads classes living the jar file publicly
  69  * visible
  70  * For example, with the following jar file:
  71  * <pre>
  72  *  /
  73  *  +- foo
  74  *     +- X.class
  75  *  +- bar
  76  *     +-foo
  77  *        +- X.class
  78  * </pre>
  79  * <p>
  80  * {@link ParallelWorldClassLoader}(MaskingClassLoader.class.getClassLoader())
  81  * would load {@code foo.X.class}  from
  82  * {@code /bar/foo.X.class} not the {@code foo.X.class}
  83  * in the publicly visible place in the jar file, thus
  84  * masking the parent classLoader from loading the class from {@code foo.X.class}
  85  * (note that X is defined in the  package foo, not
  86  * {@code bar.foo.X}.
  87  *
  88  * @author Kohsuke Kawaguchi
  89  */
  90 public class ParallelWorldClassLoader extends ClassLoader implements Closeable {
  91 
  92     /**
  93      * Strings like "prefix/", "abc/", or "" to indicate
  94      * classes should be loaded normally.
  95      */
  96     private final String prefix;
  97     private final Set<JarFile> jars;
  98 
  99     public ParallelWorldClassLoader(ClassLoader parent,String prefix) {
 100         super(parent);
 101         this.prefix = prefix;
 102         jars = Collections.synchronizedSet(new HashSet<JarFile>());
 103     }
 104 
 105     protected Class findClass(String name) throws ClassNotFoundException {
 106 


< prev index next >