1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.analysis
;
15 import java
.util
.HashMap
;
16 import java
.util
.LinkedList
;
17 import java
.util
.List
;
20 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisModuleHelperCE
;
26 * Utility class for accessing TMF analysis type extensions from the platform's
27 * extensions registry.
29 * @author Geneviève Bastien
32 public final class TmfAnalysisType
{
34 /** Extension point ID */
35 public static final String TMF_ANALYSIS_TYPE_ID
= "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
37 /** Extension point element 'module' */
38 public static final String MODULE_ELEM
= "module"; //$NON-NLS-1$
40 /** Extension point element 'parameter' */
41 public static final String PARAMETER_ELEM
= "parameter"; //$NON-NLS-1$
43 /** Extension point attribute 'ID' */
44 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
46 /** Extension point attribute 'name' */
47 public static final String NAME_ATTR
= "name"; //$NON-NLS-1$
49 /** Extension point attribute 'analysis_module' */
50 public static final String ANALYSIS_MODULE_ATTR
= "analysis_module"; //$NON-NLS-1$
52 /** Extension point attribute 'automatic' */
53 public static final String AUTOMATIC_ATTR
= "automatic"; //$NON-NLS-1$
55 /** Extension point attribute 'icon' */
56 public static final String ICON_ATTR
= "icon"; //$NON-NLS-1$
58 /** Extension point attribute 'default_value' */
59 public static final String DEFAULT_VALUE_ATTR
= "default_value"; //$NON-NLS-1$
61 /** Extension point element 'tracetype' */
62 public static final String TRACETYPE_ELEM
= "tracetype"; //$NON-NLS-1$
64 /** Extension point attribute 'class' */
65 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
67 /** Extension point attribute 'applies' */
68 public static final String APPLIES_ATTR
= "applies"; //$NON-NLS-1$
71 * The mapping of available trace type IDs to their corresponding
72 * configuration element
74 private final Map
<String
, IAnalysisModuleHelper
> fAnalysisTypeAttributes
= new HashMap
<String
, IAnalysisModuleHelper
>();
76 private static TmfAnalysisType fInstance
= null;
79 * Retrieves all configuration elements from the platform extension registry
80 * for the trace type extension.
82 * @return an array of trace type configuration elements
84 public static IConfigurationElement
[] getTypeElements() {
85 IConfigurationElement
[] elements
=
86 Platform
.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID
);
87 List
<IConfigurationElement
> typeElements
= new LinkedList
<IConfigurationElement
>();
88 for (IConfigurationElement element
: elements
) {
89 if (element
.getName().equals(MODULE_ELEM
)) {
90 typeElements
.add(element
);
93 return typeElements
.toArray(new IConfigurationElement
[typeElements
.size()]);
96 private TmfAnalysisType() {
97 populateAnalysisTypes();
101 * The analysis type instance
103 * @return the analysis type instance
105 public static synchronized TmfAnalysisType
getInstance() {
106 if (fInstance
== null) {
107 fInstance
= new TmfAnalysisType();
113 * Get the list of analysis modules
115 * @return list of analysis modules
117 public Map
<String
, IAnalysisModuleHelper
> getAnalysisModules() {
118 return fAnalysisTypeAttributes
;
121 private void populateAnalysisTypes() {
122 if (fAnalysisTypeAttributes
.isEmpty()) {
123 // Populate the Categories and Trace Types
124 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID
);
125 for (IConfigurationElement ce
: config
) {
126 String elementName
= ce
.getName();
127 if (elementName
.equals(TmfAnalysisType
.MODULE_ELEM
)) {
128 String analysisTypeId
= ce
.getAttribute(TmfAnalysisType
.ID_ATTR
);
129 fAnalysisTypeAttributes
.put(analysisTypeId
, new TmfAnalysisModuleHelperCE(ce
));