KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > protocol > bundleresource > Handler


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.protocol.bundleresource;
13
14 import java.io.FileNotFoundException JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.Enumeration JavaDoc;
18 import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
19 import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
20 import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
21 import org.eclipse.osgi.framework.internal.core.AbstractBundle;
22 import org.eclipse.osgi.framework.internal.core.BundleResourceHandler;
23
24 /**
25  * URLStreamHandler the bundleresource protocol.
26  */

27
28 public class Handler extends BundleResourceHandler {
29
30     /**
31      * Constructor for a bundle protocol resource URLStreamHandler.
32      */

33     public Handler() {
34         super();
35     }
36
37     public Handler(BundleEntry bundleEntry) {
38         super(bundleEntry);
39     }
40
41     protected BundleEntry findBundleEntry(URL JavaDoc url, AbstractBundle bundle) throws IOException JavaDoc {
42         BaseClassLoader classloader = getBundleClassLoader(bundle);
43         if (classloader == null)
44             throw new FileNotFoundException JavaDoc(url.getPath());
45         ClasspathManager cpManager = classloader.getClasspathManager();
46         int index = url.getPort();
47         BundleEntry entry = null;
48         if (index == 0) {
49             entry = cpManager.findLocalEntry(url.getPath());
50         } else {
51             Enumeration JavaDoc entries = cpManager.findLocalEntries(url.getPath());
52             if (entries != null)
53                 for (int i = 0; entries.hasMoreElements() && i <= index; i++)
54                     entry = (BundleEntry) entries.nextElement();
55         }
56         if (entry == null)
57             throw new FileNotFoundException JavaDoc(url.getPath());
58         return entry;
59     }
60
61 }
62
Popular Tags