KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > loading > ClassLoaderRepository


1 /*
2  * @(#)ClassLoaderRepository.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.loading;
9
10 import javax.management.MBeanServer JavaDoc; // for Javadoc
11

12 /**
13  * <p>Instances of this interface are used to keep the list of ClassLoaders
14  * registered in an MBean Server.
15  * They provide the necessary methods to load classes using the registered
16  * ClassLoaders.</p>
17  *
18  * <p>The first ClassLoader in a <code>ClassLoaderRepository</code> is
19  * always the MBean Server's own ClassLoader.</p>
20  *
21  * <p>When an MBean is registered in an MBean Server, if it is of a
22  * subclass of {@link java.lang.ClassLoader} and if it does not
23  * implement the interface {@link PrivateClassLoader}, it is added to
24  * the end of the MBean Server's <code>ClassLoaderRepository</code>.
25  * If it is subsequently unregistered from the MBean Server, it is
26  * removed from the <code>ClassLoaderRepository</code>.</p>
27  *
28  * <p>The order of MBeans in the <code>ClassLoaderRepository</code> is
29  * significant. For any two MBeans <em>X</em> and <em>Y</em> in the
30  * <code>ClassLoaderRepository</code>, <em>X</em> must appear before
31  * <em>Y</em> if the registration of <em>X</em> was completed before
32  * the registration of <em>Y</em> started. If <em>X</em> and
33  * <em>Y</em> were registered concurrently, their order is
34  * indeterminate. The registration of an MBean corresponds to the
35  * call to {@link MBeanServer#registerMBean} or one of the {@link
36  * MBeanServer}<code>.createMBean</code> methods.</p>
37  *
38  * @see javax.management.MBeanServerFactory
39  *
40  * @since 1.5
41  * @since.unbundled JMX 1.1
42  */

43 public interface ClassLoaderRepository {
44
45     /**
46      * <p>Load the given class name through the list of class loaders.
47      * Each ClassLoader in turn from the ClassLoaderRepository is
48      * asked to load the class via its {@link
49      * ClassLoader#loadClass(String)} method. If it successfully
50      * returns a {@link Class} object, that is the result of this
51      * method. If it throws a {@link ClassNotFoundException}, the
52      * search continues with the next ClassLoader. If it throws
53      * another exception, the exception is propagated from this
54      * method. If the end of the list is reached, a {@link
55      * ClassNotFoundException} is thrown.</p>
56      *
57      * @param className The name of the class to be loaded.
58      *
59      * @return the loaded class.
60      *
61      * @exception ClassNotFoundException The specified class could not be
62      * found.
63      */

64     public Class JavaDoc loadClass(String JavaDoc className)
65         throws ClassNotFoundException JavaDoc;
66     
67     /**
68      * <p>Load the given class name through the list of class loaders,
69      * excluding the given one. Each ClassLoader in turn from the
70      * ClassLoaderRepository, except <code>exclude</code>, is asked to
71      * load the class via its {@link ClassLoader#loadClass(String)}
72      * method. If it successfully returns a {@link Class} object,
73      * that is the result of this method. If it throws a {@link
74      * ClassNotFoundException}, the search continues with the next
75      * ClassLoader. If it throws another exception, the exception is
76      * propagated from this method. If the end of the list is
77      * reached, a {@link ClassNotFoundException} is thrown.</p>
78      *
79      * <p>Be aware that if a ClassLoader in the ClassLoaderRepository
80      * calls this method from its {@link ClassLoader#loadClass(String)
81      * loadClass} method, it exposes itself to a deadlock if another
82      * ClassLoader in the ClassLoaderRepository does the same thing at
83      * the same time. The {@link #loadClassBefore} method is
84      * recommended to avoid the risk of deadlock.</p>
85      *
86      * @param className The name of the class to be loaded.
87      * @param exclude The class loader to be excluded. May be null,
88      * in which case this method is equivalent to {@link #loadClass
89      * loadClass(className)}.
90      *
91      * @return the loaded class.
92      *
93      * @exception ClassNotFoundException The specified class could not
94      * be found.
95      */

96     public Class JavaDoc loadClassWithout(ClassLoader JavaDoc exclude,
97                   String JavaDoc className)
98         throws ClassNotFoundException JavaDoc;
99
100     /**
101      * <p>Load the given class name through the list of class loaders,
102      * stopping at the given one. Each ClassLoader in turn from the
103      * ClassLoaderRepository is asked to load the class via its {@link
104      * ClassLoader#loadClass(String)} method. If it successfully
105      * returns a {@link Class} object, that is the result of this
106      * method. If it throws a {@link ClassNotFoundException}, the
107      * search continues with the next ClassLoader. If it throws
108      * another exception, the exception is propagated from this
109      * method. If the search reaches <code>stop</code> or the end of
110      * the list, a {@link ClassNotFoundException} is thrown.</p>
111      *
112      * <p>Typically this method is called from the {@link
113      * ClassLoader#loadClass(String) loadClass} method of
114      * <code>stop</code>, to consult loaders that appear before it
115      * in the <code>ClassLoaderRepository</code>. By stopping the
116      * search as soon as <code>stop</code> is reached, a potential
117      * deadlock with concurrent class loading is avoided.</p>
118      *
119      * @param className The name of the class to be loaded.
120      * @param stop The class loader at which to stop. May be null, in
121      * which case this method is equivalent to {@link #loadClass(String)
122      * loadClass(className)}.
123      *
124      * @return the loaded class.
125      *
126      * @exception ClassNotFoundException The specified class could not
127      * be found.
128      *
129      * @since.unbundled JMX 1.2
130      */

131     public Class JavaDoc loadClassBefore(ClassLoader JavaDoc stop,
132                  String JavaDoc className)
133         throws ClassNotFoundException JavaDoc;
134     
135 }
136
Popular Tags