1 11 package org.eclipse.core.runtime.internal.adaptor; 12 13 import java.util.Dictionary ; 14 import java.util.Enumeration ; 15 import org.eclipse.osgi.framework.adaptor.BundleData; 16 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor; 17 import org.eclipse.osgi.framework.internal.core.Constants; 18 import org.eclipse.osgi.framework.log.FrameworkLogEntry; 19 import org.eclipse.osgi.util.NLS; 20 import org.osgi.framework.*; 21 22 25 public class CachedManifest extends Dictionary { 26 27 private Dictionary manifest = null; 28 private EclipseStorageHook storageHook; 29 30 public CachedManifest(EclipseStorageHook storageHook) { 31 this.storageHook = storageHook; 32 } 33 34 public Dictionary getManifest() { 35 if (manifest == null) 36 try { 37 manifest = storageHook.createCachedManifest(true); 38 } catch (BundleException e) { 39 final String message = NLS.bind(EclipseAdaptorMsg.ECLIPSE_CACHEDMANIFEST_UNEXPECTED_EXCEPTION, storageHook.getBaseData().getLocation()); 40 FrameworkLogEntry entry = new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, FrameworkLogEntry.ERROR, 0, message, 0, e, null); 41 storageHook.getAdaptor().getFrameworkLog().log(entry); 42 return null; 43 } 44 return manifest; 45 } 46 47 public int size() { 48 return getManifest().size(); 50 } 51 52 public boolean isEmpty() { 53 return size() == 0; 54 } 55 56 public Enumeration elements() { 57 return getManifest().elements(); 59 } 60 61 public Enumeration keys() { 62 return getManifest().keys(); 64 } 65 66 public Object get(Object key) { 67 if (manifest != null) 68 return manifest.get(key); 69 String keyString = (String ) key; 70 if (Constants.BUNDLE_VERSION.equalsIgnoreCase(keyString)) { 71 Version result = storageHook.getBaseData().getVersion(); 72 return result == null ? null : result.toString(); 73 } 74 if (Constants.PLUGIN_CLASS.equalsIgnoreCase(keyString)) 75 return storageHook.getPluginClass(); 76 if (Constants.BUNDLE_SYMBOLICNAME.equalsIgnoreCase(keyString)) { 77 if ((storageHook.getBaseData().getType() & BundleData.TYPE_SINGLETON) == 0) 78 return storageHook.getBaseData().getSymbolicName(); 79 return storageHook.getBaseData().getSymbolicName() + ';' + Constants.SINGLETON_DIRECTIVE + ":=true"; } 81 if (Constants.BUDDY_LOADER.equalsIgnoreCase(keyString)) 82 return storageHook.getBuddyList(); 83 if (Constants.REGISTERED_POLICY.equalsIgnoreCase(keyString)) 84 return storageHook.getRegisteredBuddyList(); 85 if (Constants.BUNDLE_ACTIVATOR.equalsIgnoreCase(keyString)) 86 return storageHook.getBaseData().getActivator(); 87 if (Constants.ECLIPSE_LAZYSTART.equals(keyString) || Constants.ECLIPSE_AUTOSTART.equals(keyString)) { 88 if (!storageHook.isAutoStartable()) 89 return null; 90 if (storageHook.getLazyStartExcludes() == null) 91 return Boolean.TRUE.toString(); 92 StringBuffer result = new StringBuffer (Boolean.TRUE.toString()); 93 result.append(";").append(Constants.ECLIPSE_LAZYSTART_EXCEPTIONS).append("=\""); String [] exceptions = storageHook.getLazyStartExcludes(); 95 for (int i = 0; i < exceptions.length; i++) { 96 if (i > 0) 97 result.append(","); result.append(exceptions[i]); 99 } 100 result.append("\""); return result.toString(); 102 } 103 Dictionary result = getManifest(); 104 return result == null ? null : result.get(key); 105 } 106 107 public Object remove(Object key) { 108 return getManifest().remove(key); 110 } 111 112 public Object put(Object key, Object value) { 113 return getManifest().put(key, value); 115 } 116 117 } 118
| Popular Tags
|