KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > SystemBundleLoader


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.internal.core;
13
14 import java.io.IOException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.*;
17 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
18 import org.osgi.framework.BundleException;
19
20 /**
21  * The System Bundle's BundleLoader. This BundleLoader is used by ImportClassLoaders
22  * to load a resource that is exported by the System Bundle.
23  */

24 public class SystemBundleLoader extends BundleLoader {
25     public static final String JavaDoc EQUINOX_EE = "x-equinox-ee"; //$NON-NLS-1$
26
ClassLoader JavaDoc classLoader;
27     private HashSet eePackages;
28
29     /**
30      * @param bundle The system bundle.
31      * @param proxy The BundleLoaderProxy for the system bundle
32      * @throws BundleException On any error.
33      */

34     protected SystemBundleLoader(BundleHost bundle, BundleLoaderProxy proxy) throws BundleException {
35         super(bundle, proxy);
36         ExportPackageDescription[] exports = proxy.getBundleDescription().getSelectedExports();
37         if (exports != null && exports.length > 0) {
38             eePackages = new HashSet(exports.length);
39             for (int i = 0; i < exports.length; i++)
40                 if (((Integer JavaDoc) exports[i].getDirective(EQUINOX_EE)).intValue() >= 0)
41                     eePackages.add(exports[i].getName());
42         }
43         this.classLoader = getClass().getClassLoader();
44     }
45
46     /**
47      * The ClassLoader that loads OSGi framework classes is used to find the class.
48      */

49     public Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
50         return classLoader.loadClass(name);
51     }
52
53     /**
54      * This method will always return null.
55      */

56     public String JavaDoc findLibrary(String JavaDoc name) {
57         return null;
58     }
59
60     /**
61      * The ClassLoader that loads OSGi framework classes is used to find the class.
62      */

63     Class JavaDoc findLocalClass(String JavaDoc name) {
64         Class JavaDoc clazz = null;
65         try {
66             clazz = classLoader.loadClass(name);
67         } catch (ClassNotFoundException JavaDoc e) {
68             // Do nothing, will return null
69
}
70         return clazz;
71     }
72
73     /**
74      * The ClassLoader that loads OSGi framework classes is used to find the resource.
75      */

76     URL JavaDoc findLocalResource(String JavaDoc name) {
77         return classLoader.getResource(name);
78     }
79
80     /**
81      * The ClassLoader that loads OSGi framework classes is used to find the resource.
82      */

83     Enumeration findLocalResources(String JavaDoc name) {
84         try {
85             return classLoader.getResources(name);
86         } catch (IOException JavaDoc e) {
87             return null;
88         }
89     }
90
91     /**
92      * The ClassLoader that loads OSGi framework classes is used to find the resource.
93      */

94     public URL JavaDoc findResource(String JavaDoc name) {
95         return classLoader.getResource(name);
96     }
97
98     /**
99      * The ClassLoader that loads OSGi framework classes is used to find the resource.
100      */

101     public Enumeration findResources(String JavaDoc name) throws IOException JavaDoc {
102         return classLoader.getResources(name);
103     }
104
105     /**
106      * Do nothing on a close.
107      */

108     protected void close() {
109         // Do nothing.
110
}
111
112     public boolean isEEPackage(String JavaDoc pkgName) {
113         return eePackages.contains(pkgName);
114     }
115 }
116
Popular Tags