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