Fix latest batch of null warnings
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / analysis / TmfAnalysisModuleSourceConfigElement.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 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.internal.tmf.core.analysis;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.util.ArrayList;
18 import java.util.LinkedList;
19 import java.util.List;
20
21 import org.eclipse.core.runtime.IConfigurationElement;
22 import org.eclipse.core.runtime.Platform;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
25 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource;
26 import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisModuleHelperConfigElement;
27
28 /**
29 * Utility class for accessing TMF analysis module extensions from the
30 * platform's extensions registry.
31 *
32 * @author Geneviève Bastien
33 */
34 public final class TmfAnalysisModuleSourceConfigElement implements IAnalysisModuleSource {
35
36 /** Extension point ID */
37 public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
38
39 /** Extension point element 'module' */
40 public static final String MODULE_ELEM = "module"; //$NON-NLS-1$
41
42 /** Extension point element 'parameter' */
43 public static final String PARAMETER_ELEM = "parameter"; //$NON-NLS-1$
44
45 /** Extension point attribute 'ID' */
46 public static final String ID_ATTR = "id"; //$NON-NLS-1$
47
48 /** Extension point attribute 'name' */
49 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
50
51 /** Extension point attribute 'analysis_module' */
52 public static final String ANALYSIS_MODULE_ATTR = "analysis_module"; //$NON-NLS-1$
53
54 /** Extension point attribute 'automatic' */
55 public static final String AUTOMATIC_ATTR = "automatic"; //$NON-NLS-1$
56
57 /** Extension point attribute 'applies_experiment' */
58 public static final String APPLIES_EXP_ATTR = "applies_experiment"; //$NON-NLS-1$
59
60 /** Extension point attribute 'icon' */
61 public static final String ICON_ATTR = "icon"; //$NON-NLS-1$
62
63 /** Extension point attribute 'default_value' */
64 public static final String DEFAULT_VALUE_ATTR = "default_value"; //$NON-NLS-1$
65
66 /** Extension point element 'tracetype' */
67 public static final String TRACETYPE_ELEM = "tracetype"; //$NON-NLS-1$
68
69 /** Extension point attribute 'class' */
70 public static final String CLASS_ATTR = "class"; //$NON-NLS-1$
71
72 /** Extension point attribute 'applies' */
73 public static final String APPLIES_ATTR = "applies"; //$NON-NLS-1$
74
75 /**
76 * The mapping of available analysis ID to their corresponding helper
77 */
78 private final List<IAnalysisModuleHelper> fAnalysisHelpers = new ArrayList<>();
79
80 /**
81 * Retrieves all configuration elements from the platform extension registry
82 * for the analysis module extension.
83 *
84 * @return an array of analysis module configuration elements
85 */
86 public static IConfigurationElement[] getTypeElements() {
87 IConfigurationElement[] elements =
88 Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
89 List<IConfigurationElement> typeElements = new LinkedList<>();
90 for (IConfigurationElement element : elements) {
91 if (element.getName().equals(MODULE_ELEM)) {
92 typeElements.add(element);
93 }
94 }
95 return checkNotNull(typeElements.toArray(new @NonNull IConfigurationElement[typeElements.size()]));
96 }
97
98 /**
99 * Constructor
100 */
101 public TmfAnalysisModuleSourceConfigElement() {
102 populateAnalysisList();
103 }
104
105 @Override
106 public Iterable<IAnalysisModuleHelper> getAnalysisModules() {
107 return fAnalysisHelpers;
108 }
109
110 private void populateAnalysisList() {
111 if (fAnalysisHelpers.isEmpty()) {
112 // Populate the analysis module list
113 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
114 for (IConfigurationElement ce : config) {
115 String elementName = ce.getName();
116 if (elementName.equals(TmfAnalysisModuleSourceConfigElement.MODULE_ELEM)) {
117 fAnalysisHelpers.add(new TmfAnalysisModuleHelperConfigElement(ce));
118 }
119 }
120 }
121 }
122
123 }
This page took 0.039978 seconds and 6 git commands to generate.