Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6ea13f76ae89a177d2b3e5b3f9d973b6079ce5e9 (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
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.osgi.framework.internal.protocol.bundleresource;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.eclipse.osgi.framework.adaptor.core.*;
import org.eclipse.osgi.framework.adaptor.core.BundleEntry;
import org.eclipse.osgi.framework.internal.core.*;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;

/**
 * URLStreamHandler the bundleresource protocol.
 */

public class Handler extends BundleResourceHandler {

	/**
	 * Constructor for a bundle protocol resource URLStreamHandler.
	 */
	public Handler() {
		super();
	}

	public Handler(BundleEntry bundleEntry) {
		super(bundleEntry);
	}

	protected BundleEntry findBundleEntry(URL url, AbstractBundle bundle) throws IOException {
		AbstractClassLoader cl = (AbstractClassLoader) getBundleClassLoader(bundle);
		if (cl== null)
			throw new FileNotFoundException(url.getPath());
		int index = url.getPort();
		BundleEntry entry = null;
		if (index == 0) {
			entry = (BundleEntry) cl.findLocalObject(url.getPath());
		}
		else {
			Enumeration entries = cl.findLocalObjects(url.getPath());
			if (entries != null)
				for (int i = 0; entries.hasMoreElements() && i <= index; i++)
					entry = (BundleEntry) entries.nextElement();
		}
		if (entry == null)
			throw new FileNotFoundException(url.getPath());
		return entry;
	}

}

Back to the top