1 19 20 package org.apache.tools.ant.module.bridge; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.Enumeration ; 25 import org.openide.util.Enumerations; 26 import org.openide.util.Exceptions; 27 28 40 final class AuxClassLoader extends AntBridge.AllPermissionURLClassLoader { 41 42 private static boolean masked(String name) { 43 return name.startsWith("org.apache.tools.") && !name.startsWith("org.apache.tools.ant.module."); } 45 46 private final ClassLoader nbLoader; 47 48 public AuxClassLoader(ClassLoader nbLoader, ClassLoader antLoader, URL extraJar) { 49 super(new URL [] {extraJar}, antLoader); 50 this.nbLoader = nbLoader; 51 } 52 53 @Override 54 protected Class <?> findClass(String name) throws ClassNotFoundException { 55 if (!masked(name)) { 56 try { 57 return nbLoader.loadClass(name); 58 } catch (ClassNotFoundException cnfe) { 59 } 61 } 62 try { 63 return super.findClass(name); 64 } catch (UnsupportedClassVersionError e) { 65 Exceptions.attachMessage(e, "loading: " + name); 67 throw e; 68 } 69 } 70 71 @Override 72 public URL findResource(String name) { 73 if (!masked(name)) { 74 URL u = nbLoader.getResource(name); 75 if (u != null) { 76 return u; 77 } 78 } 79 return super.findResource(name); 80 } 81 82 @Override 83 public Enumeration <URL > findResources(String name) throws IOException { 84 return Enumerations.removeDuplicates ( 86 Enumerations.concat ( 87 nbLoader.getResources(name), 88 super.findResources(name) 89 ) 90 ); 91 } 92 93 95 } 96 | Popular Tags |