KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > PluginClassLoader


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2005 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin;
20
21 import java.net.URL JavaDoc;
22 import java.net.URLClassLoader JavaDoc;
23 import java.net.URLStreamHandlerFactory JavaDoc;
24
25 import org.java.plugin.registry.PluginDescriptor;
26
27 /**
28  * Extension to Java class loader API. One instance of this class should be
29  * created by {@link org.java.plugin.PluginManager plug-in manager} for every
30  * available plug-in.
31  *
32  * @version $Id: PluginClassLoader.java,v 1.11 2005/07/23 09:30:07 ddimon Exp $
33  */

34 public abstract class PluginClassLoader extends URLClassLoader JavaDoc {
35     private final PluginManager manager;
36     private final PluginDescriptor descriptor;
37
38     /**
39      * @param aManager plug-in manager
40      * @param descr plug-in descriptor
41      * @param urls resources "managed" by this class loader
42      * @param parent parent class loader
43      * @param factory URL stream handler factory
44      * @see URLClassLoader#URLClassLoader(java.net.URL[], java.lang.ClassLoader,
45      * java.net.URLStreamHandlerFactory)
46      */

47     protected PluginClassLoader(final PluginManager aManager,
48             final PluginDescriptor descr, final URL JavaDoc[] urls,
49             final ClassLoader JavaDoc parent, final URLStreamHandlerFactory JavaDoc factory) {
50         super(urls, parent, factory);
51         manager = aManager;
52         descriptor = descr;
53     }
54
55     /**
56      * @param aManager plug-in manager
57      * @param descr plug-in descriptor
58      * @param urls resources "managed" by this class loader
59      * @param parent parent class loader
60      * @see URLClassLoader#URLClassLoader(java.net.URL[], java.lang.ClassLoader)
61      */

62     protected PluginClassLoader(final PluginManager aManager,
63             final PluginDescriptor descr, final URL JavaDoc[] urls,
64             final ClassLoader JavaDoc parent) {
65         super(urls, parent);
66         manager = aManager;
67         descriptor = descr;
68     }
69
70     /**
71      * @param aManager plug-in manager
72      * @param descr plug-in descriptor
73      * @param urls resources "managed" by this class loader
74      * @see URLClassLoader#URLClassLoader(java.net.URL[])
75      */

76     protected PluginClassLoader(final PluginManager aManager,
77             final PluginDescriptor descr, final URL JavaDoc[] urls) {
78         super(urls);
79         manager = aManager;
80         descriptor = descr;
81     }
82     
83     /**
84      * @return returns the plug-in manager
85      */

86     public PluginManager getPluginManager() {
87         return manager;
88     }
89     
90     /**
91      * @return returns the plug-in descriptor
92      */

93     public PluginDescriptor getPluginDescriptor() {
94         return descriptor;
95     }
96     
97     /**
98      * Should release all resources acquired by this class loader instance.
99      */

100     protected abstract void dispose();
101     
102     /**
103      * Registry data change notification.
104      */

105     protected abstract void pluginsSetChanged();
106
107     /**
108      * @see java.lang.Object#toString()
109      */

110     public String JavaDoc toString() {
111         return "{PluginClassLoader: uid=" //$NON-NLS-1$
112
+ System.identityHashCode(this) + "; " //$NON-NLS-1$
113
+ descriptor + "}"; //$NON-NLS-1$
114
}
115 }
116
Popular Tags