1 /*******************************************************************************
2 * Copyright (c) 2014 É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
.tracecompass
.tmf
.core
.analysis
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
20 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
26 * Utility class for accessing TMF analysis module extensions from the
27 * platform's extensions registry and returning the modules' outputs, wrapped as
28 * new module listeners.
30 * @author Geneviève Bastien
32 public class TmfAnalysisModuleOutputs
{
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 'output' */
38 public static final String OUTPUT_ELEM
= "output"; //$NON-NLS-1$
40 /** Extension point attribute 'outputClass' */
41 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
43 /** Extension point attribute 'id' */
44 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
47 * Extension point element 'analysisId' to associate the output to a single
50 public static final String ANALYSIS_ID_ELEM
= "analysisId"; //$NON-NLS-1$
53 * Extension point element 'analysisModuleClass' to associate the output
54 * with an analysis module class
56 public static final String MODULE_CLASS_ELEM
= "analysisModuleClass"; //$NON-NLS-1$
58 private TmfAnalysisModuleOutputs() {
63 * Return the analysis module outputs, wrapped as new module listeners,
64 * advertised in the extension point, in iterable format.
66 * @return List of {@link ITmfNewAnalysisModuleListener}
68 public static Iterable
<@NonNull ITmfNewAnalysisModuleListener
> getOutputListeners() {
69 List
<@NonNull ITmfNewAnalysisModuleListener
> newModuleListeners
= new ArrayList
<>();
70 // Get the sources element from the extension point
71 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID
);
72 for (IConfigurationElement ce
: config
) {
73 String elementName
= ce
.getName();
74 if (elementName
.equals(OUTPUT_ELEM
)) {
76 IAnalysisOutput output
= (IAnalysisOutput
) ce
.createExecutableExtension(CLASS_ATTR
);
78 Activator
.logWarning("An output could not be created"); //$NON-NLS-1$
81 ITmfNewAnalysisModuleListener listener
= null;
82 for (IConfigurationElement childCe
: ce
.getChildren()) {
83 if (childCe
.getName().equals(ANALYSIS_ID_ELEM
)) {
84 listener
= new TmfNewAnalysisOutputListener(output
, childCe
.getAttribute(ID_ATTR
), null);
85 } else if (childCe
.getName().equals(MODULE_CLASS_ELEM
)) {
86 listener
= new TmfNewAnalysisOutputListener(output
, null, childCe
.createExecutableExtension(CLASS_ATTR
).getClass().asSubclass(IAnalysisModule
.class));
89 if (listener
!= null) {
90 newModuleListeners
.add(listener
);
92 } catch (InvalidRegistryObjectException
| CoreException e
) {
93 Activator
.logError("Error creating module output listener", e
); //$NON-NLS-1$
97 return newModuleListeners
;