1 11 12 package org.eclipse.ui.internal.services; 13 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 import java.util.Set ; 19 20 import org.eclipse.ui.ISourceProvider; 21 import org.eclipse.ui.services.IDisposable; 22 23 34 public final class SourceProviderService implements ISourceProviderService, 35 IDisposable { 36 37 42 private final Map sourceProvidersByName = new HashMap (); 43 44 48 private final Set sourceProviders = new HashSet (); 49 50 public final void dispose() { 51 final Iterator sourceProviderItr = sourceProviders.iterator(); 52 while (sourceProviderItr.hasNext()) { 53 final ISourceProvider sourceProvider = (ISourceProvider) sourceProviderItr 54 .next(); 55 sourceProvider.dispose(); 56 } 57 sourceProviders.clear(); 58 sourceProvidersByName.clear(); 59 } 60 61 public final ISourceProvider getSourceProvider(final String sourceName) { 62 return (ISourceProvider) sourceProvidersByName.get(sourceName); 63 } 64 65 public final ISourceProvider[] getSourceProviders() { 66 return (ISourceProvider[]) sourceProviders 67 .toArray(new ISourceProvider[sourceProviders.size()]); 68 } 69 70 public final void registerProvider(final ISourceProvider sourceProvider) { 71 if (sourceProvider == null) { 72 throw new NullPointerException ("The source provider cannot be null"); } 74 75 final String [] sourceNames = sourceProvider.getProvidedSourceNames(); 76 for (int i = 0; i < sourceNames.length; i++) { 77 final String sourceName = sourceNames[i]; 78 sourceProvidersByName.put(sourceName, sourceProvider); 79 } 80 sourceProviders.add(sourceProvider); 81 } 82 83 } 84 | Popular Tags |