KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > tomcat > internal > WebAppClassLoader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.tomcat.internal;
12
13 import java.net.*;
14
15 import org.eclipse.help.internal.appserver.*;
16
17 /**
18  * A class loader that combines a plugin class loader with the tomcat class
19  * loader
20  */

21 public class WebAppClassLoader extends URLClassLoader {
22     private ClassLoader JavaDoc pluginLoader;
23     private PluginClassLoaderWrapper tomcatPluginLoader;
24
25     public WebAppClassLoader(ClassLoader JavaDoc pluginLoader) {
26         super(new URL[0]);
27         this.pluginLoader = pluginLoader;
28         this.tomcatPluginLoader = new PluginClassLoaderWrapper(
29                 TomcatPlugin.PLUGIN_ID);
30     }
31
32     public Class JavaDoc loadClass(String JavaDoc className) throws ClassNotFoundException JavaDoc {
33         // First check tomcat plugin loader, then the webapp plugin loader
34
Class JavaDoc c = null;
35         try {
36             c = tomcatPluginLoader.loadClass(className);
37         } catch (ClassNotFoundException JavaDoc e) {
38             c = pluginLoader.loadClass(className);
39         } finally {
40         }
41         return c;
42     }
43
44     public URL getResource(String JavaDoc resName) {
45         // First check the plugin loader, then current loader
46
URL u = pluginLoader.getResource(resName);
47         if (u == null)
48             return tomcatPluginLoader.getResource(resName);
49         return u;
50     }
51
52     /**
53      * This is a workaround for the jsp compiler that needs to know the
54      * classpath. NOTE: for now, assume that the web app plugin requires the
55      * tomcat plugin
56      */

57     public URL[] getURLs() {
58         URL[] pluginLoaderURLs;
59         if (pluginLoader instanceof URLClassLoader)
60             pluginLoaderURLs = ((URLClassLoader) pluginLoader).getURLs();
61         else
62             pluginLoaderURLs = new URL[0];
63
64         URL[] tomcatPluginLoaderURLs = tomcatPluginLoader.getURLs();
65
66         URL[] urls = new URL[pluginLoaderURLs.length
67                 + tomcatPluginLoaderURLs.length];
68
69         System.arraycopy(pluginLoaderURLs, 0, urls, 0, pluginLoaderURLs.length);
70         System.arraycopy(tomcatPluginLoaderURLs, 0, urls,
71                 pluginLoaderURLs.length, tomcatPluginLoaderURLs.length);
72         return urls;
73     }
74 }
75
Popular Tags