KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > adaptor > BundleClassLoader


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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
12 package org.eclipse.osgi.framework.adaptor;
13
14 import java.io.IOException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.security.ProtectionDomain JavaDoc;
17 import java.util.Enumeration JavaDoc;
18
19 /**
20  * The BundleClassLoader interface is used by the Framework to load local
21  * classes and resources from a Bundle. Classes that implement this
22  * interface must extend java.lang.ClassLoader, either directly or by extending
23  * a subclass of java.lang.ClassLoader.<p>
24  *
25  * ClassLoaders that implement the <code>BundleClassLoader</code> interface
26  * must use a <code>ClassLoaderDelegate</code> to delegate all class, resource
27  * and native library lookups.
28  * <p>
29  * Clients may implement this interface.
30  * </p>
31  * @since 3.1
32  * @see org.eclipse.osgi.framework.adaptor.BundleData#createClassLoader(ClassLoaderDelegate, BundleProtectionDomain, String[])
33  */

34 public interface BundleClassLoader /*extends ClassLoader*/{
35
36     /**
37      * Initializes the ClassLoader. This is called after all currently resolved fragment
38      * bundles have been attached to the BundleClassLoader by the Framework.
39      */

40     public void initialize();
41
42     /**
43      * Finds a local resource in the BundleClassLoader without
44      * consulting the delegate.
45      * @param resource the resource path to find.
46      * @return a URL to the resource or null if the resource does not exist.
47      */

48     public URL JavaDoc findLocalResource(String JavaDoc resource);
49
50     /**
51      * Finds all local resources in the BundleClassLoader with the specified
52      * path without consulting the delegate.
53      * @param resource the resource path to find.
54      * @return An Enumeration of all resources found or null if the resource.
55      * does not exist.
56      */

57     public Enumeration JavaDoc findLocalResources(String JavaDoc resource);
58
59     /**
60      * Finds a local class in the BundleClassLoader without
61      * consulting the delegate.
62      * @param classname the classname to find.
63      * @return The class object found.
64      * @throws ClassNotFoundException if the classname does not exist locally.
65      */

66     public Class JavaDoc findLocalClass(String JavaDoc classname) throws ClassNotFoundException JavaDoc;
67
68     /**
69      * This method will first search the parent class loader for the resource;
70      * That failing, this method will invoke
71      * {@link ClassLoaderDelegate#findResource(String)} to find the resource.
72      * @param name the resource path to get.
73      * @return a URL for the resource or <code>null</code> if the resource is not found.
74      */

75     public URL JavaDoc getResource(String JavaDoc name);
76
77     /**
78      * This method will first search the parent class loader for the resource;
79      * That failing, this method will invoke
80      * {@link ClassLoaderDelegate#findResource(String)} to find the resource.
81      * @param name the resource path to get.
82      * @return an Enumeration of URL objects for the resource or <code>null</code> if the resource is not found.
83      */

84     public Enumeration JavaDoc getResources(String JavaDoc name) throws IOException JavaDoc;
85
86     /**
87      * This method will first search the parent class loader for the class;
88      * That failing, this method will invoke
89      * {@link ClassLoaderDelegate#findClass(String)} to find the resource.
90      * @param name the class name to load.
91      * @return the Class.
92      * @throws ClassNotFoundException
93      */

94     public Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc;
95
96     /**
97      * Closes this class loader. After this method is called
98      * loadClass will always throw ClassNotFoundException,
99      * getResource, getResourceAsStream, getResources and will
100      * return null.
101      *
102      */

103     public void close();
104
105     /**
106      * Attaches the BundleData for a fragment to this BundleClassLoader.
107      * The Fragment BundleData resources must be appended to the end of
108      * this BundleClassLoader's classpath. Fragment BundleData resources
109      * must be searched ordered by Bundle ID's.
110      * @param bundledata The BundleData of the fragment.
111      * @param domain The ProtectionDomain of the resources of the fragment.
112      * Any classes loaded from the fragment's BundleData must belong to this
113      * ProtectionDomain.
114      * @param classpath An array of Bundle-ClassPath entries to
115      * use for loading classes and resources. This is specified by the
116      * Bundle-ClassPath manifest entry of the fragment.
117      */

118     public void attachFragment(BundleData bundledata, ProtectionDomain JavaDoc domain, String JavaDoc[] classpath);
119
120     /**
121      * Returns the ClassLoaderDelegate used by this BundleClassLoader
122      * @return the ClassLoaderDelegate used by this BundleClassLoader
123      */

124     public ClassLoaderDelegate getDelegate();
125
126     /**
127      * Returns the parent classloader used by this BundleClassLoader
128      * @return the parent classloader used by this BundleClassLoader
129      */

130     public ClassLoader JavaDoc getParent();
131 }
132
Popular Tags