KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > internal > adaptor > ClasspathManifest


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.core.runtime.internal.adaptor;
13
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.util.jar.Manifest JavaDoc;
17 import org.eclipse.osgi.baseadaptor.BaseData;
18 import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
19 import org.eclipse.osgi.baseadaptor.loader.*;
20 import org.eclipse.osgi.framework.util.KeyedElement;
21
22 public class ClasspathManifest implements KeyedElement {
23     public static final Object JavaDoc KEY = new Object JavaDoc();
24     public static final int HASHCODE = KEY.hashCode();
25
26     private Manifest JavaDoc manifest;
27     private boolean initialized = false;
28
29     public int getKeyHashCode() {
30         return HASHCODE;
31     }
32
33     public boolean compare(KeyedElement other) {
34         return other.getKey() == KEY;
35     }
36
37     public Object JavaDoc getKey() {
38         return KEY;
39     }
40
41     public Manifest JavaDoc getManifest(ClasspathEntry cpEntry, ClasspathManager loader) {
42         if (initialized)
43             return manifest;
44         if (!hasPackageInfo(cpEntry, loader)) {
45             initialized = true;
46             manifest = null;
47             return manifest;
48         }
49         BundleEntry mfEntry = cpEntry.getBundleFile().getEntry(org.eclipse.osgi.framework.internal.core.Constants.OSGI_BUNDLE_MANIFEST);
50         if (mfEntry != null)
51             try {
52                 InputStream JavaDoc manIn = mfEntry.getInputStream();
53                 manifest = new Manifest JavaDoc(manIn);
54                 manIn.close();
55             } catch (IOException JavaDoc e) {
56                 // do nothing
57
}
58         initialized = true;
59         return manifest;
60     }
61
62     private boolean hasPackageInfo(ClasspathEntry cpEntry, ClasspathManager loader) {
63         BaseData bundledata = null;
64         if (cpEntry.getBundleFile() == loader.getBaseData().getBundleFile())
65             bundledata = loader.getBaseData();
66         if (bundledata == null) {
67             FragmentClasspath[] fragCPs = loader.getFragmentClasspaths();
68             if (fragCPs != null)
69                 for (int i = 0; i < fragCPs.length; i++)
70                     if (cpEntry.getBundleFile() == fragCPs[i].getBundleData().getBundleFile()) {
71                         bundledata = fragCPs[i].getBundleData();
72                         break;
73                     }
74         }
75         if (bundledata == null)
76             return true;
77         EclipseStorageHook storageHook = (EclipseStorageHook) bundledata.getStorageHook(EclipseStorageHook.KEY);
78         return storageHook == null ? true : storageHook.hasPackageInfo();
79     }
80
81 }
82
Popular Tags