KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > internal > jsp > jasper > BundleProxyClassLoader


1 /*******************************************************************************
2  * Copyright (c) 2006-2007 Cognos Incorporated, 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  * Cognos Incorporated - initial API and implementation
10  * IBM Corporation - bug fixes and enhancements
11  *******************************************************************************/

12 package org.eclipse.equinox.internal.jsp.jasper;
13
14 import java.io.IOException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.Enumeration JavaDoc;
17
18 import org.osgi.framework.Bundle;
19
20
21 /**
22  * A BundleProxyClassLoader wraps a bundle and uses the various Bundle methods to produce a ClassLoader.
23  */

24 public class BundleProxyClassLoader extends ClassLoader JavaDoc {
25     private Bundle bundle;
26     private ClassLoader JavaDoc parent;
27
28     public BundleProxyClassLoader(Bundle bundle) {
29         this.bundle = bundle;
30     }
31
32     public BundleProxyClassLoader(Bundle bundle, ClassLoader JavaDoc parent) {
33         super(parent);
34         this.parent = parent;
35         this.bundle = bundle;
36     }
37
38     public Enumeration JavaDoc findResources(String JavaDoc name) throws IOException JavaDoc {
39         return bundle.getResources(name);
40     }
41
42     public URL JavaDoc findResource(String JavaDoc name) {
43         return bundle.getResource(name);
44     }
45
46     public Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
47         return bundle.loadClass(name);
48     }
49
50     public URL JavaDoc getResource(String JavaDoc name) {
51         return (parent == null) ? findResource(name) : super.getResource(name);
52     }
53
54     protected Class JavaDoc loadClass(String JavaDoc name, boolean resolve) throws ClassNotFoundException JavaDoc {
55         Class JavaDoc clazz = (parent == null) ? findClass(name) : super.loadClass(name, false);
56         if (resolve)
57             super.resolveClass(clazz);
58
59         return clazz;
60     }
61 }
62
Popular Tags