1 11 package org.eclipse.pde.internal.core.text.plugin; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.jface.text.IDocument; 18 import org.eclipse.pde.core.IModel; 19 import org.eclipse.pde.core.build.IBuildModel; 20 import org.eclipse.pde.core.plugin.IExtensions; 21 import org.eclipse.pde.core.plugin.IExtensionsModelFactory; 22 import org.eclipse.pde.core.plugin.IPluginBase; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.IPluginModelFactory; 25 import org.eclipse.pde.internal.core.NLResourceHelper; 26 import org.eclipse.pde.internal.core.PDEManager; 27 import org.eclipse.pde.internal.core.text.IDocumentNode; 28 import org.eclipse.pde.internal.core.text.XMLEditingModel; 29 import org.xml.sax.helpers.DefaultHandler ; 30 31 public abstract class PluginModelBase extends XMLEditingModel implements IPluginModelBase { 32 33 private PluginBaseNode fPluginBase; 34 private boolean fIsEnabled; 35 private PluginDocumentHandler fHandler; 36 private IPluginModelFactory fFactory; 37 private String fLocalization; 38 39 public PluginModelBase(IDocument document, boolean isReconciling) { 40 super(document, isReconciling); 41 fFactory = new PluginDocumentNodeFactory(this); 42 } 43 46 public IPluginBase createPluginBase(boolean isFragment) { 47 if (isFragment) { 48 fPluginBase = new FragmentNode(); 49 fPluginBase.setXMLTagName("fragment"); } else { 51 fPluginBase = new PluginNode(); 52 fPluginBase.setXMLTagName("plugin"); } 54 fPluginBase.setInTheModel(true); 55 fPluginBase.setModel(this); 56 return fPluginBase; 57 } 58 59 public IPluginBase createPluginBase() { 60 return createPluginBase(isFragmentModel()); 61 } 62 63 66 public IBuildModel getBuildModel() { 67 return null; 68 } 69 70 73 public IPluginBase getPluginBase() { 74 return getPluginBase(true); 75 } 76 77 public IExtensions getExtensions() { 78 return getPluginBase(); 79 } 80 81 84 public IPluginBase getPluginBase(boolean createIfMissing) { 85 if (!fLoaded && createIfMissing) { 86 createPluginBase(); 87 try { 88 load(); 89 } catch (CoreException e) { 90 } 91 } 92 return fPluginBase; 93 } 94 95 public IExtensions getExtensions(boolean createIfMissing) { 96 return getPluginBase(createIfMissing); 97 } 98 99 102 public boolean isEnabled() { 103 return fIsEnabled; 104 } 105 106 109 public void setEnabled(boolean enabled) { 110 fIsEnabled = enabled; 111 } 112 113 116 public IPluginModelFactory getPluginFactory() { 117 return fFactory; 118 } 119 120 123 public URL getNLLookupLocation() { 124 try { 125 String installLocation = getInstallLocation(); 126 return installLocation == null ? null : new URL ("file:" + installLocation); } catch (MalformedURLException e) { 128 } 129 return null; 130 } 131 132 135 public IExtensionsModelFactory getFactory() { 136 return fFactory; 137 } 138 139 142 protected NLResourceHelper createNLResourceHelper() { 143 URL [] locations = PDEManager.getNLLookupLocations(this); 144 return (locations.length == 0) 145 ? null 146 : new NLResourceHelper(fLocalization == null ? "plugin" : fLocalization, locations); 148 } 149 150 153 protected DefaultHandler createDocumentHandler(IModel model, boolean reconciling) { 154 if (fHandler == null) 155 fHandler = new PluginDocumentHandler(this, reconciling); 156 return fHandler; 157 } 158 159 public IDocumentNode getLastErrorNode() { 160 if (fHandler != null) 161 return fHandler.getLastErrorNode(); 162 return null; 163 } 164 165 public void setLocalization(String localization) { 166 fLocalization = localization; 167 } 168 } 169 | Popular Tags |