Showing the changes to java/pkg/javax/management/loading/DefaultLoaderRepository.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,120 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2000, 2008, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package javax.management.loading; | ||
| 27 | |||
| 28 | import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; | ||
| 29 | import java.util.Iterator; | ||
| 30 | import java.util.List; | ||
| 31 | import java.util.logging.Level; | ||
| 32 | import javax.management.MBeanServer; | ||
| 33 | import javax.management.MBeanServerFactory; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * <p>Keeps the list of Class Loaders registered in the MBean Server. | ||
| 37 | * It provides the necessary methods to load classes using the registered | ||
| 38 | * Class Loaders.</p> | ||
| 39 | * | ||
| 40 | * <p>This deprecated class is maintained for compatibility. In | ||
| 41 | * previous versions of JMX, there was one | ||
| 42 | * <code>DefaultLoaderRepository</code> shared by all MBean servers. | ||
| 43 | * As of JMX 1.2, that functionality is approximated by using {@link | ||
| 44 | * MBeanServerFactory#findMBeanServer} to find all known MBean | ||
| 45 | * servers, and consulting the {@link ClassLoaderRepository} of each | ||
| 46 | * one. It is strongly recommended that code referencing | ||
| 47 | * <code>DefaultLoaderRepository</code> be rewritten.</p> | ||
| 48 | * | ||
| 49 | * @deprecated Use | ||
| 50 | * {@link javax.management.MBeanServer#getClassLoaderRepository()}} | ||
| 51 | * instead. | ||
| 52 | * | ||
| 53 | * @since 1.5 | ||
| 54 | */ | ||
| 55 | @Deprecated | ||
| 56 | public class DefaultLoaderRepository { | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Go through the list of class loaders and try to load the requested | ||
| 60 | * class. | ||
| 61 | * The method will stop as soon as the class is found. If the class | ||
| 62 | * is not found the method will throw a <CODE>ClassNotFoundException</CODE> | ||
| 63 | * exception. | ||
| 64 | * | ||
| 65 | * @param className The name of the class to be loaded. | ||
| 66 | * | ||
| 67 | * @return the loaded class. | ||
| 68 | * | ||
| 69 | * @exception ClassNotFoundException The specified class could not be | ||
| 70 | * found. | ||
| 71 | */ | ||
| 72 | public static Class<?> loadClass(String className) | ||
| 73 | throws ClassNotFoundException { | ||
| 74 | MBEANSERVER_LOGGER.logp(Level.FINEST, | ||
| 75 | DefaultLoaderRepository.class.getName(), | ||
| 76 | "loadClass", className); | ||
| 77 | return load(null, className); | ||
| 78 | } | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Go through the list of class loaders but exclude the given | ||
| 82 | * class loader, then try to load | ||
| 83 | * the requested class. | ||
| 84 | * The method will stop as soon as the class is found. If the class | ||
| 85 | * is not found the method will throw a <CODE>ClassNotFoundException</CODE> | ||
| 86 | * exception. | ||
| 87 | * | ||
| 88 | * @param className The name of the class to be loaded. | ||
| 89 | * @param loader The class loader to be excluded. | ||
| 90 | * | ||
| 91 | * @return the loaded class. | ||
| 92 | * | ||
| 93 | * @exception ClassNotFoundException The specified class could not be | ||
| 94 | * found. | ||
| 95 | */ | ||
| 96 | public static Class<?> loadClassWithout(ClassLoader loader, | ||
| 97 | String className) | ||
| 98 | throws ClassNotFoundException { | ||
| 99 | MBEANSERVER_LOGGER.logp(Level.FINEST, | ||
| 100 | DefaultLoaderRepository.class.getName(), | ||
| 101 | "loadClassWithout", className); | ||
| 102 | return load(loader, className); | ||
| 103 | } | ||
| 104 | |||
| 105 | private static Class<?> load(ClassLoader without, String className) | ||
| 106 | throws ClassNotFoundException { | ||
| 107 | final List<MBeanServer> mbsList = MBeanServerFactory.findMBeanServer(null); | ||
| 108 | |||
| 109 | for (MBeanServer mbs : mbsList) { | ||
| 110 | ClassLoaderRepository clr = mbs.getClassLoaderRepository(); | ||
| 111 | try { | ||
| 112 | return clr.loadClassWithout(without, className); | ||
| 113 | } catch (ClassNotFoundException e) { | ||
| 114 | // OK : Try with next one... | ||
| 115 | } | ||
| 116 | } | ||
| 117 | throw new ClassNotFoundException(className); | ||
| 118 | } | ||
| 119 | |||
| 120 | } | ||