Frames | No Frames |
1: /* URLLoader.java -- base helper class for URLClassLoader 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package gnu.java.net.loader; 40: 41: import java.net.URL; 42: import java.net.URLClassLoader; 43: import java.net.URLStreamHandlerFactory; 44: import java.security.CodeSource; 45: import java.util.ArrayList; 46: import java.util.jar.Manifest; 47: 48: /** 49: * A <code>URLLoader</code> contains all logic to load resources from a 50: * given base <code>URL</code>. 51: */ 52: public abstract class URLLoader 53: { 54: /** 55: * Our classloader to get info from if needed. 56: */ 57: final URLClassLoader classloader; 58: 59: /** 60: * The base URL from which all resources are loaded. 61: */ 62: final URL baseURL; 63: 64: /** 65: * The stream handler factory. 66: */ 67: final URLStreamHandlerFactory factory; 68: 69: /** 70: * The source for stream handlers. 71: */ 72: final URLStreamHandlerCache cache; 73: 74: /** 75: * A <code>CodeSource</code> without any associated certificates. 76: * It is common for classes to not have certificates associated 77: * with them. If they come from the same <code>URLLoader</code> 78: * then it is safe to share the associated <code>CodeSource</code> 79: * between them since <code>CodeSource</code> is immutable. 80: */ 81: final CodeSource noCertCodeSource; 82: 83: public URLLoader(URLClassLoader classloader, URLStreamHandlerCache cache, 84: URLStreamHandlerFactory factory, 85: URL baseURL) 86: { 87: this(classloader, cache, factory, baseURL, baseURL); 88: } 89: 90: public URLLoader(URLClassLoader classloader, URLStreamHandlerCache cache, 91: URLStreamHandlerFactory factory, 92: URL baseURL, URL overrideURL) 93: { 94: this.classloader = classloader; 95: this.baseURL = baseURL; 96: this.factory = factory; 97: this.cache = cache; 98: this.noCertCodeSource = new CodeSource(overrideURL, null); 99: } 100: 101: /** 102: * Return the base URL of this loader. 103: */ 104: public final URL getBaseURL() 105: { 106: return baseURL; 107: } 108: 109: /** 110: * Returns a <code>Class</code> loaded by this 111: * <code>URLLoader</code>, or <code>null</code> when this loader 112: * either can't load the class or doesn't know how to load classes 113: * at all. Most subclasses do not need to override this; it is only 114: * useful in situations where the subclass has a more direct way of 115: * making <code>Class</code> objects. 116: */ 117: public Class getClass(String className) 118: { 119: return null; 120: } 121: 122: /** 123: * Returns a <code>Resource</code> loaded by this 124: * <code>URLLoader</code>, or <code>null</code> when no 125: * <code>Resource</code> with the given name exists. 126: */ 127: public abstract Resource getResource(String s); 128: 129: /** 130: * Returns the <code>Manifest</code> associated with the 131: * <code>Resource</code>s loaded by this <code>URLLoader</code> or 132: * <code>null</code> there is no such <code>Manifest</code>. 133: */ 134: public Manifest getManifest() 135: { 136: return null; 137: } 138: 139: /** 140: * Return a list of new URLLoader objects representing any 141: * class path entries added by this container. 142: */ 143: public ArrayList getClassPath() 144: { 145: return null; 146: }