blob: 048368a8e2195a5aab6623ea619c7014a8a0b86a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package org.eclipse.team.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.team.internal.core.Policy;
import org.eclipse.team.internal.core.TeamPlugin;
/**
* Provisional.
*
* This class represents things you can ask/do with a type of provider. This
* is in the absence of a project, as opposed to RepositoryProvider which
* requires a concrete project in order to be instantiated.
*/
public abstract class RepositoryProviderType {
private static Map allProviderTypes = new HashMap();
private String id;
/**
* Constructor for RepositoryProviderType.
*/
public RepositoryProviderType() {
}
public static RepositoryProviderType getProviderType(String id) {
RepositoryProviderType type = (RepositoryProviderType) allProviderTypes.get(id);
if(type != null)
return type;
//If there isn't one in the table, we'll try to create one from the extension point
//Its possible that newProviderType() will return null, but in that case it will have also logged the error so just return the result
return newProviderType(id);
}
private void setID(String id) {
this.id = id;
}
private static RepositoryProviderType newProviderType(String id) {
TeamPlugin plugin = TeamPlugin.getPlugin();
if (plugin != null) {
IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.REPOSITORY_EXTENSION);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) {
IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for (int j = 0; j < configElements.length; j++) {
String extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$
if (extensionId != null && extensionId.equals(id)) {
try {
RepositoryProviderType providerType;
//Its ok not to have a typeClass extension. In this case, a default instance will be created.
if(configElements[j].getAttribute("typeClass") == null) {
providerType = new DefaultRepositoryProviderType();
} else {
providerType = (RepositoryProviderType) configElements[j].createExecutableExtension("typeClass"); //$NON-NLS-1$
}
providerType.setID(id);
allProviderTypes.put(id, providerType);
return providerType;
} catch (CoreException e) {
TeamPlugin.log(e.getStatus());
} catch (ClassCastException e) {
String className = configElements[j].getAttribute("typeClass"); //$NON-NLS-1$
TeamPlugin.log(IStatus.ERROR, Policy.bind("RepositoryProviderType.invalidClass", id, className), e); //$NON-NLS-1$
}
return null;
}
}
}
}
}
return null;
}
/**
* Answer the id of this provider instance. The id will be the repository
* provider type's id as defined in the provider plugin's plugin.xml.
*
* @return the nature id of this provider
*/
public final String getID() {
return this.id;
}
/**
* Answers the ProjectSetCapability that implements methods to import and
* create project sets. If the provider doesn't wish to provide this
* feature, return null.
*
* @return ProjectSetCapability
*/
public ProjectSetCapability getProjectSetCapability() {
return null;
}
}
|