1 11 12 package org.eclipse.ui.internal.intro.impl.model.loader; 13 14 import java.util.ArrayList ; 15 import java.util.Hashtable ; 16 import java.util.List ; 17 import java.util.Vector ; 18 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.IExtensionRegistry; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroIdElement; 23 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; 24 import org.eclipse.ui.internal.intro.impl.util.Log; 25 import org.eclipse.ui.internal.intro.impl.util.Util; 26 27 30 public class BaseExtensionPointManager { 31 32 protected static final String CONFIG = "org.eclipse.ui.intro.config"; 35 protected static final String CONFIG_EXTENSION = "org.eclipse.ui.intro.configExtension"; 38 protected static final String ATT_CONFIG_INTRO_ID = "introId"; 41 protected static final String ATT_CONFIG_EXTENSION_CONFIG_ID = "configId"; 44 protected static final String ATT_ID = AbstractIntroIdElement.ATT_ID; 46 47 48 protected Hashtable introModels = new Hashtable (); 49 protected IExtensionRegistry registry; 50 protected SharedConfigExtensionsManager sharedConfigExtensionsManager; 51 private String extensionFilter; 52 53 56 protected BaseExtensionPointManager() { 57 registry = Platform.getExtensionRegistry(); 58 } 59 60 protected IntroModelRoot loadModel(String attributeName, 61 String attributeValue) { 62 63 long start = 0; 64 if (Log.logPerformance) 65 start = System.currentTimeMillis(); 66 67 IConfigurationElement introConfig = getIntroConfig(attributeName, 71 attributeValue); 72 73 if (introConfig != null) { 76 String configId = introConfig.getAttribute(ATT_ID); 80 IConfigurationElement[] introConfigExtensions = null; 81 if (configId == null) 82 introConfigExtensions = new IConfigurationElement[0]; 84 else 85 introConfigExtensions = getIntroConfigExtensions( 86 ATT_CONFIG_EXTENSION_CONFIG_ID, configId); 87 88 if (Log.logPerformance) 89 Util.logPerformanceTime( 90 "BEGIN: quering registry for configs took: ", start); 92 93 IntroModelRoot model = new IntroModelRoot(introConfig, 94 introConfigExtensions); 95 model.loadModel(); 96 addCachedModel(model.getId(), model); 100 101 loadSharedConfigExtensions(); 104 105 if (Log.logPerformance) 106 Util 107 .logPerformanceTime( 108 "loading Intro Model (quering registry/creating & resolving model) took: ", start); 110 111 return model; 112 } 113 return null; 114 } 115 116 125 protected IConfigurationElement getIntroConfig(String attrributeName, 126 String attributeValue) { 127 128 IConfigurationElement[] configElements = registry 129 .getConfigurationElementsFor(CONFIG); 130 131 IConfigurationElement config = getConfigurationFromAttribute( 132 configElements, attrributeName, attributeValue); 133 134 if (config == null) 135 Log.warning("No Intro configuration found with " + attrributeName + " of value = " + attributeValue); 139 return config; 140 } 141 142 147 protected IConfigurationElement[] getIntroConfigExtensions( 148 String attrributeName, String attributeValue) { 149 150 IConfigurationElement[] configExtensionElements = registry 151 .getConfigurationElementsFor(CONFIG_EXTENSION); 152 153 157 if (extensionFilter != null) { 158 List filtered = new ArrayList (); 159 for (int i=0;i<configExtensionElements.length;++i) { 160 if (extensionFilter.equals(configExtensionElements[i].getContributor().getName())) { 161 filtered.add(configExtensionElements[i]); 162 } 163 } 164 configExtensionElements = (IConfigurationElement[])filtered.toArray(new IConfigurationElement[filtered.size()]); 165 } 166 167 IConfigurationElement[] configExtensions = getConfigurationsFromAttribute( 168 configExtensionElements, attrributeName, attributeValue); 169 170 return configExtensions; 171 } 172 173 180 protected void addCachedModel(String modelId, IntroModelRoot model) { 181 introModels.put(modelId, model); 182 } 183 184 189 protected IntroModelRoot getCachedModel(String configId) { 190 return (IntroModelRoot) introModels.get(configId); 191 } 192 193 202 protected IConfigurationElement getConfigurationFromAttribute( 203 IConfigurationElement[] configElements, String attributeName, 204 String attributeValue) { 205 206 IConfigurationElement[] filteredConfigElements = getConfigurationsFromAttribute( 208 configElements, attributeName, attributeValue); 209 IConfigurationElement config = ModelLoaderUtil 211 .validateSingleContribution(filteredConfigElements, attributeName); 212 return config; 213 } 214 215 220 protected IConfigurationElement[] getConfigurationsFromAttribute( 221 IConfigurationElement[] configElements, String attributeName, 222 String attributeValue) { 223 224 Vector elements = new Vector (); 226 for (int i = 0; i < configElements.length; i++) { 227 String currentAttributeValue = configElements[i] 228 .getAttribute(attributeName); 229 if (currentAttributeValue != null 230 && currentAttributeValue.equals(attributeValue)) 231 elements.add(configElements[i]); 232 } 233 234 IConfigurationElement[] filteredConfigElements = new IConfigurationElement[elements 236 .size()]; 237 elements.copyInto(filteredConfigElements); 238 239 return filteredConfigElements; 240 } 241 242 245 protected void loadSharedConfigExtensions() { 246 sharedConfigExtensionsManager = new SharedConfigExtensionsManager( 247 registry); 248 sharedConfigExtensionsManager.loadSharedConfigExtensions(); 249 } 250 251 252 255 public SharedConfigExtensionsManager getSharedConfigExtensionsManager() { 256 return sharedConfigExtensionsManager; 257 } 258 259 262 public Hashtable getIntroModels() { 263 return introModels; 264 } 265 266 269 public void setExtensionFilter(String pluginId) { 270 extensionFilter = pluginId; 271 } 272 } 273 | Popular Tags |