|
Added
Link Here
|
| 1 |
package org.eclipse.pde.internal.core.bundle; |
| 2 |
|
| 3 |
import java.util.HashMap; |
| 4 |
import java.util.Map; |
| 5 |
|
| 6 |
import org.eclipse.pde.core.plugin.IFragment; |
| 7 |
import org.eclipse.pde.core.plugin.IPlugin; |
| 8 |
import org.eclipse.pde.core.plugin.IPluginBase; |
| 9 |
import org.eclipse.pde.core.plugin.IPluginManifestInfo; |
| 10 |
import org.eclipse.pde.core.plugin.IPluginObject; |
| 11 |
import org.eclipse.pde.internal.core.ibundle.IBundle; |
| 12 |
import org.eclipse.pde.core.IIdentifiable; |
| 13 |
import org.eclipse.pde.core.IModelChangeProvider; |
| 14 |
import org.osgi.framework.Constants; |
| 15 |
|
| 16 |
/** |
| 17 |
* Implementation of Manifest information for the plug-in model. |
| 18 |
* |
| 19 |
* TODO: Consider refactoring existing models to utilise this class as the point |
| 20 |
* that changes the manifest. |
| 21 |
* |
| 22 |
* @author Les Jones |
| 23 |
*/ |
| 24 |
public class BundleManifestInfo implements IPluginManifestInfo { |
| 25 |
|
| 26 |
/** Underlying bundle representation */ |
| 27 |
private IBundle fBundle = null; |
| 28 |
|
| 29 |
/** Object interested in change events */ |
| 30 |
private IModelChangeProvider fModelChangeProvider = null; |
| 31 |
|
| 32 |
/** |
| 33 |
* The header event type map links a header with the event that needs to be |
| 34 |
* fired to indicate that the value has been updated. |
| 35 |
*/ |
| 36 |
private Map headerEventTypeMap = null; |
| 37 |
|
| 38 |
/** |
| 39 |
* Create a new manifest info instance using the specified bundle. |
| 40 |
* |
| 41 |
* @param bundle |
| 42 |
* Bundle to refer to. |
| 43 |
*/ |
| 44 |
public BundleManifestInfo(IBundle bundle) { |
| 45 |
|
| 46 |
this(bundle, null); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Create a new manifest info instance using the specified bundle, providing model |
| 52 |
* update information to the specified model change provider. |
| 53 |
* |
| 54 |
* @param bundle |
| 55 |
* Bundle to refer to. |
| 56 |
* @param modelChangeProvider |
| 57 |
* object where model changes should be fired |
| 58 |
*/ |
| 59 |
public BundleManifestInfo(IBundle bundle, |
| 60 |
IModelChangeProvider modelChangeProvider) { |
| 61 |
|
| 62 |
fBundle = bundle; |
| 63 |
|
| 64 |
initializeManagedHeaders(); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Initialize the bundle headers that are known to be managed. |
| 69 |
* i.e. those that require a model update. |
| 70 |
*/ |
| 71 |
private void initializeManagedHeaders() { |
| 72 |
|
| 73 |
headerEventTypeMap = new HashMap(); |
| 74 |
|
| 75 |
headerEventTypeMap.put(Constants.BUNDLE_ACTIVATOR, IPlugin.P_CLASS_NAME); |
| 76 |
headerEventTypeMap.put(Constants.BUNDLE_VERSION, IPluginBase.P_VERSION); |
| 77 |
headerEventTypeMap.put(Constants.BUNDLE_NAME, IPluginObject.P_NAME); |
| 78 |
headerEventTypeMap.put(Constants.BUNDLE_VENDOR, IPluginBase.P_PROVIDER); |
| 79 |
headerEventTypeMap.put(Constants.FRAGMENT_HOST, IFragment.P_PLUGIN_ID); |
| 80 |
headerEventTypeMap.put(Constants.BUNDLE_SYMBOLICNAME, IIdentifiable.P_ID); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Get the value of a generic manifest header. |
| 85 |
* @param name The name of the header |
| 86 |
* @return The value of the header |
| 87 |
* @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String) |
| 88 |
*/ |
| 89 |
public String getHeader(String name) { |
| 90 |
|
| 91 |
if (fBundle == null) { |
| 92 |
return null; |
| 93 |
} |
| 94 |
|
| 95 |
return fBundle.getHeader(name); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Set the value of a generic manifest header. |
| 100 |
* @param name The name of the header |
| 101 |
* @param value The value of the header |
| 102 |
* @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String) |
| 103 |
*/ |
| 104 |
public void setHeader(String name, String value) { |
| 105 |
|
| 106 |
if (fBundle == null) { |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
String oldValue = fBundle.getHeader(name); |
| 111 |
|
| 112 |
fBundle.setHeader(name, value); |
| 113 |
|
| 114 |
fireHeaderUpdated(name, oldValue, value); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Fire an event to indicate to a model that a header has been updated. Two |
| 119 |
* types of event can be fired, one where the property name is the name of |
| 120 |
* the header, and another where the name is mapped from the header, e.g. |
| 121 |
* mapping Bundle-Name (Constants.BUNDLE_NAME) to name |
| 122 |
* (IPluginObject.P_NAME) |
| 123 |
* |
| 124 |
* If no model change provider is associated with this manifest model, this |
| 125 |
* method does nothing. |
| 126 |
* |
| 127 |
* TODO: Check whether this is actually required - the Bundle |
| 128 |
* implementations appear to fire their own events. |
| 129 |
* |
| 130 |
* @param header The name of the header to be updated |
| 131 |
* @param oldValue The old value of the header |
| 132 |
* @param newValue The new value of the header |
| 133 |
*/ |
| 134 |
private void fireHeaderUpdated(String header, String oldValue, String newValue) { |
| 135 |
|
| 136 |
if (fModelChangeProvider == null) { |
| 137 |
// early exit if no change provider |
| 138 |
return; |
| 139 |
} |
| 140 |
|
| 141 |
// Fire an event mapped from the header name |
| 142 |
if (headerEventTypeMap.containsKey(header)) { |
| 143 |
String eventType = (String) headerEventTypeMap.get(header); |
| 144 |
|
| 145 |
fModelChangeProvider.fireModelObjectChanged(this, eventType, |
| 146 |
oldValue, newValue); |
| 147 |
} |
| 148 |
|
| 149 |
// Fire the actual event for the header |
| 150 |
fModelChangeProvider.fireModelObjectChanged(this, header, oldValue, |
| 151 |
newValue); |
| 152 |
} |
| 153 |
} |