Fix some null warnings
[deliverable/tracecompass.git] / tmf / 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.jdt.annotation.NonNull;
23 import org.eclipse.tracecompass.internal.tmf.core.Activator;
24
25 /**
26 * Utility class for accessing TMF analysis module extensions from the
27 * platform's extensions registry and returning the modules' outputs, wrapped as
28 * new module listeners.
29 *
30 * @author Geneviève Bastien
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<@NonNull ITmfNewAnalysisModuleListener> getOutputListeners() {
69 List<@NonNull 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 if (output == null) {
78 Activator.logWarning("An output could not be created"); //$NON-NLS-1$
79 continue;
80 }
81 ITmfNewAnalysisModuleListener listener = null;
82 for (IConfigurationElement childCe : ce.getChildren()) {
83 if (childCe.getName().equals(ANALYSIS_ID_ELEM)) {
84 listener = new TmfNewAnalysisOutputListener(output, childCe.getAttribute(ID_ATTR), null);
85 } else if (childCe.getName().equals(MODULE_CLASS_ELEM)) {
86 listener = new TmfNewAnalysisOutputListener(output, null, childCe.createExecutableExtension(CLASS_ATTR).getClass().asSubclass(IAnalysisModule.class));
87 }
88 }
89 if (listener != null) {
90 newModuleListeners.add(listener);
91 }
92 } catch (InvalidRegistryObjectException | CoreException e) {
93 Activator.logError("Error creating module output listener", e); //$NON-NLS-1$
94 }
95 }
96 }
97 return newModuleListeners;
98 }
99 }
This page took 0.039639 seconds and 5 git commands to generate.