KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > services > SourceProviderService


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.internal.services;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
19
20 import org.eclipse.ui.ISourceProvider;
21 import org.eclipse.ui.services.IDisposable;
22
23 /**
24  * <p>
25  * A service holding all of the registered source providers.
26  * </p>
27  * <p>
28  * This class is not intended for use outside of the
29  * <code>org.eclipse.ui.workbench</code> plug-in.
30  * </p>
31  *
32  * @since 3.2
33  */

34 public final class SourceProviderService implements ISourceProviderService,
35         IDisposable {
36
37     /**
38      * The source providers registered with this service. This value is never
39      * <code>null</code>. This is a map of the source name ({@link String})
40      * to the source provider ({@link ISourceProvider}).
41      */

42     private final Map JavaDoc sourceProvidersByName = new HashMap JavaDoc();
43
44     /**
45      * All of the source providers registered with this service. This value is
46      * never <code>null</code>.
47      */

48     private final Set JavaDoc sourceProviders = new HashSet JavaDoc();
49
50     public final void dispose() {
51         final Iterator JavaDoc 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 JavaDoc 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 JavaDoc("The source provider cannot be null"); //$NON-NLS-1$
73
}
74
75         final String JavaDoc[] sourceNames = sourceProvider.getProvidedSourceNames();
76         for (int i = 0; i < sourceNames.length; i++) {
77             final String JavaDoc sourceName = sourceNames[i];
78             sourceProvidersByName.put(sourceName, sourceProvider);
79         }
80         sourceProviders.add(sourceProvider);
81     }
82
83 }
84
Popular Tags