001/* ClassLoaderRepository.java -- Represents a collection of class loadersx. 002 Copyright (C) 2006 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.management.loading; 039 040/** 041 * Implementations of this interface maintain a list of 042 * {@link ClassLoader}s for use by the management servers, 043 * allowing classes to be loaded by the first {@link ClassLoader} 044 * that will do so. A class loader is added to the list 045 * whenever a {@link ClassLoader} instance is registered with 046 * the management server, and it does not implement the 047 * {@link PrivateClassLoader} interface. They are removed when 048 * unregistered. The first class loader in the list is always 049 * the one which was used to load the management server itself. 050 * 051 * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 052 * @since 1.5 053 * @see MBeanServerFactory 054 */ 055public interface ClassLoaderRepository 056{ 057 058 /** 059 * Attempts to load the given class using class loaders 060 * supplied by the list. The {@link ClassLoader#loadClass(String)} 061 * method of each class loader is called. If the method 062 * returns successfully, then the returned {@link Class} instance 063 * is returned. If a {@link ClassNotFoundException} is thrown, 064 * then the next loader is tried. Any other exception thrown 065 * by the method is passed back to the caller. This method 066 * throws a {@link ClassNotFoundException} itself if all the 067 * class loaders listed prove fruitless. 068 * 069 * @param name the name of the class to load. 070 * @return the loaded class. 071 * @throws ClassNotFoundException if all the class loaders fail 072 * to load the class. 073 */ 074 Class<?> loadClass(String name) 075 throws ClassNotFoundException; 076 077 /** 078 * <p> 079 * Attempts to load the given class using class loaders 080 * supplied by the list, stopping when the specified 081 * loader is reached. The {@link ClassLoader#loadClass(String)} 082 * method of each class loader is called. If the method 083 * returns successfully, then the returned {@link Class} instance 084 * is returned. If a {@link ClassNotFoundException} is thrown, 085 * then the next loader is tried. Any other exception thrown 086 * by the method is passed back to the caller. This method 087 * throws a {@link ClassNotFoundException} itself if all the 088 * class loaders listed prove fruitless. 089 * </p> 090 * <p> 091 * This method is usually used by the class loader specified 092 * by the <code>stop</code> argument to load classes using the 093 * loaders that appear before it in the list. By stopping when 094 * the loader is reached, the deadlock that occurs when the loader 095 * is merely skipped is avoided. 096 * </p> 097 * 098 * @param stop the class loader at which to stop, or <code>null</code> 099 * to obtain the same behaviour as {@link #loadClass(String)}. 100 * @param name the name of the class to load. 101 * @return the loaded class. 102 * @throws ClassNotFoundException if all the class loaders fail 103 * to load the class. 104 */ 105 Class<?> loadClassBefore(ClassLoader stop, String name) 106 throws ClassNotFoundException; 107 108 /** 109 * <p> 110 * Attempts to load the given class using class loaders 111 * supplied by the list, excluding the one specified. 112 * The {@link ClassLoader#loadClass(String)} 113 * method of each class loader is called. If the method 114 * returns successfully, then the returned {@link Class} instance 115 * is returned. If a {@link ClassNotFoundException} is thrown, 116 * then the next loader is tried. Any other exception thrown 117 * by the method is passed back to the caller. This method 118 * throws a {@link ClassNotFoundException} itself if all the 119 * class loaders listed prove fruitless. 120 * </p> 121 * <p> 122 * Note that this method may deadlock if called simultaneously 123 * by two class loaders in the list. 124 * {@link loadClassBefore(ClassLoader, String)} should be used 125 * in preference to this method to avoid this. 126 * </p> 127 * 128 * @param exclude the class loader to exclude, or <code>null</code> 129 * to obtain the same behaviour as {@link #loadClass(String)}. 130 * @param name the name of the class to load. 131 * @return the loaded class. 132 * @throws ClassNotFoundException if all the class loaders fail 133 * to load the class. 134 */ 135 Class<?> loadClassWithout(ClassLoader exclude, String name) 136 throws ClassNotFoundException; 137 138} 139