Commit | Line | Data |
---|---|---|
b63291e6 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.analysis; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.core.runtime.CoreException; | |
19 | import org.eclipse.core.runtime.IConfigurationElement; | |
20 | import org.eclipse.core.runtime.InvalidRegistryObjectException; | |
21 | import org.eclipse.core.runtime.Platform; | |
22 | import org.eclipse.linuxtools.internal.tmf.core.Activator; | |
23 | ||
24 | /** | |
25 | * Utility class for accessing TMF analysis module extensions from the | |
26 | * platform's extensions registry and returning the modules' outputs, wrapped as | |
27 | * new module listeners. | |
28 | * | |
29 | * @author Geneviève Bastien | |
30 | * @since 3.0 | |
31 | */ | |
32 | public class TmfAnalysisModuleOutputs { | |
33 | ||
34 | /** Extension point ID */ | |
35 | public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$ | |
36 | ||
37 | /** Extension point element 'output' */ | |
38 | public static final String OUTPUT_ELEM = "output"; //$NON-NLS-1$ | |
39 | ||
40 | /** Extension point attribute 'outputClass' */ | |
41 | public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ | |
42 | ||
43 | /** Extension point attribute 'id' */ | |
44 | public static final String ID_ATTR = "id"; //$NON-NLS-1$ | |
45 | ||
46 | /** | |
47 | * Extension point element 'analysisId' to associate the output to a single | |
48 | * analysis | |
49 | */ | |
50 | public static final String ANALYSIS_ID_ELEM = "analysisId"; //$NON-NLS-1$ | |
51 | ||
52 | /** | |
53 | * Extension point element 'analysisModuleClass' to associate the output | |
54 | * with an analysis module class | |
55 | */ | |
56 | public static final String MODULE_CLASS_ELEM = "analysisModuleClass"; //$NON-NLS-1$ | |
57 | ||
58 | private TmfAnalysisModuleOutputs() { | |
59 | ||
60 | } | |
61 | ||
62 | /** | |
63 | * Return the analysis module outputs, wrapped as new module listeners, | |
64 | * advertised in the extension point, in iterable format. | |
65 | * | |
66 | * @return List of {@link ITmfNewAnalysisModuleListener} | |
67 | */ | |
68 | public static Iterable<ITmfNewAnalysisModuleListener> getOutputListeners() { | |
69 | List<ITmfNewAnalysisModuleListener> newModuleListeners = new ArrayList<>(); | |
70 | // Get the sources element from the extension point | |
71 | IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); | |
72 | for (IConfigurationElement ce : config) { | |
73 | String elementName = ce.getName(); | |
74 | if (elementName.equals(OUTPUT_ELEM)) { | |
75 | try { | |
76 | IAnalysisOutput output = (IAnalysisOutput) ce.createExecutableExtension(CLASS_ATTR); | |
77 | ITmfNewAnalysisModuleListener listener = null; | |
78 | for (IConfigurationElement childCe : ce.getChildren()) { | |
79 | if (childCe.getName().equals(ANALYSIS_ID_ELEM)) { | |
80 | listener = new TmfNewAnalysisOutputListener(output, childCe.getAttribute(ID_ATTR), null); | |
81 | } else if (childCe.getName().equals(MODULE_CLASS_ELEM)) { | |
226d3e76 | 82 | listener = new TmfNewAnalysisOutputListener(output, null, childCe.createExecutableExtension(CLASS_ATTR).getClass().asSubclass(IAnalysisModule.class)); |
b63291e6 GB |
83 | } |
84 | } | |
85 | if (listener != null) { | |
86 | newModuleListeners.add(listener); | |
87 | } | |
88 | } catch (InvalidRegistryObjectException | CoreException e) { | |
89 | Activator.logError("Error creating module output listener", e); //$NON-NLS-1$ | |
90 | } | |
91 | } | |
92 | } | |
93 | return newModuleListeners; | |
94 | } | |
95 | } |