1 11 package org.eclipse.debug.internal.core; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IConfigurationElement; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.debug.core.DebugPlugin; 24 import org.eclipse.debug.core.ILaunchDelegate; 25 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; 26 27 import com.ibm.icu.text.MessageFormat; 28 29 53 public final class LaunchDelegate implements ILaunchDelegate { 54 55 58 private IConfigurationElement fElement = null; 59 60 63 private ILaunchConfigurationDelegate fDelegate = null; 64 65 private List fLaunchModes = null; 67 private String fType = null; 68 private HashMap fPerspectiveIds = null; 69 70 74 public LaunchDelegate(IConfigurationElement element) { 75 fElement = element; 76 } 77 78 81 public ILaunchConfigurationDelegate getDelegate() throws CoreException { 82 if(fDelegate == null) { 83 Object obj = fElement.createExecutableExtension(IConfigurationElementConstants.DELEGATE); 84 if(obj instanceof ILaunchConfigurationDelegate) { 85 fDelegate = (ILaunchConfigurationDelegate)obj; 86 } else { 87 throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(DebugCoreMessages.LaunchConfigurationType_Launch_delegate_for__0__does_not_implement_required_interface_ILaunchConfigurationDelegate__1, new String []{getId()}), null)); 88 } 89 } 90 return fDelegate; 91 } 92 93 96 public String getId() { 97 return fElement.getAttribute(IConfigurationElementConstants.ID); 98 } 99 100 104 public String getLaunchConfigurationTypeId() { 105 if(fType == null) { 106 fType = fElement.getAttribute(IConfigurationElementConstants.TYPE); 108 if(fType == null) { 109 fType = fElement.getAttribute(IConfigurationElementConstants.ID); 111 } 112 } 113 return fType; 114 } 115 116 122 private Set parseModes(IConfigurationElement element) { 123 HashSet set = new HashSet (); 124 String modes = element.getAttribute(IConfigurationElementConstants.MODES); 125 if (modes != null) { 126 String [] strings = modes.split(","); for (int i = 0; i < strings.length; i++) { 128 set.add(strings[i].trim()); 129 } 130 } 131 return set; 132 } 133 134 137 public List getModes() { 138 if(fLaunchModes == null) { 139 fLaunchModes = new ArrayList (); 140 fPerspectiveIds = new HashMap (); 141 IConfigurationElement[] children = fElement.getChildren(IConfigurationElementConstants.MODE_COMBINATION); 142 Set modeset = null; 143 for (int i = 0; i < children.length; i++) { 144 modeset = parseModes(children[i]); 145 fLaunchModes.add(modeset); 146 fPerspectiveIds.put(modeset, children[i].getAttribute(IConfigurationElementConstants.PERSPECTIVE)); 147 } 148 modeset = null; 151 String modes = fElement.getAttribute(IConfigurationElementConstants.MODES); 152 if (modes != null) { 153 String [] strings = modes.split(","); for (int i = 0; i < strings.length; i++) { 155 modeset = new HashSet (); 156 modeset.add(strings[i].trim()); 157 fLaunchModes.add(modeset); 158 } 159 } 160 } 161 return fLaunchModes; 162 } 163 164 168 public String getName() { 169 String name = fElement.getAttribute(IConfigurationElementConstants.DELEGATE_NAME); 171 if(name == null) { 172 name = fElement.getAttribute(IConfigurationElementConstants.NAME); 173 if (name == null) { 174 name = getContributorName(); 175 } 176 name = name.trim(); 177 if (Character.isUpperCase(name.charAt(0))) { 178 name = MessageFormat.format(DebugCoreMessages.LaunchDelegate_1, new String []{name}); 179 } else { 180 name = MessageFormat.format(DebugCoreMessages.LaunchDelegate_2, new String []{name}); 181 } 182 } 183 return name; 184 } 185 186 191 public String getContributorName() { 192 return fElement.getContributor().getName(); 193 } 194 195 199 public String getSourceLocatorId() { 200 return fElement.getAttribute(IConfigurationElementConstants.SOURCE_LOCATOR); 201 } 202 203 207 public String getSourcePathComputerId() { 208 return fElement.getAttribute(IConfigurationElementConstants.SOURCE_PATH_COMPUTER); 209 } 210 211 214 public String getDescription() { 215 String desc = fElement.getAttribute(IConfigurationElementConstants.DELEGATE_DESCRIPTION); 216 if(desc == null) { 217 return DebugCoreMessages.LaunchDelegate_0; 218 } 219 return desc; 220 } 221 222 225 public String getPluginIdentifier() { 226 return fElement.getContributor().getName(); 227 } 228 229 232 public boolean equals(Object obj) { 233 if(obj == null) { 234 return false; 235 } 236 return obj instanceof ILaunchDelegate && getId() != null && getId().equals(((ILaunchDelegate)obj).getId()); 237 } 238 239 242 public String getPerspectiveId(Set modes) { 243 if(fPerspectiveIds == null) { 244 getModes(); 245 } 246 return (String ) fPerspectiveIds.get(modes); 247 } 248 } 249 | Popular Tags |