< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  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 


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  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 


< prev index next >