1 11 package org.eclipse.ui.internal.activities.ws; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.core.runtime.IExtension; 17 import org.eclipse.core.runtime.IExtensionPoint; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.WorkbenchPlugin; 23 import org.eclipse.ui.internal.misc.StatusUtil; 24 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 25 import org.eclipse.ui.internal.registry.RegistryReader; 26 27 30 public class TriggerPointAdvisorRegistry { 31 32 private static TriggerPointAdvisorRegistry instance; 33 34 37 private TriggerPointAdvisorRegistry() { 38 } 39 40 45 public static TriggerPointAdvisorRegistry getInstance() { 46 if (instance == null) { 47 instance = new TriggerPointAdvisorRegistry(); 48 } 49 50 return instance; 51 } 52 53 58 public TriggerPointAdvisorDescriptor[] getAdvisors() { 59 IExtensionPoint point = Platform.getExtensionRegistry() 60 .getExtensionPoint(PlatformUI.PLUGIN_ID, 61 IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT); 62 if (point == null) { 63 return new TriggerPointAdvisorDescriptor[0]; 64 } 65 66 IExtension[] extensions = point.getExtensions(); 67 extensions = RegistryReader.orderExtensions(extensions); 68 69 ArrayList list = new ArrayList (extensions.length); 70 for (int i = 0; i < extensions.length; i++) { 71 IConfigurationElement[] elements = extensions[i] 72 .getConfigurationElements(); 73 for (int j = 0; j < elements.length; j++) { 74 if (elements[j].getName().equals( 75 IWorkbenchRegistryConstants.TAG_TRIGGERPOINTADVISOR)) { 76 try { 77 TriggerPointAdvisorDescriptor descriptor = new TriggerPointAdvisorDescriptor( 78 elements[j]); 79 list.add(descriptor); 80 } catch (IllegalArgumentException e) { 81 WorkbenchPlugin.log( 83 "invalid trigger point advisor extension", StatusUtil.newStatus(IStatus.ERROR, e 85 .getMessage(), e)); 86 } 87 } 88 } 89 } 90 91 return (TriggerPointAdvisorDescriptor[]) list 92 .toArray(new TriggerPointAdvisorDescriptor[list.size()]); 93 } 94 95 102 public TriggerPointAdvisorDescriptor getAdvisorForProduct(String productId) { 103 IExtensionPoint point = Platform.getExtensionRegistry() 104 .getExtensionPoint(PlatformUI.PLUGIN_ID, 105 IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT); 106 if (point == null) { 107 return null; 108 } 109 110 IExtension[] extensions = point.getExtensions(); 111 extensions = RegistryReader.orderExtensions(extensions); 112 113 String targetIntroId = getAdvisorForProduct(productId, extensions); 114 if (targetIntroId == null) { 115 return null; 116 } 117 118 TriggerPointAdvisorDescriptor[] advisors = getAdvisors(); 119 for (int i = 0; i < advisors.length; i++) { 120 if (advisors[i].getId().equals(targetIntroId)) { 121 return advisors[i]; 122 } 123 } 124 125 return null; 126 } 127 128 133 private String getAdvisorForProduct(String targetProductId, 134 IExtension[] extensions) { 135 for (int i = 0; i < extensions.length; i++) { 136 IConfigurationElement[] elements = extensions[i] 137 .getConfigurationElements(); 138 for (int j = 0; j < elements.length; j++) { 139 if (elements[j].getName().equals( 140 IWorkbenchRegistryConstants.TAG_ADVISORPRODUCTBINDING)) { 141 String advisorId = elements[j] 142 .getAttribute(IWorkbenchRegistryConstants.ATT_ADVISORID); 143 String productId = elements[j] 144 .getAttribute(IWorkbenchRegistryConstants.ATT_PRODUCTID); 145 146 if (advisorId == null || productId == null) { 147 IStatus status = new Status( 148 IStatus.ERROR, 149 elements[j].getDeclaringExtension() 150 .getNamespace(), 151 IStatus.ERROR, 152 "triggerPointAdvisorId and productId must be defined.", new IllegalArgumentException ()); WorkbenchPlugin 154 .log( 155 "Invalid trigger point advisor binding", status); continue; 157 } 158 159 if (targetProductId.equals(productId)) { 160 return advisorId; 161 } 162 } 163 } 164 } 165 return null; 166 } 167 168 } 169 | Popular Tags |