1 11 package org.eclipse.debug.internal.core; 12 13 14 import java.util.Collections ; 15 import java.util.HashMap ; 16 import java.util.HashSet ; 17 import java.util.Hashtable ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.eclipse.core.resources.IContainer; 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IConfigurationElement; 26 import org.eclipse.core.runtime.IStatus; 27 import org.eclipse.core.runtime.PlatformObject; 28 import org.eclipse.core.runtime.Status; 29 import org.eclipse.debug.core.DebugPlugin; 30 import org.eclipse.debug.core.ILaunchConfiguration; 31 import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate; 32 import org.eclipse.debug.core.ILaunchConfigurationType; 33 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 34 import org.eclipse.debug.core.ILaunchDelegate; 35 import org.eclipse.debug.core.ILaunchManager; 36 import org.eclipse.debug.core.ILaunchMode; 37 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; 38 import org.eclipse.debug.core.sourcelookup.ISourcePathComputer; 39 40 import com.ibm.icu.text.MessageFormat; 41 42 47 public class LaunchConfigurationType extends PlatformObject implements ILaunchConfigurationType { 48 49 52 private IConfigurationElement fElement; 53 54 59 private Set fModes = null; 60 61 66 private Set fModeCombinations = null; 67 68 73 private ISourcePathComputer fSourcePathComputer = null; 74 75 80 private ILaunchConfigurationMigrationDelegate fMigrationDelegate = null; 81 82 85 private String fSourceLocator = null; 86 87 93 private Map fDelegates = null; 94 95 98 private LaunchDelegate fSourceProvider = null; 99 100 105 private Map fPreferredDelegates = null; 106 107 113 protected LaunchConfigurationType(IConfigurationElement element) { 114 fElement = element; 115 initializePreferredDelegates(); 116 } 117 118 121 public String getAttribute(String attributeName) { 122 return fElement.getAttribute(attributeName); 123 } 124 125 128 public String getCategory() { 129 return fElement.getAttribute(IConfigurationElementConstants.CATEGORY); 130 } 131 132 135 public ILaunchConfigurationDelegate getDelegate() throws CoreException { 136 return getDelegate(ILaunchManager.RUN_MODE); 137 } 138 139 142 public ILaunchConfigurationDelegate getDelegate(String mode) throws CoreException { 143 Set modes = new HashSet (); 144 modes.add(mode); 145 ILaunchDelegate[] delegates = getDelegates(modes); 146 if (delegates.length > 0) { 147 return delegates[0].getDelegate(); 148 } 149 IStatus status = null; 150 ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(mode); 151 if (launchMode == null) { 152 status = new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), 153 MessageFormat.format(DebugCoreMessages.LaunchConfigurationType_7, 154 new String []{mode})); 155 } else { 156 status = new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), 157 MessageFormat.format(DebugCoreMessages.LaunchConfigurationType_7, 158 new String []{((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).getLaunchModeName(mode)})); 159 } 160 throw new CoreException(status); 161 } 162 163 166 public ILaunchDelegate[] getDelegates(Set modes) throws CoreException { 167 initializeDelegates(); 168 Set delegates = (Set ) fDelegates.get(modes); 169 if (delegates == null) { 170 delegates = Collections.EMPTY_SET; 171 } 172 return (ILaunchDelegate[]) delegates.toArray(new ILaunchDelegate[delegates.size()]); 173 } 174 175 178 public void setPreferredDelegate(Set modes, ILaunchDelegate delegate) { 179 if(fPreferredDelegates == null) { 180 fPreferredDelegates = new HashMap (); 181 } 182 if (delegate == null) { 183 fPreferredDelegates.remove(modes); 184 } else { 185 fPreferredDelegates.put(modes, delegate); 186 } 187 } 188 189 192 public ILaunchDelegate getPreferredDelegate(Set modes) { 193 return (ILaunchDelegate) fPreferredDelegates.get(modes); 194 } 195 196 208 public Map getPreferredDelegates() { 209 return fPreferredDelegates; 210 } 211 212 222 private synchronized void initializePreferredDelegates() { 223 if(fPreferredDelegates == null) { 224 fPreferredDelegates = new HashMap (); 225 initializeDelegates(); 226 LaunchManager lm = (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); 227 ILaunchDelegate delegate = null; 228 Set modes = null; 229 for(Iterator iter = fDelegates.keySet().iterator(); iter.hasNext();) { 230 modes = (Set ) iter.next(); 231 delegate = lm.getPreferredDelegate(getIdentifier(), modes); 232 if(delegate != null) { 233 fPreferredDelegates.put(modes, delegate); 234 } 235 } 236 } 237 } 238 239 242 private synchronized void initializeDelegates() { 243 if (fDelegates == null) { 244 fDelegates = new Hashtable (); 246 LaunchDelegate[] launchDelegates = getLaunchDelegateExtensions(); 247 LaunchDelegate delegate = null; 248 List modelist = null; 249 Set modes = null, tmp = null; 250 for (int i = 0; i < launchDelegates.length; i++) { 251 delegate = launchDelegates[i]; 252 modelist = delegate.getModes(); 253 for(int j = 0; j < modelist.size(); j++) { 254 modes = (Set ) modelist.get(j); 256 tmp = (Set ) fDelegates.get(modes); 257 if (tmp == null) { 258 tmp = new HashSet (); 259 fDelegates.put(modes, tmp); 260 } 261 tmp.add(delegate); 262 } 263 } 264 } 265 } 266 267 272 private LaunchDelegate[] getLaunchDelegateExtensions() { 273 return ((LaunchManager) DebugPlugin.getDefault().getLaunchManager()).getLaunchDelegates(getIdentifier()); 274 } 275 276 279 public String getIdentifier() { 280 return fElement.getAttribute(IConfigurationElementConstants.ID); 281 } 282 283 286 public String getName() { 287 return fElement.getAttribute(IConfigurationElementConstants.NAME); 288 } 289 290 293 public String getPluginIdentifier() { 294 return fElement.getContributor().getName(); 295 } 296 297 300 public String getSourceLocatorId() { 301 if(fSourceLocator == null) { 302 fSourceLocator = getAttribute(IConfigurationElementConstants.SOURCE_LOCATOR); 303 if(fSourceProvider != null) { 305 fSourceLocator = fSourceProvider.getSourceLocatorId(); 306 } 307 if(fSourceLocator == null) { 310 LaunchDelegate[] delegates = getLaunchDelegateExtensions(); 311 for(int i = 0; i < delegates.length; i++) { 312 fSourceLocator = delegates[i].getSourceLocatorId(); 313 if(fSourceLocator != null) { 314 fSourceProvider = delegates[i]; 315 return fSourceLocator; 316 } 317 } 318 fSourceProvider = null; 319 } 320 } 321 return fSourceLocator; 322 } 323 324 327 public ISourcePathComputer getSourcePathComputer() { 328 if(fSourcePathComputer == null) { 329 String id = fElement.getAttribute(IConfigurationElementConstants.SOURCE_PATH_COMPUTER); 331 if(fSourceProvider != null) { 333 id = fSourceProvider.getSourcePathComputerId(); 334 } 335 if(id != null) { 336 fSourcePathComputer = DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(id); 337 } 338 else { 339 LaunchDelegate[] delegates = getLaunchDelegateExtensions(); 342 for(int i = 0; i < delegates.length; i++) { 343 id = delegates[i].getSourcePathComputerId(); 344 if(id != null) { 345 fSourceProvider = delegates[i]; 346 fSourcePathComputer = DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(id); 347 if(fSourcePathComputer != null) { 348 return fSourcePathComputer; 349 } 350 } 351 } 352 fSourceProvider = null; 353 } 354 355 } 356 return fSourcePathComputer; 357 } 358 359 362 public Set getSupportedModes() { 363 if(fModes == null) { 364 fModes = new HashSet (); 365 LaunchDelegate[] delegates = getLaunchDelegateExtensions(); 366 List modesets = null; 367 for(int i= 0; i < delegates.length; i++) { 368 modesets = delegates[i].getModes(); 369 for(Iterator iter = modesets.iterator(); iter.hasNext();) { 370 fModes.addAll((Set ) iter.next()); 371 } 372 } 373 } 374 return fModes; 375 } 376 377 380 public Set getSupportedModeCombinations() { 381 if(fModeCombinations == null) { 382 initializeDelegates(); 383 fModeCombinations = new HashSet (); 384 fModeCombinations = fDelegates.keySet(); 385 } 386 HashSet set = new HashSet (); 388 for(Iterator iter = fModeCombinations.iterator(); iter.hasNext();) { 389 set.add(new HashSet ((Set ) iter.next())); 390 } 391 return set; 392 } 393 394 403 public boolean isMigrationCandidate(ILaunchConfiguration candidate) throws CoreException { 404 initializeMigrationDelegate(); 405 if(fMigrationDelegate != null) { 406 return fMigrationDelegate.isCandidate(candidate); 407 } 408 return false; 409 } 410 411 415 private synchronized void initializeMigrationDelegate() throws CoreException { 416 if(fElement.getAttribute(IConfigurationElementConstants.MIGRATION_DELEGATE) != null && fMigrationDelegate == null) { 417 fMigrationDelegate = (ILaunchConfigurationMigrationDelegate) fElement.createExecutableExtension(IConfigurationElementConstants.MIGRATION_DELEGATE); 418 } 419 } 420 421 424 public boolean isPublic() { 425 String publicString = fElement.getAttribute(IConfigurationElementConstants.PUBLIC); 426 if (publicString != null) { 427 if (publicString.equalsIgnoreCase("false")) { return false; 429 } 430 } 431 return true; 432 } 433 434 442 public void migrate(ILaunchConfiguration candidate) throws CoreException { 443 initializeMigrationDelegate(); 444 if(fMigrationDelegate != null) { 445 fMigrationDelegate.migrate(candidate); 446 } 447 } 448 449 452 public ILaunchConfigurationWorkingCopy newInstance(IContainer container, String name) { 453 return new LaunchConfigurationWorkingCopy(container, name, this); 454 } 455 456 459 public boolean supportsMode(String mode) { 460 if(fModeCombinations == null) { 461 getSupportedModeCombinations(); 462 } 463 Set modes = null; 464 for(Iterator iter = fModeCombinations.iterator(); iter.hasNext();) { 465 modes = (Set ) iter.next(); 466 if(modes.size() == 1 && modes.contains(mode)) { 467 return true; 468 } 469 } 470 return false; 471 } 472 473 476 public String getContributorName() { 477 return fElement.getContributor().getName(); 478 } 479 480 483 public boolean supportsModeCombination(Set modes) { 484 if(fModeCombinations == null) { 485 getSupportedModeCombinations(); 486 } 487 return fModeCombinations.contains(modes); 488 } 489 490 } 491 492 | Popular Tags |