1 /*******************************************************************************
2 * Copyright (c) 2015 É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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.analysis
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
21 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
22 import org
.eclipse
.core
.runtime
.Platform
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisParameterProvider
;
27 * Utility class for accessing TMF analysis parameter providers extensions from
28 * the platform's extensions registry and returning the module parameter
31 * @author Geneviève Bastien
33 public final class TmfAnalysisParameterProviders
{
35 /** Extension point ID */
36 public static final String TMF_ANALYSIS_TYPE_ID
= "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
38 /** Extension point element 'module' */
39 public static final String PARAMETER_PROVIDER_ELEM
= "parameterProvider"; //$NON-NLS-1$
41 /** Extension point attribute 'class' */
42 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
44 /** Extension point attribute 'id' */
45 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
48 * Extension point element 'analysisId' to associate the output to a single
51 public static final String ANALYSIS_ID_ELEM
= "analysisId"; //$NON-NLS-1$
53 /* Maps a class name to an instance of a parameter provider */
54 private static final Map
<String
, IAnalysisParameterProvider
> fParamProviderInstances
= new HashMap
<>();
56 private TmfAnalysisParameterProviders() {
61 * Return the analysis parameter providers advertised in the extension
62 * point, and associated with an analysis ID.
65 * Get the parameter providers for an analysis identified by its
67 * @return Map of analysis ID mapped to parameter provider classes
69 public static Set
<IAnalysisParameterProvider
> getParameterProvidersFor(String analysisId
) {
70 Set
<IAnalysisParameterProvider
> providers
= new HashSet
<>();
71 // Get the parameter provider elements from the extension point
72 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID
);
73 for (IConfigurationElement ce
: config
) {
74 String elementName
= ce
.getName();
75 if (elementName
.equals(PARAMETER_PROVIDER_ELEM
)) {
77 IConfigurationElement
[] children
= ce
.getChildren(ANALYSIS_ID_ELEM
);
78 if (children
.length
== 0) {
79 throw new IllegalStateException();
81 String id
= children
[0].getAttribute(ID_ATTR
);
82 String className
= ce
.getAttribute(CLASS_ATTR
);
83 if (id
== null || className
== null) {
86 if (analysisId
.equals(id
)) {
87 IAnalysisParameterProvider provider
= fParamProviderInstances
.get(className
);
88 if (provider
!= null) {
89 providers
.add(provider
);
91 provider
= checkNotNull((IAnalysisParameterProvider
) ce
.createExecutableExtension(CLASS_ATTR
));
92 fParamProviderInstances
.put(className
, provider
);
93 providers
.add(provider
);
96 } catch (InvalidRegistryObjectException
| CoreException e
) {
97 Activator
.logError("Error creating module parameter provider", e
); //$NON-NLS-1$