KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > RepositoryProviderType


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.team.core;
12
13 import java.util.*;
14
15 import org.eclipse.core.resources.IContainer;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.team.core.subscribers.Subscriber;
19 import org.eclipse.team.internal.core.DefaultProjectSetCapability;
20 import org.eclipse.team.internal.core.TeamPlugin;
21
22 /**
23  * This class represents things you can ask/do with a type of provider. This
24  * is in the absence of a project, as opposed to RepositoryProvider which
25  * requires a concrete project in order to be instantiated.
26  * <p>
27  * A repository provider type class is associated with it's provider ID along with it's
28  * corresponding repository provider class. To add a
29  * repository provider type and have it registered with the platform, a client
30  * must minimally:
31  * <ol>
32  * <li>extend <code>RepositoryProviderType</code>
33  * <li>add the typeClass field to the repository extension in <code>plugin.xml</code>.
34  * Here is an example extension point definition:
35  *
36  * <code>
37  * <br>&lt;extension point="org.eclipse.team.core.repository"&gt;
38  * <br>&nbsp;&lt;repository
39  * <br>&nbsp;&nbsp;class="org.eclipse.myprovider.MyRepositoryProvider"
40  * <br>&nbsp;&nbsp;typeClass="org.eclipse.myprovider.MyRepositoryProviderType"
41  * <br>&nbsp;&nbsp;id="org.eclipse.myprovider.myProviderID"&gt;
42  * <br>&nbsp;&lt;/repository&gt;
43  * <br>&lt;/extension&gt;
44  * </code>
45  * </ol></p>
46  *
47  * <p>
48  * Once a repository provider type is registered with Team, then you
49  * can access the singleton instance of the class by invoking <code>RepositoryProviderType.getProviderType()</code>.
50  * </p>
51  *
52  * @see RepositoryProviderType#getProviderType(String)
53  *
54  * @since 2.1
55  */

56
57 public abstract class RepositoryProviderType extends PlatformObject {
58     private static Map allProviderTypes = new HashMap();
59     
60     private String JavaDoc id;
61
62     private String JavaDoc scheme;
63
64     public RepositoryProviderType() {
65     }
66
67     /**
68      * Return the RepositoryProviderType for the given provider ID.
69      *
70      * @param id the ID of the provider
71      * @return RepositoryProviderType
72      *
73      * @see #getID()
74      */

75     public static RepositoryProviderType getProviderType(String JavaDoc id) {
76         RepositoryProviderType type = (RepositoryProviderType) allProviderTypes.get(id);
77
78         if(type != null)
79             return type;
80             
81         //If there isn't one in the table, we'll try to create one from the extension point
82
//Its possible that newProviderType() will return null, but in that case it will have also logged the error so just return the result
83
return newProviderType(id);
84     }
85     
86     /**
87      * Return the repository type for the given file system scheme or
88      * <code>null</code> if there isn't one. The scheme corresponds to
89      * the scheme used for the <code>org.eclipse.core.filesystem.filesystems</code>
90      * extension point.
91      * @param scheme the file system scheme
92      * @return the repository type for the given file system scheme or
93      * <code>null</code>
94      * @since 3.2
95      */

96     public static RepositoryProviderType getTypeForScheme(String JavaDoc scheme) {
97         for (Iterator iter = allProviderTypes.values().iterator(); iter.hasNext();) {
98             RepositoryProviderType type = (RepositoryProviderType) iter.next();
99             if (type.getFileSystemScheme() != null && type.getFileSystemScheme().equals(scheme))
100                 return type;
101         }
102         return findProviderForScheme(scheme);
103     }
104     
105     private static RepositoryProviderType findProviderForScheme(String JavaDoc scheme) {
106         IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.REPOSITORY_EXTENSION);
107         if (extension != null) {
108             IExtension[] extensions = extension.getExtensions();
109             for (int i = 0; i < extensions.length; i++) {
110                 IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
111                 for (int j = 0; j < configElements.length; j++) {
112                     String JavaDoc extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$
113
String JavaDoc typeScheme = configElements[j].getAttribute("fileSystemScheme"); //$NON-NLS-1$
114
if (typeScheme != null && typeScheme.equals(scheme) && extensionId != null) {
115                         return newProviderType(extensionId);
116                     }
117                 }
118             }
119         }
120         return null;
121     }
122     
123     private void setID(String JavaDoc id) {
124         this.id = id;
125     }
126     
127     private static RepositoryProviderType newProviderType(String JavaDoc id) {
128         IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.REPOSITORY_EXTENSION);
129         if (extension != null) {
130             IExtension[] extensions = extension.getExtensions();
131             for (int i = 0; i < extensions.length; i++) {
132                 IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
133                 for (int j = 0; j < configElements.length; j++) {
134                     String JavaDoc extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$
135

136                     if (extensionId != null && extensionId.equals(id)) {
137                         try {
138                             RepositoryProviderType providerType;
139                             //Its ok not to have a typeClass extension. In this case, a default instance will be created.
140
if(configElements[j].getAttribute("typeClass") == null) { //$NON-NLS-1$
141
providerType = new DefaultRepositoryProviderType();
142                             } else {
143                                 providerType = (RepositoryProviderType) configElements[j].createExecutableExtension("typeClass"); //$NON-NLS-1$
144
}
145                             
146                             providerType.setID(id);
147                             allProviderTypes.put(id, providerType);
148                             String JavaDoc scheme = configElements[j].getAttribute("fileSystemScheme"); //$NON-NLS-1$
149
providerType.setFileSystemScheme(scheme);
150                             return providerType;
151                         } catch (CoreException e) {
152                             TeamPlugin.log(e);
153                         } catch (ClassCastException JavaDoc e) {
154                             String JavaDoc className = configElements[j].getAttribute("typeClass"); //$NON-NLS-1$
155
TeamPlugin.log(IStatus.ERROR, "Class " + className + " registered for repository provider type id " + id + " is not a subclass of RepositoryProviderType", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
156
}
157                         return null;
158                     }
159                 }
160             }
161         }
162         return null;
163     }
164     
165     private void setFileSystemScheme(String JavaDoc scheme) {
166         this.scheme = scheme;
167     }
168
169     /**
170      * Answer the id of this provider type. The id will be the repository
171      * provider type's id as defined in the provider plugin's plugin.xml.
172      *
173      * @return the id of this provider type
174      */

175     public final String JavaDoc getID() {
176         return this.id;
177     }
178
179     /**
180      * Answers an object for serializing and deserializing
181      * of references to projects. Given a project, it can produce a
182      * UTF-8 encoded String which can be stored in a file.
183      * Given this String, it can load a project into the workspace.
184      * It also provides a mechanism
185      * by which repository providers can be notified when a project set is created and exported.
186      * If the provider doesn't wish to provide this
187      * feature, return null.
188      * <p>
189      * Subclasses should override this method to return the appropriate
190      * serializer for the associated repository type.
191      * It is recommended that serializers not have any references to UI classes
192      * so that they can be used in a headless environment.
193      * <p>
194      * At this time, the default implementation wrappers the <code>IProjectSetSerializer</code>
195      * interface if one exists, providing backward compatibility with existing code.
196      * At some time in the future, the <code>IProjectSetSerializer</code> interface will be removed
197      * and the default implementation will revert to having limited functionality.
198      *
199      * @return the project set serializer (or <code>null</code>)
200      */

201     public ProjectSetCapability getProjectSetCapability() {
202         // Provide backward compatibility with the old IProjectSetSerializer interface
203
IProjectSetSerializer oldSerializer = Team.getProjectSetSerializer(getID());
204         if (oldSerializer != null) {
205             ProjectSetCapability capability = new DefaultProjectSetCapability();
206             capability.setSerializer(oldSerializer);
207             return capability;
208         }
209         return null;
210     }
211     
212     /**
213      * Callback from team when the meta-files for a repository type are detected in an
214      * unshared project. The meta-file paths are provided as part of the <code>repository</code>
215      * entry in the plugin manifest file.
216      * <p>
217      * By default, nothing is done (except that the repository type's
218      * plugin will have been loaded. Subclass may wish to mark the met-data as team-private.
219      * This method is called from a resource delta so subclasses may not obtain scheduling rules
220      * or in any way modify workspace resources (including auto-sharing the project). However,
221      * auto-sharing (or other modification) could be performed by a background job scheduled from
222      * this callback.
223      *
224      * @since 3.1
225      *
226      * @param project the project that contains the detected meta-files.
227      * @param containers the folders (possibly including the project folder) in which meta-files were found
228      */

229     public void metaFilesDetected(IProject project, IContainer[] containers) {
230         // Do nothing by default
231
}
232     
233     /**
234      * Return a {@link Subscriber} that describes the synchronization state
235      * of the resources contained in the project associated with this
236      * provider type. By default, <code>null</code> is returned. Subclasses
237      * may override.
238      * @return a subscriber that provides resource synchronization state or <code>null</code>
239      * @since 3.2
240      */

241     public Subscriber getSubscriber() {
242         return null;
243     }
244
245     /**
246      * Return the file system scheme for this provider type or
247      * <code>null</code> if the type doesn't support file systems
248      * as defined by the <code>org.eclipse.core.filesystem.filesystems</code>
249      * extension point.
250      * @return the file system scheme for this provider type or
251      * <code>null</code>
252      * @since 3.2
253      */

254     public final String JavaDoc getFileSystemScheme() {
255         return scheme;
256     }
257 }
258
Popular Tags