31fdc1e157d38161f47f085e02d3d6467ffc41f2
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / analysis / TmfAnalysisModuleOutputs.java
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.tracecompass.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.tracecompass.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 */
31 public class TmfAnalysisModuleOutputs {
32
33 /** Extension point ID */
34 public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
35
36 /** Extension point element 'output' */
37 public static final String OUTPUT_ELEM = "output"; //$NON-NLS-1$
38
39 /** Extension point attribute 'outputClass' */
40 public static final String CLASS_ATTR = "class"; //$NON-NLS-1$
41
42 /** Extension point attribute 'id' */
43 public static final String ID_ATTR = "id"; //$NON-NLS-1$
44
45 /**
46 * Extension point element 'analysisId' to associate the output to a single
47 * analysis
48 */
49 public static final String ANALYSIS_ID_ELEM = "analysisId"; //$NON-NLS-1$
50
51 /**
52 * Extension point element 'analysisModuleClass' to associate the output
53 * with an analysis module class
54 */
55 public static final String MODULE_CLASS_ELEM = "analysisModuleClass"; //$NON-NLS-1$
56
57 private TmfAnalysisModuleOutputs() {
58
59 }
60
61 /**
62 * Return the analysis module outputs, wrapped as new module listeners,
63 * advertised in the extension point, in iterable format.
64 *
65 * @return List of {@link ITmfNewAnalysisModuleListener}
66 */
67 public static Iterable<ITmfNewAnalysisModuleListener> getOutputListeners() {
68 List<ITmfNewAnalysisModuleListener> newModuleListeners = new ArrayList<>();
69 // Get the sources element from the extension point
70 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
71 for (IConfigurationElement ce : config) {
72 String elementName = ce.getName();
73 if (elementName.equals(OUTPUT_ELEM)) {
74 try {
75 IAnalysisOutput output = (IAnalysisOutput) ce.createExecutableExtension(CLASS_ATTR);
76 if (output == null) {
77 Activator.logWarning("An output could not be created"); //$NON-NLS-1$
78 continue;
79 }
80 ITmfNewAnalysisModuleListener listener = null;
81 for (IConfigurationElement childCe : ce.getChildren()) {
82 if (childCe.getName().equals(ANALYSIS_ID_ELEM)) {
83 listener = new TmfNewAnalysisOutputListener(output, childCe.getAttribute(ID_ATTR), null);
84 } else if (childCe.getName().equals(MODULE_CLASS_ELEM)) {
85 listener = new TmfNewAnalysisOutputListener(output, null, childCe.createExecutableExtension(CLASS_ATTR).getClass().asSubclass(IAnalysisModule.class));
86 }
87 }
88 if (listener != null) {
89 newModuleListeners.add(listener);
90 }
91 } catch (InvalidRegistryObjectException | CoreException e) {
92 Activator.logError("Error creating module output listener", e); //$NON-NLS-1$
93 }
94 }
95 }
96 return newModuleListeners;
97 }
98 }
This page took 0.052827 seconds and 4 git commands to generate.