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.pde.core.plugin.IPlugin; 18 import org.eclipse.pde.core.plugin.IPluginExtension; 19 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 20 import org.eclipse.pde.internal.core.PDEState; 21 import org.w3c.dom.Node ; 22 23 public class Plugin extends PluginBase implements IPlugin { 24 private static final long serialVersionUID = 1L; 25 private String fClassname; 26 private boolean fHasExtensibleAPI; 27 28 public String getClassName() { 29 return fClassname; 30 } 31 32 public IPlugin getPlugin() { 33 return this; 34 } 35 36 void load(BundleDescription bundleDescription, PDEState state) { 37 fClassname = state.getClassName(bundleDescription.getBundleId()); 38 fHasExtensibleAPI = state.hasExtensibleAPI(bundleDescription.getBundleId()); 39 super.load(bundleDescription, state); 40 } 41 42 void load(Node node, String schemaVersion) { 43 fClassname = getNodeAttribute(node, "class"); super.load(node, schemaVersion); 45 } 46 47 public void reset() { 48 fClassname = null; 49 super.reset(); 50 } 51 public void setClassName(String newClassName) throws CoreException { 52 ensureModelEditable(); 53 String oldValue = fClassname; 54 fClassname = newClassName; 55 firePropertyChanged(P_CLASS_NAME, oldValue, fClassname); 56 } 57 58 public void restoreProperty(String name, Object oldValue, Object newValue) 59 throws CoreException { 60 if (name.equals(P_CLASS_NAME)) { 61 setClassName(newValue != null ? newValue.toString() : null); 62 return; 63 } 64 super.restoreProperty(name, oldValue, newValue); 65 } 66 67 public void write(String indent, PrintWriter writer) { 68 writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (getSchemaVersion()!=null) { 70 writer.println("<?eclipse version=\"" + getSchemaVersion() + "\"?>"); } 72 writer.print("<plugin"); if (getId() != null) { 74 writer.println(); 75 writer.print(" id=\"" + getId() + "\""); } 77 if (getName() != null) { 78 writer.println(); 79 writer.print(" name=\"" + getWritableString(getName()) + "\""); } 81 if (getVersion() != null) { 82 writer.println(); 83 writer.print(" version=\"" + getVersion() + "\""); } 85 if (getProviderName() != null) { 86 writer.println(); 87 writer.print( 88 " provider-name=\"" + getWritableString(getProviderName()) 90 + "\""); } 92 if (getClassName() != null) { 93 writer.println(); 94 writer.print(" class=\"" + getClassName() + "\""); } 96 writer.println(">"); writer.println(); 98 99 String firstIndent = " "; 101 Object [] children = getLibraries(); 103 if (children.length > 0) { 104 writeChildren(firstIndent, "runtime", children, writer); writer.println(); 106 } 107 108 children = getImports(); 110 if (children.length > 0) { 111 writeChildren(firstIndent, "requires", children, writer); writer.println(); 113 } 114 115 children = getExtensionPoints(); 116 for (int i = 0; i < children.length; i++) { 117 ((IPluginExtensionPoint) children[i]).write(firstIndent, writer); 118 } 119 if (children.length > 0) 120 writer.println(); 121 122 children = getExtensions(); 124 for (int i = 0; i < children.length; i++) { 125 ((IPluginExtension) children[i]).write(firstIndent, writer); 126 } 127 if (children.length > 0) 128 writer.println(); 129 130 writer.println("</plugin>"); } 132 133 public boolean hasExtensibleAPI() { 134 return fHasExtensibleAPI; 135 } 136 } 137 | Popular Tags |