1 11 package org.eclipse.pde.internal.core.plugin; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.osgi.service.resolver.BundleDescription; 17 import org.eclipse.osgi.service.resolver.HostSpecification; 18 import org.eclipse.osgi.service.resolver.VersionRange; 19 import org.eclipse.pde.core.plugin.IFragment; 20 import org.eclipse.pde.core.plugin.IMatchRules; 21 import org.eclipse.pde.core.plugin.IPluginExtension; 22 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 23 import org.eclipse.pde.internal.core.PDEState; 24 import org.w3c.dom.Node ; 25 26 public class Fragment extends PluginBase implements IFragment { 27 private static final long serialVersionUID = 1L; 28 29 private String fPluginId = ""; 31 private String fPluginVersion = ""; 33 private int fMatchRule = IMatchRules.NONE; 34 35 private boolean fPatch; 36 37 public String getPluginId() { 38 return fPluginId; 39 } 40 41 public String getPluginVersion() { 42 return fPluginVersion; 43 } 44 45 public int getRule() { 46 return fMatchRule; 47 } 48 49 protected boolean hasRequiredAttributes() { 50 if (fPluginId == null || fPluginVersion == null) 51 return false; 52 return super.hasRequiredAttributes(); 53 } 54 55 void load(BundleDescription bundleDescription, PDEState state) { 56 HostSpecification host = bundleDescription.getHost(); 57 fPluginId = host.getName(); 58 VersionRange versionRange = host.getVersionRange(); 59 if (versionRange != null) { 60 fPluginVersion = versionRange.getMinimum() != null ? versionRange 61 .getMinimum().toString() 62 : null; 63 fMatchRule = PluginBase.getMatchRule(versionRange); 64 } 65 fPatch = state.isPatchFragment(bundleDescription.getBundleId()); 66 super.load(bundleDescription, state); 67 } 68 69 void load(Node node, String schemaVersion) { 70 fPluginId = getNodeAttribute(node, "plugin-id"); fPluginVersion = getNodeAttribute(node, "plugin-version"); String match = getNodeAttribute(node, "match"); if (match != null) { 74 String [] table = IMatchRules.RULE_NAME_TABLE; 75 for (int i = 0; i < table.length; i++) { 76 if (match.equalsIgnoreCase(table[i])) { 77 fMatchRule = i; 78 break; 79 } 80 } 81 } 82 super.load(node, schemaVersion); 83 } 84 85 public void reset() { 86 fPluginId = ""; fPluginVersion = ""; fMatchRule = IMatchRules.NONE; 89 super.reset(); 90 } 91 92 public void setPluginId(String newPluginId) throws CoreException { 93 ensureModelEditable(); 94 String oldValue = this.fPluginId; 95 fPluginId = newPluginId; 96 firePropertyChanged(P_PLUGIN_ID, oldValue, fPluginId); 97 } 98 99 public void setPluginVersion(String newPluginVersion) throws CoreException { 100 ensureModelEditable(); 101 String oldValue = this.fPluginVersion; 102 fPluginVersion = newPluginVersion; 103 firePropertyChanged(P_PLUGIN_VERSION, oldValue, fPluginVersion); 104 } 105 106 public void setRule(int rule) throws CoreException { 107 ensureModelEditable(); 108 Integer oldValue = new Integer (this.fMatchRule); 109 fMatchRule = rule; 110 firePropertyChanged(P_RULE, oldValue, new Integer (rule)); 111 } 112 113 public void restoreProperty(String name, Object oldValue, Object newValue) 114 throws CoreException { 115 if (name.equals(P_PLUGIN_ID)) { 116 setPluginId(newValue != null ? newValue.toString() : null); 117 return; 118 } 119 if (name.equals(P_PLUGIN_VERSION)) { 120 setPluginVersion(newValue != null ? newValue.toString() : null); 121 return; 122 } 123 if (name.equals(P_RULE)) { 124 setRule(((Integer ) newValue).intValue()); 125 return; 126 } 127 super.restoreProperty(name, oldValue, newValue); 128 } 129 130 public void write(String indent, PrintWriter writer) { 131 writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (getSchemaVersion() != null) { 133 writer.println("<?eclipse version=\"" + getSchemaVersion() + "\"?>"); } 135 writer.print("<fragment"); if (getId() != null) { 137 writer.println(); 138 writer.print(" id=\"" + getId() + "\""); } 140 if (getName() != null) { 141 writer.println(); 142 writer.print(" name=\"" + getWritableString(getName()) + "\""); } 144 if (getVersion() != null) { 145 writer.println(); 146 writer.print(" version=\"" + getVersion() + "\""); } 148 if (getProviderName() != null) { 149 writer.println(); 150 writer.print(" provider-name=\"" + getWritableString(getProviderName()) + "\""); } 152 String pid = getPluginId(); 153 if (pid != null && pid.length() > 0) { 154 writer.println(); 155 writer.print(" plugin-id=\"" + getPluginId() + "\""); } 157 String pver = getPluginVersion(); 158 if (pver != null && pver.length() > 0) { 159 writer.println(); 160 writer.print(" plugin-version=\"" + getPluginVersion() + "\""); } 162 if (getRule() != IMatchRules.NONE) { 163 writer.println(); 164 writer.print(" match=\"" + IMatchRules.RULE_NAME_TABLE[getRule()] + "\""); } 166 writer.println(">"); writer.println(); 168 169 String firstIndent = " "; 171 Object [] children = getLibraries(); 173 if (children.length > 0) { 174 writeChildren(firstIndent, "runtime", children, writer); writer.println(); 176 } 177 178 children = getImports(); 180 if (children.length > 0) { 181 writeChildren(firstIndent, "requires", children, writer); writer.println(); 183 } 184 185 children = getExtensionPoints(); 186 if (children.length > 0) { 187 for (int i = 0; i < children.length; i++) { 188 ((IPluginExtensionPoint) children[i]).write(firstIndent, writer); 189 } 190 writer.println(); 191 } 192 193 children = getExtensions(); 195 for (int i = 0; i < children.length; i++) { 196 ((IPluginExtension) children[i]).write(firstIndent, writer); 197 } 198 writer.println("</fragment>"); } 200 201 public boolean isPatch() { 202 return fPatch; 203 } 204 } 205 | Popular Tags |