1 | package de.uka.ipd.sdq.pipesandfilters.framework.recorder.launch; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import org.eclipse.core.runtime.CoreException; |
7 | import org.eclipse.core.runtime.IConfigurationElement; |
8 | import org.eclipse.core.runtime.IExtension; |
9 | import org.eclipse.core.runtime.Platform; |
10 | import org.eclipse.debug.ui.ILaunchConfigurationTab; |
11 | |
12 | public class RecorderExtensionHelper { |
13 | |
14 | public static String[] getRecorderNames() throws CoreException { |
15 | List<IExtension> recorderExtensions = loadExtensions("de.uka.ipd.sdq.pipesandfilters.framework.recorder"); |
16 | List<String> names = new ArrayList<String>(); |
17 | for (IExtension extension : recorderExtensions) { |
18 | IConfigurationElement e = obtainConfigurationElement("recorder", |
19 | extension); |
20 | if (e != null) { |
21 | names.add(e.getAttribute("name")); |
22 | } |
23 | } |
24 | return names.toArray(new String[names.size()]); |
25 | } |
26 | |
27 | public static ILaunchConfigurationTab[] getLaunchConfigTabs() |
28 | throws CoreException { |
29 | List<IExtension> recorderExtensions = loadExtensions("de.uka.ipd.sdq.pipesandfilters.framework.recorder"); |
30 | List<ILaunchConfigurationTab> tabList = new ArrayList<ILaunchConfigurationTab>(); |
31 | for (IExtension extension : recorderExtensions) { |
32 | IConfigurationElement e = obtainConfigurationElement("recorder", |
33 | extension); |
34 | if (e != null) { |
35 | tabList.add((ILaunchConfigurationTab) e |
36 | .createExecutableExtension("launchConfigTab")); |
37 | } |
38 | } |
39 | return tabList.toArray(new ILaunchConfigurationTab[tabList.size()]); |
40 | } |
41 | |
42 | public static String getExtensionIdentifierForName(String recorderName) |
43 | throws CoreException { |
44 | List<IExtension> recorderExtensions = loadExtensions("de.uka.ipd.sdq.pipesandfilters.framework.recorder"); |
45 | for (IExtension extension : recorderExtensions) { |
46 | IConfigurationElement e = obtainConfigurationElement("recorder", |
47 | extension); |
48 | if (e != null && e.getAttribute("name").equals(recorderName)) { |
49 | return extension.getUniqueIdentifier(); |
50 | } |
51 | } |
52 | return null; |
53 | } |
54 | |
55 | public static IRecorderConfiguration getRecorderConfigForName( |
56 | String recorderName) throws CoreException { |
57 | List<IExtension> recorderExtensions = loadExtensions("de.uka.ipd.sdq.pipesandfilters.framework.recorder"); |
58 | for (IExtension extension : recorderExtensions) { |
59 | IConfigurationElement e = obtainConfigurationElement("recorder", |
60 | extension); |
61 | if (e != null && e.getAttribute("name").equals(recorderName)) { |
62 | Object config = e.createExecutableExtension("configuration"); |
63 | if (config != null) { |
64 | return (IRecorderConfiguration) config; |
65 | } |
66 | } |
67 | } |
68 | return null; |
69 | } |
70 | |
71 | public static String getWriteStrategyClassNameForName(String recorderName) |
72 | throws CoreException { |
73 | List<IExtension> recorderExtensions = loadExtensions("de.uka.ipd.sdq.pipesandfilters.framework.recorder"); |
74 | for (IExtension extension : recorderExtensions) { |
75 | IConfigurationElement e = obtainConfigurationElement("recorder", |
76 | extension); |
77 | if (e != null && e.getAttribute("name").equals(recorderName)) { |
78 | Object writeStrategy = e.getAttribute("writeStrategy"); |
79 | if (writeStrategy != null) { |
80 | return (String) writeStrategy; |
81 | } |
82 | } |
83 | } |
84 | return null; |
85 | } |
86 | |
87 | public static String getNameForExtensionIdentifier(String extensionID) |
88 | throws CoreException { |
89 | IExtension ext = Platform.getExtensionRegistry().getExtensionPoint( |
90 | "de.uka.ipd.sdq.pipesandfilters.framework.recorder") |
91 | .getExtension(extensionID); |
92 | if (ext != null) { |
93 | IConfigurationElement e = obtainConfigurationElement("recorder", |
94 | ext); |
95 | return e.getAttribute("name"); |
96 | } |
97 | return null; |
98 | } |
99 | |
100 | private static IConfigurationElement obtainConfigurationElement( |
101 | String elementName, IExtension extension) throws CoreException { |
102 | IConfigurationElement[] elements = extension.getConfigurationElements(); |
103 | for (IConfigurationElement element : elements) { |
104 | if (element.getName().equals(elementName)) { |
105 | return element; |
106 | } |
107 | } |
108 | return null; |
109 | } |
110 | |
111 | private static List<IExtension> loadExtensions(String extensionPointID) { |
112 | IExtension[] exts = Platform.getExtensionRegistry().getExtensionPoint( |
113 | extensionPointID).getExtensions(); |
114 | List<IExtension> results = new ArrayList<IExtension>(); |
115 | for (IExtension extension : exts) { |
116 | results.add(extension); |
117 | } |
118 | return results; |
119 | } |
120 | |
121 | } |