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.security.cert.Certificate; 46: import java.util.ArrayList; 47: import java.util.jar.Manifest; 48: 49: /** 50: * A <code>URLLoader</code> contains all logic to load resources from a 51: * given base <code>URL</code>. 52: */ 53: public abstract class URLLoader 54: { 55: /** 56: * Our classloader to get info from if needed. 57: */ 58: final URLClassLoader classloader; 59: 60: /** 61: * The base URL from which all resources are loaded. 62: */ 63: final URL baseURL; 64: 65: /** 66: * The stream handler factory. 67: */ 68: final URLStreamHandlerFactory factory; 69: 70: /** 71: * The source for stream handlers. 72: */ 73: final URLStreamHandlerCache cache; 74: 75: /** 76: * A <code>CodeSource</code> without any associated certificates. 77: * It is common for classes to not have certificates associated 78: * with them. If they come from the same <code>URLLoader</code> 79: * then it is safe to share the associated <code>CodeSource</code> 80: * between them since <code>CodeSource</code> is immutable. 81: */ 82: final CodeSource noCertCodeSource; 83: 84: public URLLoader(URLClassLoader classloader, URLStreamHandlerCache cache, 85: URLStreamHandlerFactory factory, 86: URL baseURL) 87: { 88: this(classloader, cache, factory, baseURL, baseURL); 89: } 90: 91: public URLLoader(URLClassLoader classloader, URLStreamHandlerCache cache, 92: URLStreamHandlerFactory factory, 93: URL baseURL, URL overrideURL) 94: { 95: this.classloader = classloader; 96: this.baseURL = baseURL; 97: this.factory = factory; 98: this.cache = cache; 99: this.noCertCodeSource = new CodeSource(overrideURL, (Certificate[]) null); 100: } 101: 102: /** 103: * Return the base URL of this loader. 104: */ 105: public final URL getBaseURL() 106: { 107: return baseURL; 108: } 109: 110: /** 111: * Returns a <code>Class</code> loaded by this 112: * <code>URLLoader</code>, or <code>null</code> when this loader 113: * either can't load the class or doesn't know how to load classes 114: * at all. Most subclasses do not need to override this; it is only 115: * useful in situations where the subclass has a more direct way of 116: * making <code>Class</code> objects. 117: */ 118: public Class getClass(String className) 119: { 120: return null; 121: } 122: 123: /** 124: * Returns a <code>Resource</code> loaded by this 125: * <code>URLLoader</code>, or <code>null</code> when no 126: * <code>Resource</code> with the given name exists. 127: */ 128: public abstract Resource getResource(String s); 129: 130: /** 131: * Returns the <code>Manifest</code> associated with the 132: * <code>Resource</code>s loaded by this <code>URLLoader</code> or 133: * <code>null</code> there is no such <code>Manifest</code>. 134: */ 135: public Manifest getManifest() 136: { 137: return null; 138: } 139: 140: /** 141: * Return a list of new URLLoader objects representing any 142: * class path entries added by this container. 143: */ 144: public ArrayList<URLLoader> getClassPath() 145: { 146: return null; 147: } 148: }