1 11 package org.eclipse.pde.internal.core.text.plugin; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.pde.core.plugin.IMatchRules; 15 import org.eclipse.pde.core.plugin.IPluginImport; 16 17 public class PluginImportNode extends PluginObjectNode implements IPluginImport { 18 19 private static final long serialVersionUID = 1L; 20 21 public PluginImportNode(String id) { 22 super(); 23 String name = "plugin"; try { 25 if (id == null) 26 id = ""; PluginAttribute attr = new PluginAttribute(); 28 attr.setName(name); 29 attr.setEnclosingElement(this); 30 fAttributes.put(name, attr); 31 attr.setValue(id); 32 } catch (CoreException e) { 33 } 34 } 35 36 public PluginImportNode() { 37 super(); 38 } 39 40 43 public boolean isReexported() { 44 String value = getXMLAttributeValue(P_REEXPORTED); 45 return value != null && value.equals("true"); } 47 50 public boolean isOptional() { 51 String value = getXMLAttributeValue(P_OPTIONAL); 52 return value != null && value.equals("true"); } 54 57 public void setReexported(boolean value) throws CoreException { 58 setXMLAttribute(P_REEXPORTED, value ? "true" : "false"); } 60 63 public void setOptional(boolean value) throws CoreException { 64 setXMLAttribute(P_OPTIONAL, value ? "true" : "false"); } 66 69 public int getMatch() { 70 String match = getXMLAttributeValue(P_MATCH); 71 if (match == null || match.trim().length() == 0) 72 return IMatchRules.NONE; 73 if (match.equals("compatible")) return IMatchRules.COMPATIBLE; 75 if (match.equals("perfect")) return IMatchRules.PERFECT; 77 if (match.equals("equivalent")) return IMatchRules.EQUIVALENT; 79 return IMatchRules.GREATER_OR_EQUAL; 80 } 81 84 public String getVersion() { 85 return getXMLAttributeValue(P_VERSION); 86 } 87 90 public void setMatch(int match) throws CoreException { 91 switch(match) { 92 case IMatchRules.GREATER_OR_EQUAL: 93 setXMLAttribute(P_MATCH, "greaterOrEqual"); break; 95 case IMatchRules.EQUIVALENT: 96 setXMLAttribute(P_MATCH, "equivalent"); break; 98 case IMatchRules.COMPATIBLE: 99 setXMLAttribute(P_MATCH, "compatible"); break; 101 case IMatchRules.PERFECT: 102 setXMLAttribute(P_MATCH, "perfect"); break; 104 default: 105 setXMLAttribute(P_MATCH, null); 106 } 107 } 108 111 public void setVersion(String version) throws CoreException { 112 setXMLAttribute(P_VERSION, version); 113 } 114 117 public String getId() { 118 return getXMLAttributeValue("plugin"); } 120 123 public void setId(String id) throws CoreException { 124 setXMLAttribute("plugin", id); } 126 127 130 public String write(boolean indent) { 131 return indent ? getIndent() + writeShallow(true) : writeShallow(true); 132 } 133 134 137 public String writeShallow(boolean terminate) { 138 StringBuffer buffer = new StringBuffer ("<import"); appendAttribute(buffer, "plugin"); appendAttribute(buffer, P_VERSION); 141 appendAttribute(buffer, P_MATCH); 142 appendAttribute(buffer, P_REEXPORTED, "false"); appendAttribute(buffer, P_OPTIONAL, "false"); 145 if (terminate) 146 buffer.append("/"); buffer.append(">"); return buffer.toString(); 149 } 150 151 } 152 | Popular Tags |