releng: Transition to jdt.annotation 2.0
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / analysis / TmfAnalysisParameterProviders.java
1 /*******************************************************************************
2 * Copyright (c) 2015 É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
10 package org.eclipse.tracecompass.internal.tmf.core.analysis;
11
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Map;
17 import java.util.Set;
18
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;
25
26 /**
27 * Utility class for accessing TMF analysis parameter providers extensions from
28 * the platform's extensions registry and returning the module parameter
29 * providers.
30 *
31 * @author Geneviève Bastien
32 */
33 public final class TmfAnalysisParameterProviders {
34
35 /** Extension point ID */
36 public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
37
38 /** Extension point element 'module' */
39 public static final String PARAMETER_PROVIDER_ELEM = "parameterProvider"; //$NON-NLS-1$
40
41 /** Extension point attribute 'class' */
42 public static final String CLASS_ATTR = "class"; //$NON-NLS-1$
43
44 /** Extension point attribute 'id' */
45 public static final String ID_ATTR = "id"; //$NON-NLS-1$
46
47 /**
48 * Extension point element 'analysisId' to associate the output to a single
49 * analysis
50 */
51 public static final String ANALYSIS_ID_ELEM = "analysisId"; //$NON-NLS-1$
52
53 /* Maps a class name to an instance of a parameter provider */
54 private static final Map<String, IAnalysisParameterProvider> fParamProviderInstances = new HashMap<>();
55
56 private TmfAnalysisParameterProviders() {
57
58 }
59
60 /**
61 * Return the analysis parameter providers advertised in the extension
62 * point, and associated with an analysis ID.
63 *
64 * @param analysisId
65 * Get the parameter providers for an analysis identified by its
66 * ID
67 * @return Map of analysis ID mapped to parameter provider classes
68 */
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)) {
76 try {
77 IConfigurationElement[] children = ce.getChildren(ANALYSIS_ID_ELEM);
78 if (children.length == 0) {
79 throw new IllegalStateException();
80 }
81 String id = children[0].getAttribute(ID_ATTR);
82 String className = ce.getAttribute(CLASS_ATTR);
83 if (id == null || className == null) {
84 continue;
85 }
86 if (analysisId.equals(id)) {
87 IAnalysisParameterProvider provider = fParamProviderInstances.get(className);
88 if (provider != null) {
89 providers.add(provider);
90 } else {
91 provider = checkNotNull((IAnalysisParameterProvider) ce.createExecutableExtension(CLASS_ATTR));
92 fParamProviderInstances.put(className, provider);
93 providers.add(provider);
94 }
95 }
96 } catch (InvalidRegistryObjectException | CoreException e) {
97 Activator.logError("Error creating module parameter provider", e); //$NON-NLS-1$
98 }
99 }
100 }
101 return providers;
102 }
103
104 }
This page took 0.033984 seconds and 5 git commands to generate.