KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > adaptor > CachedManifest


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime.adaptor;
12
13 import java.util.Dictionary JavaDoc;
14 import java.util.Enumeration JavaDoc;
15 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
16 import org.eclipse.osgi.framework.log.FrameworkLogEntry;
17 import org.eclipse.osgi.service.resolver.Version;
18 import org.osgi.framework.BundleException;
19 import org.osgi.framework.Constants;
20
21 /**
22  * Internal class.
23  */

24 public class CachedManifest extends Dictionary JavaDoc {
25
26     Dictionary JavaDoc manifest = null;
27     EclipseBundleData bundledata;
28
29     public CachedManifest(EclipseBundleData bundledata) {
30         this.bundledata = bundledata;
31     }
32
33     private Dictionary JavaDoc getManifest() {
34         if (manifest == null)
35             try {
36                 manifest = bundledata.loadManifest();
37             } catch (BundleException e) {
38                 final String JavaDoc message = EclipseAdaptorMsg.formatter.getString("ECLIPSE_CACHEDMANIFEST_UNEXPECTED_EXCEPTION", bundledata.getLocation()); //$NON-NLS-1$
39
FrameworkLogEntry entry = new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, message, 0, e, null);
40                 EclipseAdaptor.getDefault().getFrameworkLog().log(entry);
41                 return null;
42             }
43         return manifest;
44     }
45
46     public int size() {
47         //TODO: getManifest may return null
48
return getManifest().size();
49     }
50
51     public boolean isEmpty() {
52         return size() == 0;
53     }
54
55     public Enumeration JavaDoc elements() {
56         //TODO: getManifest may return null
57
return getManifest().elements();
58     }
59
60     public Enumeration JavaDoc keys() {
61         //TODO: getManifest may return null
62
return getManifest().keys();
63     }
64
65     public Object JavaDoc get(Object JavaDoc key) {
66         String JavaDoc keyString = (String JavaDoc) key;
67         if (Constants.BUNDLE_VERSION.equalsIgnoreCase(keyString)) {
68             Version result = bundledata.getVersion();
69             return result == null ? null : result.toString();
70         }
71         if (EclipseAdaptor.PLUGIN_CLASS.equalsIgnoreCase(keyString))
72             return bundledata.getPluginClass();
73         if (Constants.BUNDLE_SYMBOLICNAME.equalsIgnoreCase(keyString))
74             return bundledata.getSymbolicName();
75         Dictionary JavaDoc result = getManifest();
76         return result == null ? null : result.get(key);
77     }
78
79     public Object JavaDoc remove(Object JavaDoc key) {
80         //TODO: getManifest may return null
81
return getManifest().remove(key);
82     }
83
84     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
85         //TODO: getManifest may return null
86
return getManifest().put(key, value);
87     }
88
89 }
Popular Tags