Skip to main content
summaryrefslogtreecommitdiffstats
blob: 986dc388f34c5624d49328c3d3ef8475e0f2d9cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.osgi.framework.internal.core;

import java.io.IOException;
import java.net.URL;
import java.util.*;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.osgi.framework.BundleException;

/**
 * The System Bundle's BundleLoader.  This BundleLoader is used by ImportClassLoaders
 * to load a resource that is exported by the System Bundle.
 */
public class SystemBundleLoader extends BundleLoader {
	public static final String EQUINOX_EE = "x-equinox-ee"; //$NON-NLS-1$
	ClassLoader classLoader;
	private HashSet eePackages;

	/**
	 * @param bundle The system bundle.
	 * @param proxy The BundleLoaderProxy for the system bundle
	 * @throws BundleException On any error.
	 */
	protected SystemBundleLoader(BundleHost bundle, BundleLoaderProxy proxy) throws BundleException {
		super(bundle, proxy);
		ExportPackageDescription[] exports = proxy.getBundleDescription().getSelectedExports();
		if (exports != null && exports.length > 0) {
			eePackages = new HashSet(exports.length);
			for (int i = 0; i < exports.length; i++)
				if (((Integer) exports[i].getDirective(EQUINOX_EE)).intValue() >= 0)
					eePackages.add(exports[i].getName());
		}
		this.classLoader = getClass().getClassLoader();
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the class.
	 */
	public Class findClass(String name) throws ClassNotFoundException {
		return classLoader.loadClass(name);
	}

	/**
	 * This method will always return null.
	 */
	public String findLibrary(String name) {
		return null;
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the class. 
	 */
	Class findLocalClass(String name) {
		Class clazz = null;
		try {
			clazz = classLoader.loadClass(name);
		} catch (ClassNotFoundException e) {
			// Do nothing, will return null
		}
		return clazz;
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the resource.
	 */
	URL findLocalResource(String name) {
		return classLoader.getResource(name);
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the resource.
	 */
	Enumeration findLocalResources(String name) {
		try {
			return classLoader.getResources(name);
		} catch (IOException e) {
			return null;
		}
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the resource.
	 */
	public URL findResource(String name) {
		return classLoader.getResource(name);
	}

	/**
	 * The ClassLoader that loads OSGi framework classes is used to find the resource.
	 */
	public Enumeration findResources(String name) throws IOException {
		return classLoader.getResources(name);
	}

	/**
	 * Do nothing on a close.
	 */
	protected void close() {
		// Do nothing.
	}

	public boolean isEEPackage(String pkgName) {
		return eePackages.contains(pkgName);
	}
}

Back to the top