1 11 package org.eclipse.pde.internal.core.plugin; 12 13 import java.io.InputStream ; 14 15 import javax.xml.parsers.SAXParser ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.osgi.service.resolver.BundleDescription; 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.core.ModelChangedEvent; 21 import org.eclipse.pde.core.plugin.IExtensions; 22 import org.eclipse.pde.core.plugin.IExtensionsModelFactory; 23 import org.eclipse.pde.core.plugin.IPluginAttribute; 24 import org.eclipse.pde.core.plugin.IPluginBase; 25 import org.eclipse.pde.core.plugin.IPluginElement; 26 import org.eclipse.pde.core.plugin.IPluginExtension; 27 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 28 import org.eclipse.pde.core.plugin.IPluginImport; 29 import org.eclipse.pde.core.plugin.IPluginLibrary; 30 import org.eclipse.pde.core.plugin.IPluginModelBase; 31 import org.eclipse.pde.core.plugin.IPluginModelFactory; 32 import org.eclipse.pde.core.plugin.IPluginObject; 33 import org.eclipse.pde.internal.core.AbstractNLModel; 34 import org.eclipse.pde.internal.core.PDEState; 35 36 public abstract class AbstractPluginModelBase 37 extends AbstractNLModel 38 implements IPluginModelBase, IPluginModelFactory { 39 protected IPluginBase fPluginBase; 40 private boolean enabled; 41 private BundleDescription fBundleDescription; 42 protected boolean fAbbreviated; 43 44 public AbstractPluginModelBase() { 45 super(); 46 } 47 48 public abstract String getInstallLocation(); 49 50 public abstract IPluginBase createPluginBase(); 51 52 public IExtensions createExtensions() { 53 return createPluginBase(); 54 } 55 56 public IExtensionsModelFactory getFactory() { 57 return this; 58 } 59 60 public IPluginModelFactory getPluginFactory() { 61 return this; 62 } 63 64 public IPluginBase getPluginBase() { 65 return getPluginBase(true); 66 } 67 public IPluginBase getPluginBase(boolean createIfMissing) { 68 if (fPluginBase == null && createIfMissing) { 69 fPluginBase = createPluginBase(); 70 setLoaded(true); 71 } 72 return fPluginBase; 73 } 74 75 public void load(InputStream stream, boolean outOfSync) throws CoreException { 76 load(stream, outOfSync, new PluginHandler(fAbbreviated)); 77 } 78 79 public void load(InputStream stream, boolean outOfSync, PluginHandler handler) throws CoreException { 80 if (fPluginBase == null) 81 fPluginBase = createPluginBase(); 82 83 ((PluginBase)fPluginBase).reset(); 84 setLoaded(false); 85 try { 86 SAXParser parser = getSaxParser(); 87 parser.parse(stream, handler); 88 ((PluginBase)fPluginBase).load(handler.getDocumentElement(), handler.getSchemaVersion()); 89 setLoaded(true); 90 if (!outOfSync) 91 updateTimeStamp(); 92 } catch (Exception e) { 93 } 94 } 95 96 public void load(BundleDescription description, PDEState state) { 97 setBundleDescription(description); 98 IPluginBase base = getPluginBase(); 99 if (base instanceof Plugin) 100 ((Plugin)base).load(description, state); 101 else 102 ((Fragment)base).load(description, state); 103 updateTimeStamp(); 104 setLoaded(true); 105 } 106 107 public IExtensions getExtensions() { 108 return getPluginBase(); 109 } 110 public IExtensions getExtensions(boolean createIfMissing) { 111 return getPluginBase(createIfMissing); 112 } 113 public boolean isEnabled() { 114 return enabled; 115 } 116 public boolean isFragmentModel() { 117 return false; 118 } 119 120 public void reload(InputStream stream, boolean outOfSync) 121 throws CoreException { 122 load(stream, outOfSync); 123 fireModelChanged( 124 new ModelChangedEvent(this, 125 IModelChangedEvent.WORLD_CHANGED, 126 new Object [] { fPluginBase }, 127 null)); 128 } 129 public void setEnabled(boolean newEnabled) { 130 enabled = newEnabled; 131 } 132 public String toString() { 133 IPluginBase pluginBase = getPluginBase(); 134 if (pluginBase != null) 135 return pluginBase.getId(); 136 return super.toString(); 137 } 138 139 protected abstract void updateTimeStamp(); 140 141 public IPluginAttribute createAttribute(IPluginElement element) { 142 PluginAttribute attribute = new PluginAttribute(); 143 attribute.setModel(this); 144 attribute.setParent(element); 145 return attribute; 146 } 147 public IPluginElement createElement(IPluginObject parent) { 148 PluginElement element = new PluginElement(); 149 element.setModel(this); 150 element.setParent(parent); 151 return element; 152 } 153 public IPluginExtension createExtension() { 154 PluginExtension extension = new PluginExtension(); 155 extension.setParent(getPluginBase()); 156 extension.setModel(this); 157 return extension; 158 } 159 public IPluginExtensionPoint createExtensionPoint() { 160 PluginExtensionPoint extensionPoint = new PluginExtensionPoint(); 161 extensionPoint.setModel(this); 162 extensionPoint.setParent(getPluginBase()); 163 return extensionPoint; 164 } 165 public IPluginImport createImport() { 166 PluginImport iimport = new PluginImport(); 167 iimport.setModel(this); 168 iimport.setParent(getPluginBase()); 169 return iimport; 170 } 171 172 public IPluginImport createImport(String pluginId) { 173 PluginImport iimport = new PluginImport(this, pluginId); 174 iimport.setParent(getPluginBase()); 175 return iimport; 176 } 177 178 public IPluginLibrary createLibrary() { 179 PluginLibrary library = new PluginLibrary(); 180 library.setModel(this); 181 library.setParent(getPluginBase()); 182 return library; 183 } 184 185 public boolean isValid() { 186 if (!isLoaded()) return false; 187 if (fPluginBase==null) return false; 188 return fPluginBase.isValid(); 189 } 190 191 public boolean isBundleModel() { 192 return false; 193 } 194 195 198 public void dispose() { 199 fBundleDescription = null; 200 super.dispose(); 201 } 202 203 206 public BundleDescription getBundleDescription() { 207 return fBundleDescription; 208 } 209 210 213 public void setBundleDescription(BundleDescription description) { 214 fBundleDescription = description; 215 } 216 217 } 218 | Popular Tags |